Skip to content

Instantly share code, notes, and snippets.

@dimitrilw
Last active July 15, 2023 02:09
Show Gist options
  • Save dimitrilw/990d3a29ff77767389dd1e9cc66e7ce2 to your computer and use it in GitHub Desktop.
Save dimitrilw/990d3a29ff77767389dd1e9cc66e7ce2 to your computer and use it in GitHub Desktop.
golang default logger for use in coding challenges
import (
// most already have these imported; putting here just in case
"log"
"os"
)
var (
// logger = log.New(os.Stdout, "", log.Lshortfile)
logger1 = log.New(os.Stdout, "optional prefix: ", log.LstdFlags|log.Lshortfile)
logger2 = log.New(os.Stdout, "log 2: ", log.Lshortfile)
)
func testLog() {
logger1.Println("inside testLog")
logger2.Println("also inside testLog")
}
func demoMain() {
logger2.Println("Hello, world!")
testLog()
logger1.Println("Goodbye.")
}
// approx output:
// log 2: some_filename.go:19: Hello, world!
// optional prefix: 2023/07/11 22:04:35 some_filename.go:14: inside testLog
// log 2: some_filename.go:15: also inside testLog
// optional prefix: 2023/07/11 22:04:35 some_filename.go:21: Goodbye.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment