@@ -10,6 +10,7 @@ import (
1010
1111type LoggerOptionFunc func (* Options )
1212
13+ // WithLevelText sets the log level as string
1314func WithLevelText (val string ) LoggerOptionFunc {
1415 level , err := TranslateToLogLevel (val )
1516 if err != nil {
@@ -21,12 +22,14 @@ func WithLevelText(val string) LoggerOptionFunc {
2122 }
2223}
2324
25+ // WithLevel sets the log level as slog.Level
2426func WithLevel (level slog.Level ) LoggerOptionFunc {
2527 return func (opt * Options ) {
2628 opt .Level = level
2729 }
2830}
2931
32+ // WithSourceMode sets the source (file, line) mode
3033func WithSourceMode (mode SourceMode ) LoggerOptionFunc {
3134 switch mode {
3235 case "" :
@@ -47,6 +50,7 @@ func WithSourceMode(mode SourceMode) LoggerOptionFunc {
4750 }
4851}
4952
53+ // WithFormat sets the mode (logfmt or json)
5054func WithFormat (mode FormatMode ) LoggerOptionFunc {
5155 switch mode {
5256 case "" :
@@ -62,18 +66,32 @@ func WithFormat(mode FormatMode) LoggerOptionFunc {
6266 }
6367}
6468
69+ // WithColor sets if logs should be colorful or not
6570func WithColor (mode ColorMode ) LoggerOptionFunc {
6671 return func (opt * Options ) {
6772 opt .SetColorMode (mode )
6873 }
6974}
7075
76+ // WithTime sets if logs lines should also include the time (not useful for containers)
7177func WithTime (v bool ) LoggerOptionFunc {
7278 return func (opt * Options ) {
7379 opt .ShowTime = v
7480 }
7581}
7682
83+ // NewFromSlog converts a slog.Logger to an slogger.Logger
84+ func NewFromSlog (logger * slog.Logger ) * Logger {
85+ return & Logger {logger }
86+ }
87+
88+ // NewDiscardLogger creates a logger which discards all logs (send logs to /dev/null)
89+ func NewDiscardLogger () * Logger {
90+ loggerOptions := NewOptions (nil )
91+ return newLoggerHandler (io .Discard , loggerOptions )
92+ }
93+
94+ // NewDaemonLogger creates a logger with defaults for daemons
7795func NewDaemonLogger (w io.Writer , opts ... LoggerOptionFunc ) * Logger {
7896 loggerOptions := NewOptions (nil ).
7997 SetLevel (LevelInfo ).
@@ -83,6 +101,7 @@ func NewDaemonLogger(w io.Writer, opts ...LoggerOptionFunc) *Logger {
83101 return newLoggerHandler (w , loggerOptions , opts ... )
84102}
85103
104+ // NewCliLogger creates a cli logger with defaults for cli tasks
86105func NewCliLogger (w io.Writer , opts ... LoggerOptionFunc ) * Logger {
87106 loggerOptions := NewOptions (nil ).
88107 SetLevel (LevelInfo ).
0 commit comments