Skip to content

Commit 5b35957

Browse files
committed
- uses the latest Koded\Stdlib
- adds VERSION file - updates the tests - README clean up - LICENSE update
1 parent 6abd537 commit 5b35957

13 files changed

Lines changed: 62 additions & 68 deletions

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
BSD 3-Clause License
22

33
Koded - Logging
4-
Copyright (c) 2017, Mihail Binev
4+
Copyright (c) 2018, Mihail Binev
55
All rights reserved.
66

77
Redistribution and use in source and binary forms, with or without

README.md

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ $log = new Log($settings);
4444
$log->alert('The message with {variable}', ['variable' => 'useful info']);
4545

4646
// This message won't be processed by ErrorLog because the level is below ERROR
47-
// but File will handle it
47+
// but *File* will handle it
4848
$log->warning("You don't see anything");
4949

5050
```
@@ -53,44 +53,46 @@ Configuration
5353
-------------
5454

5555
There are two ways of throwing the log messages
56-
- register the logger at PHP's shutdown phase with
57-
```php
58-
<?php
59-
60-
$logger->register();
61-
62-
// or
63-
register_shutdown_function([$logger, 'process']);
64-
65-
// or
66-
register_shutdown_function([new Log($settings), 'process']);
67-
```
68-
somewhere in your bootstrap, at the very beginning of your project.
69-
**You do this only once**.
70-
71-
- calling directly `$logger->process()` if you want immediate log messages.
72-
**This approach will dump all accumulated messages and clear the messages stack**,
73-
so at the shutdown phase (if any) the logger will be empty
56+
- automatically at the shutdown phase by using the `Log::process()` method somewhere in your bootstrap
57+
(at the very beginning of your project).
58+
**You should do this only once**.
59+
60+
```php
61+
<?php
62+
63+
$logger->register();
64+
65+
// or
66+
register_shutdown_function([$logger, 'process']);
67+
68+
// or
69+
register_shutdown_function([new Log($settings), 'process']);
70+
```
71+
72+
- calling directly `$logger->process()` if you want immediate log messages.
73+
**This call will dump all accumulated messages and clear the stack**
74+
(after that the logger will be empty)
7475

7576

7677
### Log and Processor default directives
7778

7879
Every log processor has it's own set of configuration directives.
79-
The table shows parameters that are always present in the classes.
80+
The table shows log parameters in the classes.
8081

81-
| Param | Type | Required | Default | Description |
82-
|:-----------|:--------|:--------:|:------------|:---------------------------------------------------------------------|
83-
| class | string | yes | | The name of the log processor class |
84-
| levels | integer | no | -1 | Packed integer for bitwise comparison. See the constants in Logger |
85-
| dateformat | string | no | d/m/Y H:i:s | The datetime format for the log message |
86-
| timezone | string | no | UTC | The desired timezone for the datetime log message |
82+
| Param | Type | Required | Default | Description
83+
|:-----------|:--------|:--------:|:------------|:-----------
84+
| class | string | yes | | The name of the log processor class
85+
| levels | integer | no | -1 | Packed integer for bitwise comparison. See the constants in Logger class
86+
| dateformat | string | no | d/m/Y H:i:s | The datetime format for the log message
87+
| timezone | string | no | UTC | The desired timezone for the datetime log message
8788

8889

8990
### Levels example
91+
9092
The messages are filtered with bitwise operator (as packed integer). Every processor will filter out the messages as
9193
defined in it's **levels** directive.
9294

93-
To log only WARNING, INFO and ERROR messages set levels to
95+
For instance, to log only WARNING, INFO and ERROR messages set levels to
9496

9597
```php
9698
<?php
@@ -101,29 +103,20 @@ To log only WARNING, INFO and ERROR messages set levels to
101103
Tips:
102104
- every processor is configured separately
103105
- if you want to process all log levels, skip the `levels` value
104-
- if you want to suppress the processor, set the level to 0
106+
- if you want to suppress a specific processor, set it's level to 0
105107

106108

107109
Processors
108110
----------
109111

110-
- **ErrorLog**
111-
uses the [error_log()][error-log] function to send the message to PHP's logger
112-
113-
- **File**
114-
saves the messages on a disk. It's a slow one
115-
116-
- **Syslog**
117-
will open the system logger and send messages using the [syslog()][syslog] function
118-
119-
- **Cli**
120-
for CLI applications, it can write the messages in the console
121-
122-
- **Memory**
123-
will store all messages in an array. Useful for unit tests if the logger is involved
124-
125-
- **Voided**
126-
is here for no particular reason and purpose. It's the fastest one tho
112+
| Class name | Description
113+
|-----------:|:-----------
114+
| ErrorLog | uses the [error_log()][error-log] function to send the message to PHP's logger
115+
| SysLog | will open the system logger and send messages using the [syslog()][syslog] function
116+
| Cli | for CLI applications, it can write the messages in the console
117+
| Memory | will store all messages in an array. Useful for unit tests if the logger is involved
118+
| File | saves the messages on a disk. It's a slow one and should be avoided
119+
| Voided | is here for no particular reason and purpose. It's the fastest one tho :)
127120

128121

129122
License
@@ -134,4 +127,4 @@ The code is distributed under the terms of [The 3-Clause BSD license](LICENSE).
134127
[psr-3]: http://www.php-fig.org/psr/psr-3/
135128
[composer]: https://getcomposer.org/download/
136129
[error-log]: http://php.net/error_log
137-
[syslog]: http://php.net/syslog
130+
[syslog]: http://php.net/syslog

Tests/LogConstructorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class LogConstructorTest extends TestCase
99
{
1010

11-
public function testConstructionWithConfigArray()
11+
public function test_construction_with_config_array()
1212
{
1313
$log = new Log([
1414
'timezone' => 'Europe/Berlin',
@@ -22,7 +22,7 @@ public function testConstructionWithConfigArray()
2222
$this->assertAttributeSame('Europe/Berlin', 'timezone', $log);
2323
}
2424

25-
public function testConstructionWithoutConfig()
25+
public function test_construction_without_config()
2626
{
2727
$log = new Log([]);
2828
$this->assertAttributeSame('d/m/Y H:i:s', 'dateFormat', $log);

Tests/LogTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class LogTest extends TestCase
1414
*/
1515
private $SUT;
1616

17-
public function testAttachAndDetach()
17+
public function test_attach_and_detach()
1818
{
1919
$processor = new Memory([]);
2020
$this->assertAttributeCount(0, 'processors', $this->SUT);
@@ -26,14 +26,14 @@ public function testAttachAndDetach()
2626
$this->assertAttributeCount(0, 'processors', $this->SUT);
2727
}
2828

29-
public function testMessagesStack()
29+
public function test_messages_stack()
3030
{
3131
$this->assertAttributeCount(0, 'messages', $this->SUT);
3232
$this->SUT->alert('Hello');
3333
$this->assertAttributeCount(1, 'messages', $this->SUT);
3434
}
3535

36-
public function testMessageBlock()
36+
public function test_message_block()
3737
{
3838
$this->SUT->alert('Hello {you}', ['you' => 'the most awesome person in the universe']);
3939
$message = $this->getMessages()[0];
@@ -44,7 +44,7 @@ public function testMessageBlock()
4444
$this->assertInternalType('string', $message['timestamp']);
4545
}
4646

47-
public function testUnsupportedLevelShouldPassToDefaultLevel()
47+
public function test_unsupported_level_should_pass_to_default_level()
4848
{
4949
$this->SUT->log('', '');
5050
$message = $this->getMessages()[0];
@@ -53,14 +53,14 @@ public function testUnsupportedLevelShouldPassToDefaultLevel()
5353
$this->assertSame('LOG', $message['levelname']);
5454
}
5555

56-
public function testExceptionAttribute()
56+
public function test_exception_attribute()
5757
{
5858
$processor = new Memory([]);
5959
$this->SUT->exception(new Exception('The message', 1), $processor);
6060
$this->assertAttributeContains('ALERT: The message', 'formatted', $processor);
6161
}
6262

63-
public function testLogSuppression()
63+
public function test_log_suppression()
6464
{
6565
$processor = new Memory([
6666
'levels' => 0 // suppress the logger completely
@@ -78,7 +78,7 @@ public function testLogSuppression()
7878
$this->assertSame('', $processor->formatted());
7979
}
8080

81-
public function testRegister()
81+
public function test_register()
8282
{
8383
$mock = $this
8484
->getMockBuilder(Log::class)

Tests/Processors/CliTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class CliTest extends TestCase
99
{
1010

11-
public function testFormatting()
11+
public function test_formatting()
1212
{
1313
$processor = new Cli([]);
1414

Tests/Processors/DefaultProcessorPropertiesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
class DefaultProcessorPropertiesTest extends TestCase
99
{
1010

11-
public function testDefaults()
11+
public function test_defaults()
1212
{
1313
$processor = new Voided([]);
1414
$this->assertAttributeSame(-1, 'levels', $processor);
1515
$this->assertAttributeSame('[timestamp] levelname: message', 'format', $processor);
1616
$this->assertAttributeSame('', 'formatted', $processor);
1717
}
1818

19-
public function testConstructorSettings()
19+
public function test_constructor_settings()
2020
{
2121
$processor = new Memory([
2222
'levels' => Logger::ALERT | Logger::NOTICE | Logger::WARNING,

Tests/Processors/ErrorLogTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class ErrorLogTest extends TestCase
99
{
1010

11-
public function testFormatting()
11+
public function test_formatting()
1212
{
1313
$processor = new ErrorLog([]);
1414

Tests/Processors/FileTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class FileTest extends TestCase
1919
* @dataProvider dataMessage
2020
* @param $message
2121
*/
22-
public function testFormatting($message)
22+
public function test_formatting($message)
2323
{
2424
$subdirectory = date('Y/m');
2525
$file = date('d') . '.log';
@@ -37,7 +37,7 @@ public function testFormatting($message)
3737
* @dataProvider dataMessage
3838
* @param $message
3939
*/
40-
public function testWhenDirectoryDoesNotExist($message)
40+
public function test_when_directory_does_not_exist($message)
4141
{
4242
$dir = $this->dir->url() . '/nonexistent';
4343

@@ -52,7 +52,7 @@ public function testWhenDirectoryDoesNotExist($message)
5252
* @dataProvider dataMessage
5353
* @param $message
5454
*/
55-
public function testWhenDirectoryIsNotWritable($message)
55+
public function test_when_directory_is_not_writable($message)
5656
{
5757
$dir = $this->dir->url();
5858

Tests/Processors/MemoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class MemoryTest extends TestCase
88
{
99

10-
public function testFormatting()
10+
public function test_formatting()
1111
{
1212
$processor = new Memory([]);
1313

Tests/Processors/SyslogTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class SyslogTest extends TestCase
99
{
1010

11-
public function testFormatting()
11+
public function test_formatting()
1212
{
1313
$processor = new Syslog([]);
1414

0 commit comments

Comments
 (0)