August 2019
Beginner to intermediate
798 pages
17h 2m
English
In this section, you are going to learn how to print the line number of the source file that executed the statement that wrote the log entry to a log file using the Go code of customLogLineNumber.go. This will be presented in two parts. The first part is as follows:
package main
import (
"fmt"
"log"
"os"
)
var LOGFILE = "/tmp/mGo.log"
func main() {
f, err := os.OpenFile(LOGFILE, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
fmt.Println(err)
return
}
defer f.Close()
So far, there is nothing special when compared to the code of customLog.go.
The remaining Go code of customLogLineNumber.go is as follows:
iLog := log.New(f, "customLogLineNumber ", log.LstdFlags) iLog.SetFlags(log.LstdFlags ...
Read now
Unlock full access