global.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package log
  2. import (
  3. "fmt"
  4. "io"
  5. "os"
  6. )
  7. var (
  8. DefaultHandler = StreamHandler{
  9. W: os.Stderr,
  10. Fmt: twoLineFormatter,
  11. }
  12. Default Logger // Inited after GO_LOG is parsed.
  13. DiscardHandler = StreamHandler{
  14. W: io.Discard,
  15. Fmt: func(Record) []byte { return nil },
  16. }
  17. )
  18. // Logs a message to the [Default] Logger with text formatted in the style of [fmt.Printf], with the
  19. // given [Level].
  20. func Levelf(level Level, format string, a ...interface{}) {
  21. Default.LazyLog(level, func() Msg {
  22. return Fmsg(format, a...).Skip(1)
  23. })
  24. }
  25. // Prints the arguments to the [Default] Logger in the style of [fmt] functions of similar names.
  26. func Printf(format string, a ...interface{}) {
  27. Default.Log(Fmsg(format, a...).Skip(1))
  28. }
  29. // Prints the arguments to the [Default] Logger in the style of [fmt] functions of similar names.
  30. func Print(a ...interface{}) {
  31. // TODO: There's no "Print" equivalent constructor for a Msg, and I don't know what I'd call it.
  32. Str(fmt.Sprint(a...)).Skip(1).Log(Default)
  33. }
  34. // Prints the arguments to the [Default] Logger in the style of [fmt] functions of similar names.
  35. func Println(a ...interface{}) {
  36. Default.LazyLogDefaultLevel(func() Msg {
  37. return Msgln(a...).Skip(1)
  38. })
  39. }