Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Golang's log output back to console?

Google Go's log package has SetOutput - a function for setting the log output to any io.Writer. After I set it for testing, I would like to revert the output back to the standard console output - how do I do that? I don't see any obvious way of resetting it in the log or io packages.

like image 389
ThePiachu Avatar asked Jun 07 '15 19:06

ThePiachu


People also ask

Where are console logs stored?

Steps to Open the Console Log in Google Chrome By default, the Inspect will open the "Elements" tab in the Developer Tools. Click on the "Console" tab which is to the right of "Elements". Now you can see the Console and any output that has been written to the Console log.

What is a console log file?

console. log specifically is a method for developers to write code to inconspicuously inform the developers what the code is doing. It can be used to alert you that there's an issue, but shouldn't take the place of an interactive debugger when it comes time to debug the code.

How do I get a log file?

"shortenFilePath()" method used to get the name of the file from full path of file. and "LogServer()" method is used to create a formatted log statement (contains : filename, line number, log level, error statement etc...) Save this answer.

How to set up logging in Golang?

NewProductionConfig() // we configure the destination for our log, in this case, a file config. OutputPaths = []string{"zap-demo. log"} // we build the logger zapLogger, err := config. Build() // Go doesn't support exceptions, so we check for the error, exiting the application if needed if err !=


1 Answers

For standard error (the default):

log.SetOutput(os.Stderr) 

For standard output:

log.SetOutput(os.Stdout) 

http://golang.org/src/log/log.go

like image 136
frhack Avatar answered Nov 13 '22 06:11

frhack