-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
63 additions
and
280 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
package zlogger | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/rs/zerolog" | ||
) | ||
|
||
// Logger creates a new zerolog logger with the given log level and wraps it in a context. | ||
// The logger will use a console writer with the time format set to RFC3339Nano. | ||
// The logger will also embed the timestamp in all log entries. | ||
// | ||
// Parameters: | ||
// - ctx: The context to wrap the logger in. | ||
// - level: The log level to use for the logger. | ||
// | ||
// Returns: | ||
// - context.Context: The context with the logger embedded in it. | ||
func Logger(ctx context.Context, level zerolog.Level) context.Context { | ||
// Create a new zerolog logger | ||
logger := zerolog.New(zerolog.NewConsoleWriter(func(w *zerolog.ConsoleWriter) { | ||
// Set the time format of the console writer to RFC3339Nano | ||
w.TimeFormat = time.RFC3339Nano | ||
})). | ||
Level(level). // Set the log level of the logger | ||
With(). // Start a new log entry with no fields | ||
Timestamp() // Add a timestamp to the log entry | ||
|
||
// Wrap the logger in the context and return it | ||
return logger.Logger().WithContext(ctx) | ||
} |
Oops, something went wrong.