Usage of flag in New constructor of log package in Golang
Package log in Golang provides simple functionality for logging. In previous post we made several examples of usage New constructor for Logger. In this post will be exposed examples of usage New and meaning of third argument of New constructor. Let's begin with the simplest example. We will make logger that logs messages to standard output: package main import ( "log" "os" ) func main() { logger := log.New(os.Stdout, "", log.Ldate) logger.Println("First log message") } Output: 2020/04/21 First log message Let me remind signature of New: func New(out io.Writer, prefix string, flag int) *Logger In example as out io.Writer we used os.Stdout - standard output. As flag int used const from log package - log.Ldate - it is integer 1 - provides the date in the local time zone: 2020/04/21. Total there are 8 such constants in log package: log.Ldate - integer 1 - the date in the local time zone: 2020/04...