fortio.org/log@v1.12.2/levelsDemo/levels.go (about)

     1  // Initially from https://github.com/fortio/logc/blob/v1.1.0/levelsDemo/levels.go
     2  package main
     3  
     4  import (
     5  	"fmt"
     6  
     7  	"fortio.org/log"
     8  )
     9  
    10  func main() {
    11  	log.SetLogLevelQuiet(log.Debug)
    12  	log.Config.LogFileAndLine = false
    13  	log.Config.LogPrefix = ""
    14  	log.Config.GoroutineID = false
    15  	log.Debugf("This is a debug message without goroutine id, file:line nor prefix (cli style)")
    16  	log.Config = log.DefaultConfig()
    17  	// So log fatal doesn't panic nor exit (so we can print the non json last line).
    18  	log.Config.FatalPanics = false
    19  	log.Config.FatalExit = func(int) {}
    20  	// Meat of the example: (some of these are reproducing fixed issues in `logc` json->console attributes detection)
    21  	log.Debugf("Back to default (server) logging style with a debug message ending with backslash \\")
    22  	log.LogVf("This is a verbose message")
    23  	log.Printf("This an always printed, file:line omitted message (and no level in console)")
    24  	log.Infof("This is an info message with no attributes but with \"quotes\"...")
    25  	log.S(log.Info, "This is multi line\n\tstructured info message with 3 attributes",
    26  		log.Str("attr1", "value1"), log.Attr("attr2", 42), log.Str("attr3", "\"quoted\nvalue\""))
    27  	log.Warnf("This is a warning message")
    28  	log.Errf("This is an error message")
    29  	log.Critf("This is a critical message")
    30  	log.Fatalf("This is a fatal message") //nolint:revive // we disabled exit for this demo
    31  	fmt.Println("This is a non json output, will get prefixed with a exclamation point with logc")
    32  }