log.go 840 B

123456789101112131415161718192021222324252627282930313233
  1. package golog
  2. import (
  3. "time"
  4. )
  5. // A Log represents a log line.
  6. type Log struct {
  7. // Logger is the original printer of this Log.
  8. Logger *Logger
  9. // Time is the current time
  10. Time time.Time
  11. // Level is the log level.
  12. Level Level
  13. // Message is the string reprensetation of the log's main body.
  14. Message string
  15. // NewLine returns false if this Log
  16. // derives from a `Print` function,
  17. // otherwise true if derives from a `Println`, `Error`, `Errorf`, `Warn`, etc...
  18. //
  19. // This NewLine does not mean that `Message` ends with "\n" (or `pio#NewLine`).
  20. // NewLine has to do with the methods called,
  21. // not the original content of the `Message`.
  22. NewLine bool
  23. }
  24. // FormatTime returns the formatted `Time`.
  25. func (l Log) FormatTime() string {
  26. if l.Logger.TimeFormat == "" {
  27. return ""
  28. }
  29. return l.Time.Format(l.Logger.TimeFormat)
  30. }