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.

logging-config.en-us.md 12KB

Rewrite logger system (#24726) ## ⚠️ Breaking The `log.<mode>.<logger>` style config has been dropped. If you used it, please check the new config manual & app.example.ini to make your instance output logs as expected. Although many legacy options still work, it's encouraged to upgrade to the new options. The SMTP logger is deleted because SMTP is not suitable to collect logs. If you have manually configured Gitea log options, please confirm the logger system works as expected after upgrading. ## Description Close #12082 and maybe more log-related issues, resolve some related FIXMEs in old code (which seems unfixable before) Just like rewriting queue #24505 : make code maintainable, clear legacy bugs, and add the ability to support more writers (eg: JSON, structured log) There is a new document (with examples): `logging-config.en-us.md` This PR is safer than the queue rewriting, because it's just for logging, it won't break other logic. ## The old problems The logging system is quite old and difficult to maintain: * Unclear concepts: Logger, NamedLogger, MultiChannelledLogger, SubLogger, EventLogger, WriterLogger etc * Some code is diffuclt to konw whether it is right: `log.DelNamedLogger("console")` vs `log.DelNamedLogger(log.DEFAULT)` vs `log.DelLogger("console")` * The old system heavily depends on ini config system, it's difficult to create new logger for different purpose, and it's very fragile. * The "color" trick is difficult to use and read, many colors are unnecessary, and in the future structured log could help * It's difficult to add other log formats, eg: JSON format * The log outputer doesn't have full control of its goroutine, it's difficult to make outputer have advanced behaviors * The logs could be lost in some cases: eg: no Fatal error when using CLI. * Config options are passed by JSON, which is quite fragile. * INI package makes the KEY in `[log]` section visible in `[log.sub1]` and `[log.sub1.subA]`, this behavior is quite fragile and would cause more unclear problems, and there is no strong requirement to support `log.<mode>.<logger>` syntax. ## The new design See `logger.go` for documents. ## Screenshot <details> ![image](https://github.com/go-gitea/gitea/assets/2114189/4462d713-ba39-41f5-bb08-de912e67e1ff) ![image](https://github.com/go-gitea/gitea/assets/2114189/b188035e-f691-428b-8b2d-ff7b2199b2f9) ![image](https://github.com/go-gitea/gitea/assets/2114189/132e9745-1c3b-4e00-9e0d-15eaea495dee) </details> ## TODO * [x] add some new tests * [x] fix some tests * [x] test some sub-commands (manually ....) --------- Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Giteabot <teabot@gitea.io>
1 year ago
Rewrite logger system (#24726) ## ⚠️ Breaking The `log.<mode>.<logger>` style config has been dropped. If you used it, please check the new config manual & app.example.ini to make your instance output logs as expected. Although many legacy options still work, it's encouraged to upgrade to the new options. The SMTP logger is deleted because SMTP is not suitable to collect logs. If you have manually configured Gitea log options, please confirm the logger system works as expected after upgrading. ## Description Close #12082 and maybe more log-related issues, resolve some related FIXMEs in old code (which seems unfixable before) Just like rewriting queue #24505 : make code maintainable, clear legacy bugs, and add the ability to support more writers (eg: JSON, structured log) There is a new document (with examples): `logging-config.en-us.md` This PR is safer than the queue rewriting, because it's just for logging, it won't break other logic. ## The old problems The logging system is quite old and difficult to maintain: * Unclear concepts: Logger, NamedLogger, MultiChannelledLogger, SubLogger, EventLogger, WriterLogger etc * Some code is diffuclt to konw whether it is right: `log.DelNamedLogger("console")` vs `log.DelNamedLogger(log.DEFAULT)` vs `log.DelLogger("console")` * The old system heavily depends on ini config system, it's difficult to create new logger for different purpose, and it's very fragile. * The "color" trick is difficult to use and read, many colors are unnecessary, and in the future structured log could help * It's difficult to add other log formats, eg: JSON format * The log outputer doesn't have full control of its goroutine, it's difficult to make outputer have advanced behaviors * The logs could be lost in some cases: eg: no Fatal error when using CLI. * Config options are passed by JSON, which is quite fragile. * INI package makes the KEY in `[log]` section visible in `[log.sub1]` and `[log.sub1.subA]`, this behavior is quite fragile and would cause more unclear problems, and there is no strong requirement to support `log.<mode>.<logger>` syntax. ## The new design See `logger.go` for documents. ## Screenshot <details> ![image](https://github.com/go-gitea/gitea/assets/2114189/4462d713-ba39-41f5-bb08-de912e67e1ff) ![image](https://github.com/go-gitea/gitea/assets/2114189/b188035e-f691-428b-8b2d-ff7b2199b2f9) ![image](https://github.com/go-gitea/gitea/assets/2114189/132e9745-1c3b-4e00-9e0d-15eaea495dee) </details> ## TODO * [x] add some new tests * [x] fix some tests * [x] test some sub-commands (manually ....) --------- Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Giteabot <teabot@gitea.io>
1 year ago
Rewrite logger system (#24726) ## ⚠️ Breaking The `log.<mode>.<logger>` style config has been dropped. If you used it, please check the new config manual & app.example.ini to make your instance output logs as expected. Although many legacy options still work, it's encouraged to upgrade to the new options. The SMTP logger is deleted because SMTP is not suitable to collect logs. If you have manually configured Gitea log options, please confirm the logger system works as expected after upgrading. ## Description Close #12082 and maybe more log-related issues, resolve some related FIXMEs in old code (which seems unfixable before) Just like rewriting queue #24505 : make code maintainable, clear legacy bugs, and add the ability to support more writers (eg: JSON, structured log) There is a new document (with examples): `logging-config.en-us.md` This PR is safer than the queue rewriting, because it's just for logging, it won't break other logic. ## The old problems The logging system is quite old and difficult to maintain: * Unclear concepts: Logger, NamedLogger, MultiChannelledLogger, SubLogger, EventLogger, WriterLogger etc * Some code is diffuclt to konw whether it is right: `log.DelNamedLogger("console")` vs `log.DelNamedLogger(log.DEFAULT)` vs `log.DelLogger("console")` * The old system heavily depends on ini config system, it's difficult to create new logger for different purpose, and it's very fragile. * The "color" trick is difficult to use and read, many colors are unnecessary, and in the future structured log could help * It's difficult to add other log formats, eg: JSON format * The log outputer doesn't have full control of its goroutine, it's difficult to make outputer have advanced behaviors * The logs could be lost in some cases: eg: no Fatal error when using CLI. * Config options are passed by JSON, which is quite fragile. * INI package makes the KEY in `[log]` section visible in `[log.sub1]` and `[log.sub1.subA]`, this behavior is quite fragile and would cause more unclear problems, and there is no strong requirement to support `log.<mode>.<logger>` syntax. ## The new design See `logger.go` for documents. ## Screenshot <details> ![image](https://github.com/go-gitea/gitea/assets/2114189/4462d713-ba39-41f5-bb08-de912e67e1ff) ![image](https://github.com/go-gitea/gitea/assets/2114189/b188035e-f691-428b-8b2d-ff7b2199b2f9) ![image](https://github.com/go-gitea/gitea/assets/2114189/132e9745-1c3b-4e00-9e0d-15eaea495dee) </details> ## TODO * [x] add some new tests * [x] fix some tests * [x] test some sub-commands (manually ....) --------- Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Giteabot <teabot@gitea.io>
1 year ago
Rewrite logger system (#24726) ## ⚠️ Breaking The `log.<mode>.<logger>` style config has been dropped. If you used it, please check the new config manual & app.example.ini to make your instance output logs as expected. Although many legacy options still work, it's encouraged to upgrade to the new options. The SMTP logger is deleted because SMTP is not suitable to collect logs. If you have manually configured Gitea log options, please confirm the logger system works as expected after upgrading. ## Description Close #12082 and maybe more log-related issues, resolve some related FIXMEs in old code (which seems unfixable before) Just like rewriting queue #24505 : make code maintainable, clear legacy bugs, and add the ability to support more writers (eg: JSON, structured log) There is a new document (with examples): `logging-config.en-us.md` This PR is safer than the queue rewriting, because it's just for logging, it won't break other logic. ## The old problems The logging system is quite old and difficult to maintain: * Unclear concepts: Logger, NamedLogger, MultiChannelledLogger, SubLogger, EventLogger, WriterLogger etc * Some code is diffuclt to konw whether it is right: `log.DelNamedLogger("console")` vs `log.DelNamedLogger(log.DEFAULT)` vs `log.DelLogger("console")` * The old system heavily depends on ini config system, it's difficult to create new logger for different purpose, and it's very fragile. * The "color" trick is difficult to use and read, many colors are unnecessary, and in the future structured log could help * It's difficult to add other log formats, eg: JSON format * The log outputer doesn't have full control of its goroutine, it's difficult to make outputer have advanced behaviors * The logs could be lost in some cases: eg: no Fatal error when using CLI. * Config options are passed by JSON, which is quite fragile. * INI package makes the KEY in `[log]` section visible in `[log.sub1]` and `[log.sub1.subA]`, this behavior is quite fragile and would cause more unclear problems, and there is no strong requirement to support `log.<mode>.<logger>` syntax. ## The new design See `logger.go` for documents. ## Screenshot <details> ![image](https://github.com/go-gitea/gitea/assets/2114189/4462d713-ba39-41f5-bb08-de912e67e1ff) ![image](https://github.com/go-gitea/gitea/assets/2114189/b188035e-f691-428b-8b2d-ff7b2199b2f9) ![image](https://github.com/go-gitea/gitea/assets/2114189/132e9745-1c3b-4e00-9e0d-15eaea495dee) </details> ## TODO * [x] add some new tests * [x] fix some tests * [x] test some sub-commands (manually ....) --------- Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Giteabot <teabot@gitea.io>
1 year ago
Rewrite logger system (#24726) ## ⚠️ Breaking The `log.<mode>.<logger>` style config has been dropped. If you used it, please check the new config manual & app.example.ini to make your instance output logs as expected. Although many legacy options still work, it's encouraged to upgrade to the new options. The SMTP logger is deleted because SMTP is not suitable to collect logs. If you have manually configured Gitea log options, please confirm the logger system works as expected after upgrading. ## Description Close #12082 and maybe more log-related issues, resolve some related FIXMEs in old code (which seems unfixable before) Just like rewriting queue #24505 : make code maintainable, clear legacy bugs, and add the ability to support more writers (eg: JSON, structured log) There is a new document (with examples): `logging-config.en-us.md` This PR is safer than the queue rewriting, because it's just for logging, it won't break other logic. ## The old problems The logging system is quite old and difficult to maintain: * Unclear concepts: Logger, NamedLogger, MultiChannelledLogger, SubLogger, EventLogger, WriterLogger etc * Some code is diffuclt to konw whether it is right: `log.DelNamedLogger("console")` vs `log.DelNamedLogger(log.DEFAULT)` vs `log.DelLogger("console")` * The old system heavily depends on ini config system, it's difficult to create new logger for different purpose, and it's very fragile. * The "color" trick is difficult to use and read, many colors are unnecessary, and in the future structured log could help * It's difficult to add other log formats, eg: JSON format * The log outputer doesn't have full control of its goroutine, it's difficult to make outputer have advanced behaviors * The logs could be lost in some cases: eg: no Fatal error when using CLI. * Config options are passed by JSON, which is quite fragile. * INI package makes the KEY in `[log]` section visible in `[log.sub1]` and `[log.sub1.subA]`, this behavior is quite fragile and would cause more unclear problems, and there is no strong requirement to support `log.<mode>.<logger>` syntax. ## The new design See `logger.go` for documents. ## Screenshot <details> ![image](https://github.com/go-gitea/gitea/assets/2114189/4462d713-ba39-41f5-bb08-de912e67e1ff) ![image](https://github.com/go-gitea/gitea/assets/2114189/b188035e-f691-428b-8b2d-ff7b2199b2f9) ![image](https://github.com/go-gitea/gitea/assets/2114189/132e9745-1c3b-4e00-9e0d-15eaea495dee) </details> ## TODO * [x] add some new tests * [x] fix some tests * [x] test some sub-commands (manually ....) --------- Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Giteabot <teabot@gitea.io>
1 year ago
Rewrite logger system (#24726) ## ⚠️ Breaking The `log.<mode>.<logger>` style config has been dropped. If you used it, please check the new config manual & app.example.ini to make your instance output logs as expected. Although many legacy options still work, it's encouraged to upgrade to the new options. The SMTP logger is deleted because SMTP is not suitable to collect logs. If you have manually configured Gitea log options, please confirm the logger system works as expected after upgrading. ## Description Close #12082 and maybe more log-related issues, resolve some related FIXMEs in old code (which seems unfixable before) Just like rewriting queue #24505 : make code maintainable, clear legacy bugs, and add the ability to support more writers (eg: JSON, structured log) There is a new document (with examples): `logging-config.en-us.md` This PR is safer than the queue rewriting, because it's just for logging, it won't break other logic. ## The old problems The logging system is quite old and difficult to maintain: * Unclear concepts: Logger, NamedLogger, MultiChannelledLogger, SubLogger, EventLogger, WriterLogger etc * Some code is diffuclt to konw whether it is right: `log.DelNamedLogger("console")` vs `log.DelNamedLogger(log.DEFAULT)` vs `log.DelLogger("console")` * The old system heavily depends on ini config system, it's difficult to create new logger for different purpose, and it's very fragile. * The "color" trick is difficult to use and read, many colors are unnecessary, and in the future structured log could help * It's difficult to add other log formats, eg: JSON format * The log outputer doesn't have full control of its goroutine, it's difficult to make outputer have advanced behaviors * The logs could be lost in some cases: eg: no Fatal error when using CLI. * Config options are passed by JSON, which is quite fragile. * INI package makes the KEY in `[log]` section visible in `[log.sub1]` and `[log.sub1.subA]`, this behavior is quite fragile and would cause more unclear problems, and there is no strong requirement to support `log.<mode>.<logger>` syntax. ## The new design See `logger.go` for documents. ## Screenshot <details> ![image](https://github.com/go-gitea/gitea/assets/2114189/4462d713-ba39-41f5-bb08-de912e67e1ff) ![image](https://github.com/go-gitea/gitea/assets/2114189/b188035e-f691-428b-8b2d-ff7b2199b2f9) ![image](https://github.com/go-gitea/gitea/assets/2114189/132e9745-1c3b-4e00-9e0d-15eaea495dee) </details> ## TODO * [x] add some new tests * [x] fix some tests * [x] test some sub-commands (manually ....) --------- Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Giteabot <teabot@gitea.io>
1 year ago
Rewrite logger system (#24726) ## ⚠️ Breaking The `log.<mode>.<logger>` style config has been dropped. If you used it, please check the new config manual & app.example.ini to make your instance output logs as expected. Although many legacy options still work, it's encouraged to upgrade to the new options. The SMTP logger is deleted because SMTP is not suitable to collect logs. If you have manually configured Gitea log options, please confirm the logger system works as expected after upgrading. ## Description Close #12082 and maybe more log-related issues, resolve some related FIXMEs in old code (which seems unfixable before) Just like rewriting queue #24505 : make code maintainable, clear legacy bugs, and add the ability to support more writers (eg: JSON, structured log) There is a new document (with examples): `logging-config.en-us.md` This PR is safer than the queue rewriting, because it's just for logging, it won't break other logic. ## The old problems The logging system is quite old and difficult to maintain: * Unclear concepts: Logger, NamedLogger, MultiChannelledLogger, SubLogger, EventLogger, WriterLogger etc * Some code is diffuclt to konw whether it is right: `log.DelNamedLogger("console")` vs `log.DelNamedLogger(log.DEFAULT)` vs `log.DelLogger("console")` * The old system heavily depends on ini config system, it's difficult to create new logger for different purpose, and it's very fragile. * The "color" trick is difficult to use and read, many colors are unnecessary, and in the future structured log could help * It's difficult to add other log formats, eg: JSON format * The log outputer doesn't have full control of its goroutine, it's difficult to make outputer have advanced behaviors * The logs could be lost in some cases: eg: no Fatal error when using CLI. * Config options are passed by JSON, which is quite fragile. * INI package makes the KEY in `[log]` section visible in `[log.sub1]` and `[log.sub1.subA]`, this behavior is quite fragile and would cause more unclear problems, and there is no strong requirement to support `log.<mode>.<logger>` syntax. ## The new design See `logger.go` for documents. ## Screenshot <details> ![image](https://github.com/go-gitea/gitea/assets/2114189/4462d713-ba39-41f5-bb08-de912e67e1ff) ![image](https://github.com/go-gitea/gitea/assets/2114189/b188035e-f691-428b-8b2d-ff7b2199b2f9) ![image](https://github.com/go-gitea/gitea/assets/2114189/132e9745-1c3b-4e00-9e0d-15eaea495dee) </details> ## TODO * [x] add some new tests * [x] fix some tests * [x] test some sub-commands (manually ....) --------- Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Giteabot <teabot@gitea.io>
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. ---
  2. date: "2019-04-02T17:06:00+01:00"
  3. title: "Logging Configuration"
  4. slug: "logging-config"
  5. sidebar_position: 40
  6. toc: false
  7. draft: false
  8. aliases:
  9. - /en-us/logging-configuration
  10. menu:
  11. sidebar:
  12. parent: "administration"
  13. name: "Logging Configuration"
  14. sidebar_position: 40
  15. identifier: "logging-config"
  16. ---
  17. # Logging Configuration
  18. The logging configuration of Gitea mainly consists of 3 types of components:
  19. - The `[log]` section for general configuration
  20. - `[log.<mode-name>]` sections for the configuration of different log writers to output logs, aka: "writer mode", the mode name is also used as "writer name".
  21. - The `[log]` section can also contain sub-logger configurations following the key schema `logger.<logger-name>.<CONFIG-KEY>`
  22. There is a fully functional log output by default, so it is not necessary to define one.
  23. ## Collecting Logs for Help
  24. To collect logs for help and issue report, see [Support Options](help/support.md).
  25. ## The `[log]` section
  26. Configuration of logging facilities in Gitea happen in the `[log]` section and its subsections.
  27. In the top level `[log]` section the following configurations can be placed:
  28. - `ROOT_PATH`: (Default: **%(GITEA_WORK_DIR)/log**): Base path for log files
  29. - `MODE`: (Default: **console**) List of log outputs to use for the Default logger.
  30. - `LEVEL`: (Default: **Info**) Least severe log events to persist, case-insensitive. Possible values are: `Trace`, `Debug`, `Info`, `Warn`, `Error`, `Fatal`.
  31. - `STACKTRACE_LEVEL`: (Default: **None**) For this and more severe events the stacktrace will be printed upon getting logged.
  32. And it can contain the following sub-loggers:
  33. - `logger.router.MODE`: (Default: **,**): List of log outputs to use for the Router logger.
  34. - `logger.access.MODE`: (Default: **_empty_**) List of log outputs to use for the Access logger. By default, the access logger is disabled.
  35. - `logger.xorm.MODE`: (Default: **,**) List of log outputs to use for the XORM logger.
  36. Setting a comma (`,`) to sub-logger's mode means making it use the default global `MODE`.
  37. ## Quick samples
  38. ### Default (empty) Configuration
  39. The empty configuration is equivalent to default:
  40. ```ini
  41. [log]
  42. ROOT_PATH = %(GITEA_WORK_DIR)/log
  43. MODE = console
  44. LEVEL = Info
  45. STACKTRACE_LEVEL = None
  46. logger.router.MODE = ,
  47. logger.xorm.MODE = ,
  48. logger.access.MODE =
  49. ; this is the config options of "console" mode (used by MODE=console above)
  50. [log.console]
  51. MODE = console
  52. FLAGS = stdflags
  53. PREFIX =
  54. COLORIZE = true
  55. ```
  56. This is equivalent to sending all logs to the console, with default Golang log being sent to the console log too.
  57. This is only a sample, and it is the default, do not need to write it into your configuration file.
  58. ### Disable Router logs and record some access logs to file
  59. The Router logger is disabled, the access logs (>=Warn) goes into `access.log`:
  60. ```ini
  61. [log]
  62. logger.router.MODE =
  63. logger.access.MODE = access-file
  64. [log.access-file]
  65. MODE = file
  66. LEVEL = Warn
  67. FILE_NAME = access.log
  68. ```
  69. ### Set different log levels for different modes
  70. Default logs (>=Warn) goes into `gitea.log`, while Error logs goes into `file-error.log`:
  71. ```ini
  72. [log]
  73. LEVEL = Warn
  74. MODE = file, file-error
  75. ; by default, the "file" mode will record logs to %(log.ROOT_PATH)/gitea.log, so we don't need to set it
  76. ; [log.file]
  77. ; by default, the MODE (actually it's the output writer of this logger) is taken from the section name, so we don't need to set it either
  78. ; MODE = file
  79. [log.file-error]
  80. MODE = file
  81. LEVEL = Error
  82. FILE_NAME = file-error.log
  83. ```
  84. ## Log outputs (mode and writer)
  85. Gitea provides the following log output writers:
  86. - `console` - Log to `stdout` (or `stderr` if it is set in the config)
  87. - `file` - Log to a file
  88. - `conn` - Log to a socket (network or unix)
  89. ### Common configuration
  90. Certain configuration is common to all modes of log output:
  91. - `MODE` is the mode of the log output writer. It will default to the mode name in the ini section. Thus `[log.console]` will default to `MODE = console`.
  92. - `LEVEL` is the lowest level that this output will log.
  93. - `STACKTRACE_LEVEL` is the lowest level that this output will print a stacktrace.
  94. - `COLORIZE` will default to `true` for `console` as described, otherwise it will default to `false`.
  95. #### `EXPRESSION`
  96. `EXPRESSION` represents a regular expression that log events must match to be logged by the output writer.
  97. Either the log message, (with colors removed), must match or the `longfilename:linenumber:functionname` must match.
  98. NB: the whole message or string doesn't need to completely match.
  99. Please note this expression will be run in the writer's goroutine but not the logging event goroutine.
  100. #### `FLAGS`
  101. `FLAGS` represents the preceding logging context information that is
  102. printed before each message. It is a comma-separated string set. The order of values does not matter.
  103. It defaults to `stdflags` (= `date,time,medfile,shortfuncname,levelinitial`)
  104. Possible values are:
  105. - `none` or `,` - No flags.
  106. - `date` - the date in the local time zone: `2009/01/23`.
  107. - `time` - the time in the local time zone: `01:23:23`.
  108. - `microseconds` - microsecond resolution: `01:23:23.123123`. Assumes time.
  109. - `longfile` - full file name and line number: `/a/b/c/d.go:23`.
  110. - `shortfile` - final file name element and line number: `d.go:23`.
  111. - `funcname` - function name of the caller: `runtime.Caller()`.
  112. - `shortfuncname` - last part of the function name. Overrides `funcname`.
  113. - `utc` - if date or time is set, use UTC rather than the local time zone.
  114. - `levelinitial` - initial character of the provided level in brackets eg. `[I]` for info.
  115. - `level` - level in brackets `[INFO]`.
  116. - `gopid` - the Goroutine-PID of the context.
  117. - `medfile` - last 20 characters of the filename - equivalent to `shortfile,longfile`.
  118. - `stdflags` - equivalent to `date,time,medfile,shortfuncname,levelinitial`.
  119. ### Console mode
  120. In this mode the logger will forward log messages to the stdout and
  121. stderr streams attached to the Gitea process.
  122. For loggers in console mode, `COLORIZE` will default to `true` if not
  123. on windows, or the Windows terminal can be set into ANSI mode or is a
  124. cygwin or Msys pipe.
  125. Settings:
  126. - `STDERR`: **false**: Whether the logger should print to `stderr` instead of `stdout`.
  127. ### File mode
  128. In this mode the logger will save log messages to a file.
  129. Settings:
  130. - `FILE_NAME`: The file to write the log events to, relative to `ROOT_PATH`, Default to `%(ROOT_PATH)/gitea.log`. Exception: access log will default to `%(ROOT_PATH)/access.log`.
  131. - `MAX_SIZE_SHIFT`: **28**: Maximum size shift of a single file. 28 represents 256Mb. For details see below.
  132. - `LOG_ROTATE` **true**: Whether to rotate the log files. TODO: if false, will it delete instead on daily rotate, or do nothing?.
  133. - `DAILY_ROTATE`: **true**: Whether to rotate logs daily.
  134. - `MAX_DAYS`: **7**: Delete rotated log files after this number of days.
  135. - `COMPRESS`: **true**: Whether to compress old log files by default with gzip.
  136. - `COMPRESSION_LEVEL`: **-1**: Compression level. For details see below.
  137. `MAX_SIZE_SHIFT` defines the maximum size of a file by left shifting 1 the given number of times (`1 << x`).
  138. The exact behavior at the time of v1.17.3 can be seen [here](https://github.com/go-gitea/gitea/blob/v1.17.3/modules/setting/log.go#L185).
  139. The useful values of `COMPRESSION_LEVEL` are from 1 to (and including) 9, where higher numbers mean better compression.
  140. Beware that better compression might come with higher resource usage.
  141. Must be preceded with a `-` sign.
  142. ### Conn mode
  143. In this mode the logger will send log messages over a network socket.
  144. Settings:
  145. - `ADDR`: **:7020**: Sets the address to connect to.
  146. - `PROTOCOL`: **tcp**: Set the protocol, either "tcp", "unix" or "udp".
  147. - `RECONNECT`: **false**: Try to reconnect when connection is lost.
  148. - `RECONNECT_ON_MSG`: **false**: Reconnect host for every single message.
  149. ### The "Router" logger
  150. The Router logger logs the following message types when Gitea's route handlers work:
  151. - `started` messages will be logged at TRACE level
  152. - `polling`/`completed` routers will be logged at INFO. Exception: "/assets" static resource requests are also logged at TRACE.
  153. - `slow` routers will be logged at WARN
  154. - `failed` routers will be logged at WARN
  155. ### The "XORM" logger
  156. To make XORM outputs SQL logs, the `LOG_SQL` in `[database]` section should also be set to `true`.
  157. ### The "Access" logger
  158. The Access logger is a new logger since Gitea 1.9. It provides a NCSA
  159. Common Log compliant log format. It's highly configurable but caution
  160. should be taken when changing its template. The main benefit of this
  161. logger is that Gitea can now log accesses in a standard log format so
  162. standard tools may be used.
  163. You can enable this logger using `logger.access.MODE = ...`.
  164. If desired the format of the Access logger can be changed by changing
  165. the value of the `ACCESS_LOG_TEMPLATE`.
  166. Please note, the access logger will log at `INFO` level, setting the
  167. `LEVEL` of this logger to `WARN` or above will result in no access logs.
  168. #### The ACCESS_LOG_TEMPLATE
  169. This value represents a go template. Its default value is
  170. ```tmpl
  171. {{.Ctx.RemoteHost}} - {{.Identity}} {{.Start.Format "[02/Jan/2006:15:04:05 -0700]" }} "{{.Ctx.Req.Method}} {{.Ctx.Req.URL.RequestURI}} {{.Ctx.Req.Proto}}" {{.ResponseWriter.Status}} {{.ResponseWriter.Size}} "{{.Ctx.Req.Referer}}" "{{.Ctx.Req.UserAgent}}"`
  172. ```
  173. The template is passed following options:
  174. - `Ctx` is the `context.Context`
  175. - `Identity` is the `SignedUserName` or `"-"` if the user is not logged in
  176. - `Start` is the start time of the request
  177. - `ResponseWriter` is the `http.ResponseWriter`
  178. Caution must be taken when changing this template as it runs outside of
  179. the standard panic recovery trap. The template should also be as simple
  180. as it runs for every request.
  181. ## Releasing-and-Reopening, Pausing and Resuming logging
  182. If you are running on Unix you may wish to release-and-reopen logs in order to use `logrotate` or other tools.
  183. It is possible force Gitea to release and reopen it's logging files and connections by sending `SIGUSR1` to the
  184. running process, or running `gitea manager logging release-and-reopen`.
  185. Alternatively, you may wish to pause and resume logging - this can be accomplished through the use of the
  186. `gitea manager logging pause` and `gitea manager logging resume` commands. Please note that whilst logging
  187. is paused log events below INFO level will not be stored and only a limited number of events will be stored.
  188. Logging may block, albeit temporarily, slowing Gitea considerably whilst paused - therefore it is
  189. recommended that pausing only done for a very short period of time.
  190. ## Adding and removing logging whilst Gitea is running
  191. It is possible to add and remove logging whilst Gitea is running using the `gitea manager logging add` and `remove` subcommands.
  192. This functionality can only adjust running log systems and cannot be used to start the access or router loggers if they
  193. were not already initialized. If you wish to start these systems you are advised to adjust the app.ini and (gracefully) restart
  194. the Gitea service.
  195. The main intention of these commands is to easily add a temporary logger to investigate problems on running systems where a restart
  196. may cause the issue to disappear.
  197. ## Using `logrotate` instead of built-in log rotation
  198. Gitea includes built-in log rotation, which should be enough for most deployments. However, if you instead want to use the `logrotate` utility:
  199. - Disable built-in log rotation by setting `LOG_ROTATE` to `false` in your `app.ini`.
  200. - Install `logrotate`.
  201. - Configure `logrotate` to match your deployment requirements, see `man 8 logrotate` for configuration syntax details.
  202. In the `postrotate/endscript` block send Gitea a `USR1` signal via `kill -USR1` or `kill -10` to the `gitea` process itself,
  203. or run `gitea manager logging release-and-reopen` (with the appropriate environment).
  204. Ensure that your configurations apply to all files emitted by Gitea loggers as described in the above sections.
  205. - Always do `logrotate /etc/logrotate.conf --debug` to test your configurations.
  206. - If you are using docker and are running from outside the container you can use
  207. `docker exec -u $OS_USER $CONTAINER_NAME sh -c 'gitea manager logging release-and-reopen'`
  208. or `docker exec $CONTAINER_NAME sh -c '/bin/s6-svc -1 /etc/s6/gitea/'` or send `USR1` directly to the Gitea process itself.
  209. The next `logrotate` jobs will include your configurations, so no restart is needed.
  210. You can also immediately reload `logrotate` with `logrotate /etc/logrotate.conf --force`.