Golang logging: Difference between revisions
From wikinotes
(Created page with "Logging is a standardized format of writing progress/debug info. = Example = <blockquote> <syntaxhighlight lang="go"> // ./logger.go package main import "os" import "log" // params: // 1. device you'd like to log to // 2. log-prefix of this logger // 3. log-formatting options // var Logger = log.New(os.Stderr, "", log.Ldate|log.Ltime|log.Lshortfile) </syntaxhighlight> <syntaxhighlight lang="go"> // ./main.go package main func main() { Logger.Println("th...") |
No edit summary |
||
Line 5: | Line 5: | ||
<syntaxhighlight lang="go"> | <syntaxhighlight lang="go"> | ||
import "os" | import "os" | ||
import "log" | import "log" | ||
Line 18: | Line 14: | ||
// | // | ||
var Logger = log.New(os.Stderr, "", log.Ldate|log.Ltime|log.Lshortfile) | var Logger = log.New(os.Stderr, "", log.Ldate|log.Ltime|log.Lshortfile) | ||
func main() { | func main() { | ||
Logger.Println("this is a test") | Logger.Println("this is a test") | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Example --> | </blockquote><!-- Example --> |
Revision as of 21:34, 18 June 2022
Logging is a standardized format of writing progress/debug info.
Example
import "os" import "log" // params: // 1. device you'd like to log to // 2. log-prefix of this logger // 3. log-formatting options // var Logger = log.New(os.Stderr, "", log.Ldate|log.Ltime|log.Lshortfile) func main() { Logger.Println("this is a test") }