-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add writer and level methods (#31)
- Loading branch information
Showing
5 changed files
with
80 additions
and
49 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package golog | ||
|
||
import ( | ||
"github.com/danteay/golog/fields" | ||
"github.com/danteay/golog/internal/contextfields" | ||
"github.com/danteay/golog/internal/errors" | ||
"github.com/danteay/golog/levels" | ||
) | ||
|
||
// Log logs a message with the provided level, message and arguments. | ||
func (l *Logger) Log(level levels.Level, msg string, args ...any) { | ||
defer l.reset() | ||
|
||
if level <= levels.Disabled { | ||
return | ||
} | ||
|
||
l.fields.Merge(contextfields.Fields(l.ctx)) | ||
|
||
if l.err != nil { | ||
l.fields.Set("stack", errors.GetStackTrace()) | ||
} | ||
|
||
l.logger.Log(level, l.err, l.fields, msg, args...) | ||
} | ||
|
||
// Debug logs a message with the Debug level. | ||
func (l *Logger) Debug(msg string, args ...any) { | ||
l.Log(levels.Debug, msg, args...) | ||
} | ||
|
||
// Info logs a message with the Info level. | ||
func (l *Logger) Info(msg string, args ...any) { | ||
l.Log(levels.Info, msg, args...) | ||
} | ||
|
||
// Warn logs a message with the Warn level. | ||
func (l *Logger) Warn(msg string, args ...any) { | ||
l.Log(levels.Warn, msg, args...) | ||
} | ||
|
||
// Error logs a message with the Error level. | ||
func (l *Logger) Error(msg string, args ...any) { | ||
l.Log(levels.Error, msg, args...) | ||
} | ||
|
||
// Fatal logs a message with the Fatal level. | ||
func (l *Logger) Fatal(msg string, args ...any) { | ||
l.Log(levels.Fatal, msg, args...) | ||
} | ||
|
||
// Panic logs a message with the Panic level. | ||
func (l *Logger) Panic(msg string, args ...any) { | ||
l.Log(levels.Panic, msg, args...) | ||
} | ||
|
||
func (l *Logger) reset() { | ||
l.fields = fields.New() | ||
l.err = nil | ||
} |
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