Golang logging

From wikinotes
Revision as of 21:30, 18 June 2022 by Will (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Logging is a standardized format of writing progress/debug info.

Example

// ./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)
// ./main.go

package main

func main() {
    Logger.Println("this is a test")
}
go run main.go logger.go  # build/run