Logger.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. namespace Config;
  3. use CodeIgniter\Config\BaseConfig;
  4. use CodeIgniter\Log\Handlers\FileHandler;
  5. class Logger extends BaseConfig
  6. {
  7. /**
  8. * --------------------------------------------------------------------------
  9. * Error Logging Threshold
  10. * --------------------------------------------------------------------------
  11. *
  12. * You can enable error logging by setting a threshold over zero. The
  13. * threshold determines what gets logged. Any values below or equal to the
  14. * threshold will be logged.
  15. *
  16. * Threshold options are:
  17. *
  18. * - 0 = Disables logging, Error logging TURNED OFF
  19. * - 1 = Emergency Messages - System is unusable
  20. * - 2 = Alert Messages - Action Must Be Taken Immediately
  21. * - 3 = Critical Messages - Application component unavailable, unexpected exception.
  22. * - 4 = Runtime Errors - Don't need immediate action, but should be monitored.
  23. * - 5 = Warnings - Exceptional occurrences that are not errors.
  24. * - 6 = Notices - Normal but significant events.
  25. * - 7 = Info - Interesting events, like user logging in, etc.
  26. * - 8 = Debug - Detailed debug information.
  27. * - 9 = All Messages
  28. *
  29. * You can also pass an array with threshold levels to show individual error types
  30. *
  31. * array(1, 2, 3, 8) = Emergency, Alert, Critical, and Debug messages
  32. *
  33. * For a live site you'll usually enable Critical or higher (3) to be logged otherwise
  34. * your log files will fill up very fast.
  35. *
  36. * @var array|int
  37. */
  38. public $threshold = (ENVIRONMENT === 'production') ? 4 : 9;
  39. /**
  40. * --------------------------------------------------------------------------
  41. * Date Format for Logs
  42. * --------------------------------------------------------------------------
  43. *
  44. * Each item that is logged has an associated date. You can use PHP date
  45. * codes to set your own date formatting
  46. */
  47. public string $dateFormat = 'Y-m-d H:i:s';
  48. /**
  49. * --------------------------------------------------------------------------
  50. * Log Handlers
  51. * --------------------------------------------------------------------------
  52. *
  53. * The logging system supports multiple actions to be taken when something
  54. * is logged. This is done by allowing for multiple Handlers, special classes
  55. * designed to write the log to their chosen destinations, whether that is
  56. * a file on the getServer, a cloud-based service, or even taking actions such
  57. * as emailing the dev team.
  58. *
  59. * Each handler is defined by the class name used for that handler, and it
  60. * MUST implement the `CodeIgniter\Log\Handlers\HandlerInterface` interface.
  61. *
  62. * The value of each key is an array of configuration items that are sent
  63. * to the constructor of each handler. The only required configuration item
  64. * is the 'handles' element, which must be an array of integer log levels.
  65. * This is most easily handled by using the constants defined in the
  66. * `Psr\Log\LogLevel` class.
  67. *
  68. * Handlers are executed in the order defined in this array, starting with
  69. * the handler on top and continuing down.
  70. */
  71. public array $handlers = [
  72. /*
  73. * --------------------------------------------------------------------
  74. * File Handler
  75. * --------------------------------------------------------------------
  76. */
  77. FileHandler::class => [
  78. // The log levels that this handler will handle.
  79. 'handles' => [
  80. 'critical',
  81. 'alert',
  82. 'emergency',
  83. 'debug',
  84. 'error',
  85. 'info',
  86. 'notice',
  87. 'warning',
  88. ],
  89. /*
  90. * The default filename extension for log files.
  91. * An extension of 'php' allows for protecting the log files via basic
  92. * scripting, when they are to be stored under a publicly accessible directory.
  93. *
  94. * NOTE: Leaving it blank will default to 'log'.
  95. */
  96. 'fileExtension' => '',
  97. /*
  98. * The file system permissions to be applied on newly created log files.
  99. *
  100. * IMPORTANT: This MUST be an integer (no quotes) and you MUST use octal
  101. * integer notation (i.e. 0700, 0644, etc.)
  102. */
  103. 'filePermissions' => 0644,
  104. /*
  105. * Logging Directory Path
  106. *
  107. * By default, logs are written to WRITEPATH . 'logs/'
  108. * Specify a different destination here, if desired.
  109. */
  110. 'path' => '',
  111. ],
  112. /*
  113. * The ChromeLoggerHandler requires the use of the Chrome web browser
  114. * and the ChromeLogger extension. Uncomment this block to use it.
  115. */
  116. // 'CodeIgniter\Log\Handlers\ChromeLoggerHandler' => [
  117. // /*
  118. // * The log levels that this handler will handle.
  119. // */
  120. // 'handles' => ['critical', 'alert', 'emergency', 'debug',
  121. // 'error', 'info', 'notice', 'warning'],
  122. // ],
  123. /*
  124. * The ErrorlogHandler writes the logs to PHP's native `error_log()` function.
  125. * Uncomment this block to use it.
  126. */
  127. // 'CodeIgniter\Log\Handlers\ErrorlogHandler' => [
  128. // /* The log levels this handler can handle. */
  129. // 'handles' => ['critical', 'alert', 'emergency', 'debug', 'error', 'info', 'notice', 'warning'],
  130. //
  131. // /*
  132. // * The message type where the error should go. Can be 0 or 4, or use the
  133. // * class constants: `ErrorlogHandler::TYPE_OS` (0) or `ErrorlogHandler::TYPE_SAPI` (4)
  134. // */
  135. // 'messageType' => 0,
  136. // ],
  137. ];
  138. }