O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The log package provides the New function which simplifies the creation of a customized logger. The New function consumes the Writer, which could be any object implementing the Writer interface, the prefix in the form of the string, and the form of the logged message that is composed of flags. The last argument is the most interesting because with it, you are able to enhance the log message with dynamic fields, such as date and filename.

Note that the preceding example uses, for the first logger, the custLogger, the flags configuring the message to display the date and time in front of the log message. The second one, named the custLoggerEnh, uses the flag, Ldate and Lshortfile, to show the filename and date.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required