File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ func RunBackend(ctx context.Context, config RunnerConfig) error {
6060 // Sanitize args for safe logging
6161 sanitizedArgs := make ([]string , len (config .Args ))
6262 for i , arg := range config .Args {
63- sanitizedArgs [i ] = utils .SanitizeForLog (arg )
63+ sanitizedArgs [i ] = utils .SanitizeForLog (arg , 0 )
6464 }
6565 config .Logger .Infof ("%s args: %v" , config .BackendName , sanitizedArgs )
6666
Original file line number Diff line number Diff line change @@ -7,9 +7,11 @@ import (
77
88// SanitizeForLog sanitizes a string for safe logging by removing or escaping
99// control characters that could cause log injection attacks.
10+ // The optional maxLength parameter controls truncation (default: 100).
11+ // Pass 0 or negative to disable truncation.
1012// TODO: Consider migrating to structured logging which
1113// handles sanitization automatically through field encoding.
12- func SanitizeForLog (s string ) string {
14+ func SanitizeForLog (s string , maxLength ... int ) string {
1315 if s == "" {
1416 return ""
1517 }
@@ -42,9 +44,15 @@ func SanitizeForLog(s string) string {
4244 }
4345 }
4446
45- const maxLength = 100
46- if result .Len () > maxLength {
47- return result .String ()[:maxLength ] + "...[truncated]"
47+ // Default maxLength is 100, or use provided value.
48+ // Pass 0 or negative to disable truncation.
49+ maxLen := 100
50+ if len (maxLength ) > 0 {
51+ maxLen = maxLength [0 ]
52+ }
53+
54+ if maxLen > 0 && result .Len () > maxLen {
55+ return result .String ()[:maxLen ] + "...[truncated]"
4856 }
4957
5058 return result .String ()
You can’t perform that action at this time.
0 commit comments