package main
import (
"context"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"os"
)
func main() {
// Set up zerolog to log to standard output
zerolog.ConsoleWriter := zerolog.NewConsoleWriter()
log.Logger = log.Output(ConsoleWriter).With().Timestamp().Logger()
// Create a root context
ctx := context.Background()
// Adding a logger to the context
ctx = context.WithValue(ctx, "logger", log.With().Str("component", "main").Logger())
// Use the logger from the context
doWork(ctx)
}
func doWork(ctx context.Context) {
// Retrieve the logger from the context
logger := ctx.Value("logger").(zerolog.Logger)
// Log an event
logger.Info().Msg("Starting work...")
// Simulating some work
logger.Info().Msg("Work in progress...")
// Indicate completion
logger.Info().Msg("Work completed successfully.")
}
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?