Skip to content

Commit 42179a1

Browse files
committed
refactor Logger config
1 parent 91acbea commit 42179a1

2 files changed

Lines changed: 66 additions & 63 deletions

File tree

app/Config/Logger.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use CodeIgniter\Config\BaseConfig;
66
use CodeIgniter\Log\Handlers\FileHandler;
7+
use CodeIgniter\Log\Handlers\HandlerInterface;
78

89
class Logger extends BaseConfig
910
{
@@ -73,7 +74,7 @@ class Logger extends BaseConfig
7374
* Handlers are executed in the order defined in this array, starting with
7475
* the handler on top and continuing down.
7576
*
76-
* @var array<class-string, array<string, int|list<string>|string>>
77+
* @var array<class-string<HandlerInterface>, array<string, int|list<string>|string>>
7778
*/
7879
public array $handlers = [
7980
/*

system/Test/Mock/MockLogger.php

Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -13,77 +13,79 @@
1313

1414
namespace CodeIgniter\Test\Mock;
1515

16+
use CodeIgniter\Log\Handlers\HandlerInterface;
17+
use Config\Logger;
1618
use Tests\Support\Log\Handlers\TestHandler;
1719

18-
class MockLogger
20+
class MockLogger extends Logger
1921
{
20-
/*
21-
|--------------------------------------------------------------------------
22-
| Error Logging Threshold
23-
|--------------------------------------------------------------------------
24-
|
25-
| You can enable error logging by setting a threshold over zero. The
26-
| threshold determines what gets logged. Any values below or equal to the
27-
| threshold will be logged. Threshold options are:
28-
|
29-
| 0 = Disables logging, Error logging TURNED OFF
30-
| 1 = Emergency Messages - System is unusable
31-
| 2 = Alert Messages - Action Must Be Taken Immediately
32-
| 3 = Critical Messages - Application component unavailable, unexpected exception.
33-
| 4 = Runtime Errors - Don't need immediate action, but should be monitored.
34-
| 5 = Warnings - Exceptional occurrences that are not errors.
35-
| 6 = Notices - Normal but significant events.
36-
| 7 = Info - Interesting events, like user logging in, etc.
37-
| 8 = Debug - Detailed debug information.
38-
| 9 = All Messages
39-
|
40-
| You can also pass an array with threshold levels to show individual error types
41-
|
42-
| array(1, 2, 3, 8) = Emergency, Alert, Critical, and Debug messages
43-
|
44-
| For a live site you'll usually enable Critical or higher (3) to be logged otherwise
45-
| your log files will fill up very fast.
46-
|
22+
/**
23+
*--------------------------------------------------------------------------
24+
* Error Logging Threshold
25+
*--------------------------------------------------------------------------
26+
*
27+
* You can enable error logging by setting a threshold over zero. The
28+
* threshold determines what gets logged. Any values below or equal to the
29+
* threshold will be logged. Threshold options are:
30+
*
31+
* 0 = Disables logging, Error logging TURNED OFF
32+
* 1 = Emergency Messages - System is unusable
33+
* 2 = Alert Messages - Action Must Be Taken Immediately
34+
* 3 = Critical Messages - Application component unavailable, unexpected exception.
35+
* 4 = Runtime Errors - Don't need immediate action, but should be monitored.
36+
* 5 = Warnings - Exceptional occurrences that are not errors.
37+
* 6 = Notices - Normal but significant events.
38+
* 7 = Info - Interesting events, like user logging in, etc.
39+
* 8 = Debug - Detailed debug information.
40+
* 9 = All Messages
41+
*
42+
* You can also pass an array with threshold levels to show individual error types
43+
*
44+
* array(1, 2, 3, 8) = Emergency, Alert, Critical, and Debug messages
45+
*
46+
* For a live site you'll usually enable Critical or higher (3) to be logged otherwise
47+
* your log files will fill up very fast.
48+
*
49+
* @var int|list<int>
4750
*/
48-
4951
public $threshold = 9;
5052

51-
/*
52-
|--------------------------------------------------------------------------
53-
| Date Format for Logs
54-
|--------------------------------------------------------------------------
55-
|
56-
| Each item that is logged has an associated date. You can use PHP date
57-
| codes to set your own date formatting
58-
|
53+
/**
54+
*--------------------------------------------------------------------------
55+
* Date Format for Logs
56+
*--------------------------------------------------------------------------
57+
*
58+
* Each item that is logged has an associated date. You can use PHP date
59+
* codes to set your own date formatting
5960
*/
60-
public $dateFormat = 'Y-m-d';
61+
public string $dateFormat = 'Y-m-d';
6162

62-
/*
63-
|--------------------------------------------------------------------------
64-
| Log Handlers
65-
|--------------------------------------------------------------------------
66-
|
67-
| The logging system supports multiple actions to be taken when something
68-
| is logged. This is done by allowing for multiple Handlers, special classes
69-
| designed to write the log to their chosen destinations, whether that is
70-
| a file on the server, a cloud-based service, or even taking actions such
71-
| as emailing the dev team.
72-
|
73-
| Each handler is defined by the class name used for that handler, and it
74-
| MUST implement the CodeIgniter\Log\Handlers\HandlerInterface interface.
75-
|
76-
| The value of each key is an array of configuration items that are sent
77-
| to the constructor of each handler. The only required configuration item
78-
| is the 'handles' element, which must be an array of integer log levels.
79-
| This is most easily handled by using the constants defined in the
80-
| Psr\Log\LogLevel class.
81-
|
82-
| Handlers are executed in the order defined in this array, starting with
83-
| the handler on top and continuing down.
84-
|
63+
/**
64+
*--------------------------------------------------------------------------
65+
* Log Handlers
66+
*--------------------------------------------------------------------------
67+
*
68+
* The logging system supports multiple actions to be taken when something
69+
* is logged. This is done by allowing for multiple Handlers, special classes
70+
* designed to write the log to their chosen destinations, whether that is
71+
* a file on the server, a cloud-based service, or even taking actions such
72+
* as emailing the dev team.
73+
*
74+
* Each handler is defined by the class name used for that handler, and it
75+
* MUST implement the CodeIgniter\Log\Handlers\HandlerInterface interface.
76+
*
77+
* The value of each key is an array of configuration items that are sent
78+
* to the constructor of each handler. The only required configuration item
79+
* is the 'handles' element, which must be an array of integer log levels.
80+
* This is most easily handled by using the constants defined in the
81+
* Psr\Log\LogLevel class.
82+
*
83+
* Handlers are executed in the order defined in this array, starting with
84+
* the handler on top and continuing down.
85+
*
86+
* @var array<class-string<HandlerInterface>, array<string, int|list<string>|string>>
8587
*/
86-
public $handlers = [
88+
public array $handlers = [
8789
// File Handler
8890
TestHandler::class => [
8991
// The log levels that this handler will handle.

0 commit comments

Comments
 (0)