Logger.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 int|list<int>
  37. */
  38. //public $threshold = (ENVIRONMENT === 'production') ? 4 : 9;
  39. public $threshold = 4;
  40. /**
  41. * --------------------------------------------------------------------------
  42. * Date Format for Logs
  43. * --------------------------------------------------------------------------
  44. *
  45. * Each item that is logged has an associated date. You can use PHP date
  46. * codes to set your own date formatting
  47. */
  48. public string $dateFormat = 'Y-m-d H:i:s';
  49. /**
  50. * --------------------------------------------------------------------------
  51. * Log Handlers
  52. * --------------------------------------------------------------------------
  53. *
  54. * The logging system supports multiple actions to be taken when something
  55. * is logged. This is done by allowing for multiple Handlers, special classes
  56. * designed to write the log to their chosen destinations, whether that is
  57. * a file on the getServer, a cloud-based service, or even taking actions such
  58. * as emailing the dev team.
  59. *
  60. * Each handler is defined by the class name used for that handler, and it
  61. * MUST implement the `CodeIgniter\Log\Handlers\HandlerInterface` interface.
  62. *
  63. * The value of each key is an array of configuration items that are sent
  64. * to the constructor of each handler. The only required configuration item
  65. * is the 'handles' element, which must be an array of integer log levels.
  66. * This is most easily handled by using the constants defined in the
  67. * `Psr\Log\LogLevel` class.
  68. *
  69. * Handlers are executed in the order defined in this array, starting with
  70. * the handler on top and continuing down.
  71. *
  72. * @var array<class-string, array<string, int|list<string>|string>>
  73. */
  74. public array $handlers = [
  75. /*
  76. * --------------------------------------------------------------------
  77. * File Handler
  78. * --------------------------------------------------------------------
  79. */
  80. FileHandler::class => [
  81. // The log levels that this handler will handle.
  82. 'handles' => [
  83. 'critical',
  84. 'alert',
  85. 'emergency',
  86. 'debug',
  87. 'error',
  88. 'info',
  89. 'notice',
  90. 'warning',
  91. ],
  92. /*
  93. * The default filename extension for log files.
  94. * An extension of 'php' allows for protecting the log files via basic
  95. * scripting, when they are to be stored under a publicly accessible directory.
  96. *
  97. * NOTE: Leaving it blank will default to 'log'.
  98. */
  99. 'fileExtension' => '',
  100. /*
  101. * The file system permissions to be applied on newly created log files.
  102. *
  103. * IMPORTANT: This MUST be an integer (no quotes) and you MUST use octal
  104. * integer notation (i.e. 0700, 0644, etc.)
  105. */
  106. 'filePermissions' => 0644,
  107. /*
  108. * Logging Directory Path
  109. *
  110. * By default, logs are written to WRITEPATH . 'logs/'
  111. * Specify a different destination here, if desired.
  112. */
  113. 'path' => '',
  114. ],
  115. /*
  116. * The ChromeLoggerHandler requires the use of the Chrome web browser
  117. * and the ChromeLogger extension. Uncomment this block to use it.
  118. */
  119. // 'CodeIgniter\Log\Handlers\ChromeLoggerHandler' => [
  120. // /*
  121. // * The log levels that this handler will handle.
  122. // */
  123. // 'handles' => ['critical', 'alert', 'emergency', 'debug',
  124. // 'error', 'info', 'notice', 'warning'],
  125. // ],
  126. /*
  127. * The ErrorlogHandler writes the logs to PHP's native `error_log()` function.
  128. * Uncomment this block to use it.
  129. */
  130. // 'CodeIgniter\Log\Handlers\ErrorlogHandler' => [
  131. // /* The log levels this handler can handle. */
  132. // 'handles' => ['critical', 'alert', 'emergency', 'debug', 'error', 'info', 'notice', 'warning'],
  133. //
  134. // /*
  135. // * The message type where the error should go. Can be 0 or 4, or use the
  136. // * class constants: `ErrorlogHandler::TYPE_OS` (0) or `ErrorlogHandler::TYPE_SAPI` (4)
  137. // */
  138. // 'messageType' => 0,
  139. // ],
  140. ];
  141. }