-
Notifications
You must be signed in to change notification settings - Fork 327
feat: added remote syslog logging and log annotation (domain+msgid) #850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,11 @@ type Logger struct { | |
| // Additional fields that will be added | ||
| // to the Msg output. | ||
| Fields map[string]interface{} | ||
|
|
||
| // LogFields are rendered as [key=value ...] before the message text so | ||
| // that individual mail flows can be identified and filtered with grep. | ||
| // Use With() to populate this. | ||
| LogFields []string | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this is a good solution since we already have Fields. This is probably better done by customizing formatting at Logger level - msg_id is already added explicitly for most log records that are related to message delivery. This, in turn, would require some further design work as current logger implementation is very simple and lacks extended configuration parsing. Is there a specific reason why need fields formatted in this exact way? |
||
| } | ||
|
|
||
| func (l *Logger) Zap() *zap.Logger { | ||
|
|
@@ -171,6 +176,17 @@ func fieldsToMap(fields []interface{}, out map[string]interface{}) { | |
| func (l *Logger) formatMsg(msg string, fields map[string]interface{}) string { | ||
| formatted := strings.Builder{} | ||
|
|
||
| if len(l.LogFields) > 0 { | ||
| formatted.WriteRune('[') | ||
| for i, f := range l.LogFields { | ||
| if i > 0 { | ||
| formatted.WriteRune(' ') | ||
| } | ||
| formatted.WriteString(f) | ||
| } | ||
| formatted.WriteString("] ") | ||
| } | ||
|
|
||
| formatted.WriteString(msg) | ||
| formatted.WriteRune('\t') | ||
|
|
||
|
|
@@ -252,6 +268,21 @@ func (l *Logger) Sublogger(name string) *Logger { | |
| } | ||
| } | ||
|
|
||
| // With returns a copy of the logger with additional key=value pairs prepended | ||
| // to every log message as [key=value ...]. Multiple With calls accumulate. | ||
| // Use this to attach identifiers like domain or message-ID so log lines can | ||
| // be filtered with grep. | ||
| func (l *Logger) With(kvpairs ...interface{}) *Logger { | ||
| inherited := make([]string, len(l.LogFields), len(l.LogFields)+len(kvpairs)/2) | ||
| copy(inherited, l.LogFields) | ||
| for i := 0; i+1 < len(kvpairs); i += 2 { | ||
| inherited = append(inherited, fmt.Sprintf("%v=%v", kvpairs[i], kvpairs[i+1])) | ||
| } | ||
| newL := *l | ||
| newL.LogFields = inherited | ||
| return &newL | ||
| } | ||
|
|
||
| // DefaultLogger is the global Logger object that is used by | ||
| // package-level logging functions. | ||
| // | ||
|
|
||