-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from openconfig/log-by-line
Add logutil.LogByLine to avoid log truncation on logging SetRequests.
- Loading branch information
Showing
3 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package logutil | ||
|
||
import ( | ||
"bufio" | ||
"strings" | ||
|
||
log "github.com/golang/glog" | ||
) | ||
|
||
const ( | ||
// logLimit is used by logging helpers to avoid log truncation on some systems. | ||
logLimit = 15000 | ||
) | ||
|
||
// LogByLine logs the message line-by-line, and splits lines as well given the | ||
// log limit. | ||
func LogByLine(logLevel log.Level, message string) { | ||
scanner := bufio.NewScanner(strings.NewReader(message)) | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
length := len(line) | ||
for startIndex := 0; startIndex < length; startIndex += logLimit { | ||
endIndex := startIndex + logLimit | ||
if endIndex > length { | ||
endIndex = length | ||
} | ||
log.V(logLevel).Info(line[startIndex:endIndex]) | ||
} | ||
} | ||
if err := scanner.Err(); err != nil { | ||
log.Warningf("ygnmi/logutil: error while scanning log input: %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters