Where do I find the log and how do I read it

I have an app and part of what the app does is write to the log. Where do I find this log because I cannot find it at all. Is there a command you must run to view the log or what?

Read over this as it will explain in more detail about the logging package.

By default the log is printed to the console you run your application from, but can be set to a specified file.

2 Likes

Interesting article! However one thing which is wrong in the article is “don’t log from go routines”. All functions of package log goes thru a function which uses a mutex so multiple go routines can write to same log.

For example https://golang.org/src/log/log.go?s=6167:6207#L188

func (l *Logger) Println(v ...interface{}) { l.Output(2, fmt.Sprintln(v...)) }

calls l.Output https://golang.org/src/log/log.go?s=6167:6207#L149 which uses a mutex

func (l *Logger) Output(calldepth int, s string) error {
	now := time.Now() // get this early.
	var file string
	var line int
	l.mu.Lock()
	defer l.mu.Unlock()
       .....
1 Like

Thank you for your inset it’s much appreciated

Thank you I will read over it

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.