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