A golang package for logging to a file
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
945 B

2 years ago
  1. package flog
  2. import (
  3. "io"
  4. "time"
  5. )
  6. // LevelType defines the level type
  7. type LevelType uint8
  8. // All possible log levels
  9. const (
  10. LevelDebug LevelType = iota
  11. LevelInfo
  12. LevelWarning
  13. LevelError
  14. LevelCritical
  15. )
  16. var levels = []string{`debug`, `info`, `warning`, `error`, `critical`}
  17. // String returns the name of the level as string
  18. func (l LevelType) String() string {
  19. return levels[l]
  20. }
  21. // LogEntry is an entry for the log
  22. type LogEntry struct {
  23. Level LevelType `json:"level"`
  24. Time time.Time `json:"time"`
  25. Message string `json:"message"`
  26. StackTrace []StackTraceEntry `json:"stack_trace,omitempty"`
  27. }
  28. // StackTraceEntry is an entry in the stack trace
  29. type StackTraceEntry struct {
  30. Function string `json:"function"`
  31. File string `json:"file"`
  32. Line int `json:"line"`
  33. }
  34. // LogFormatType defines the log format
  35. type LogFormatType interface {
  36. FormatMessage(io.Writer, LogEntry)
  37. }