Logging customization
Besides the logging with the default logger from the log package, the standard library also provides a way to create the custom logger, according to the needs of the application or package. This recipe will give a brief insight on how to create one.
How to do it...
- Open the console and create the folder
chapter11/recipe01. - Navigate to the directory.
- Create the file
logging.gowith the following content:
package main
import (
"log"
"os"
)
func main() {
custLogger := log.New(os.Stdout, "custom1: ",
log.Ldate|log.Ltime)
custLogger.Println("Hello I'm customized")
custLoggerEnh := log.New(os.Stdout, "custom2: ",
log.Ldate|log.Lshortfile)
custLoggerEnh.Println("Hello I'm customized logger 2")
}- Execute the code by
go run logging.go. - See the output:

How it works...
The log package provides the New function which...