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.

logger.go 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. // Package log provides logging capabilities for Gitea.
  4. // Concepts:
  5. //
  6. // * Logger: a Logger provides logging functions and dispatches log events to all its writers
  7. //
  8. // * EventWriter: written log Event to a destination (eg: file, console)
  9. // - EventWriterBase: the base struct of a writer, it contains common fields and functions for all writers
  10. // - WriterType: the type name of a writer, eg: console, file
  11. // - WriterName: aka Mode Name in document, the name of a writer instance, it's usually defined by the config file.
  12. // It is called "mode name" because old code use MODE as config key, to keep compatibility, keep this concept.
  13. //
  14. // * WriterMode: the common options for all writers, eg: log level.
  15. // - WriterConsoleOption and others: the specified options for a writer, eg: file path, remote address.
  16. //
  17. // Call graph:
  18. // -> log.Info()
  19. // -> LoggerImpl.Log()
  20. // -> LoggerImpl.SendLogEvent, then the event goes into writer's goroutines
  21. // -> EventWriter.Run() handles the events
  22. package log
  23. // BaseLogger provides the basic logging functions
  24. type BaseLogger interface {
  25. Log(skip int, level Level, format string, v ...any)
  26. GetLevel() Level
  27. }
  28. // LevelLogger provides level-related logging functions
  29. type LevelLogger interface {
  30. LevelEnabled(level Level) bool
  31. Trace(format string, v ...any)
  32. Debug(format string, v ...any)
  33. Info(format string, v ...any)
  34. Warn(format string, v ...any)
  35. Error(format string, v ...any)
  36. Critical(format string, v ...any)
  37. }
  38. type Logger interface {
  39. BaseLogger
  40. LevelLogger
  41. }
  42. type LogStringer interface { //nolint:revive
  43. LogString() string
  44. }