gitea源码

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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, event *Event, 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 // export stutter
  43. LogString() string
  44. }