Using the standard logger
The standard library logger is defined in the log
package. It is a simple logging library that can be used to print formatted log messages that show the progression of a program. For most practical purposes, the standard library logger functionality is too limited, but it can be a useful tool that requires minimal setup for proof-of-concepts and smaller programs. Use the structured logger log/slog
package for any nontrivial project.
Writing log messages
The standard logger is a simple logging implementation to print diagnostic messages. It does not offer structured output or multiple log levels but can be useful for programs where log messages are geared toward the end users or developers.
How to do it...
You can use the default logger to print log messages:
log.Println("This is a log message similar to fmt.Println") log.Printf("This is a log message similar to fmt.Printf")
Here is the output:
2024/09/17 23:05:26 This...