Skip to content

Commit c394f76

Browse files
committed
Fix update readme and docs
1 parent dbfe1d8 commit c394f76

File tree

3 files changed

+29
-89
lines changed

3 files changed

+29
-89
lines changed

README.md

Lines changed: 18 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Simple data logging
22

33
<p>
4-
<img alt="Package version" src="https://packages-api.hopex.ru/api/simplog/version/package">
54
<img alt="Package version" src="https://packages-api.hopex.ru/api/simplog/packagist/hopex/downloads">
65
<img alt="Package version" src="https://packages-api.hopex.ru/api/simplog/packagist/hopex/stars">
76
<img alt="PHP version" src="https://packages-api.hopex.ru/api/simplog/version/php">
@@ -16,78 +15,21 @@ The library contains a simple class, and it's facade, for simple data and except
1615
composer require hopex/simplog
1716
```
1817

19-
## Usage
20-
21-
Simple data logging. Your data will be saved to a file `./logs/runtime/NameOfLogFile.log`:
22-
```php
23-
(new Logger())->putData($data, 'NameOfLogFile');
24-
```
25-
26-
### Directory
27-
28-
Default logging directory is `./logs/`. You can change the location directory of the log
29-
files and the "logging level", after which your logging file will be
30-
saved along the path `./example/logs/MyLevel/NameOfLogFile.log`:
31-
```php
32-
(new Logger())
33-
->setWorkDirectory('example/logs')
34-
->setLevel('MyLevel')
35-
->putData($data, 'NameOfLogFile');
36-
```
37-
38-
### Date and time format
39-
40-
Timezone default UTC and date format is `Y-m-d H:i:s`. You can also change the time format and time zone that are used inside the logging files:
41-
```php
42-
(new Logger())
43-
->setTimeZone('Europe/Moscow')
44-
->setDateFormat('(Y) H:i:s')
45-
->putData([
46-
'example' => [
47-
'parameter' => 1
48-
]
49-
], 'NameOfLogFile');
50-
```
51-
Output log file:
52-
```json
53-
{
54-
"(2022) 19:13:28": {
55-
"example": {
56-
"parameter": 1
57-
}
58-
}
59-
}
60-
```
61-
62-
### Data of exceptions
63-
64-
You can log exception data by easily passing it to the `putException` function:
65-
66-
```php
67-
(new Logger())
68-
->setDateFormat('H:i:s')
69-
->setLevel('Exceptions')
70-
->putException($e, date('Y-m-d'), true);
71-
```
72-
Output log file `./logs/exceptions/2022.24.12.log`:
73-
```json
74-
{
75-
"17:45:31": {
76-
"message": "Some message",
77-
"file": "G:\\OSPanel\\domains\\localhost\\example.php",
78-
"line": 10,
79-
"trace": "#0 {main}"
80-
}
81-
}
82-
```
83-
84-
### Common
85-
86-
The class has a built-in function `clearLevel` of cleaning the logging working directory
87-
from unnecessary files:
88-
89-
```php
90-
(new Logger())
91-
->clearLevel()
92-
->putData($data, 'NameOfLogFile');
93-
```
18+
## Documentation
19+
20+
| Methods | Description | Example for usage |
21+
|:-------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
22+
| `setWorkDirectory` | Specifies the root directory of the hierarchy of logging levels. It can take several directories in turn one after the other in the form of a standard path. | `setWorkDirectory('logging')` <br> `setWorkDirectory('logging/sub-folder')` |
23+
| `setLevel` | Specifies the name of the directory where you want to save the logging file. It can't take several directories in turn one after the other in the form of a standard path. | `setLevel('requests')` |
24+
| `setTimeZone` | Specifies the current timezone. | `setTimeZone('UTC')` <br> `setTimeZone('Europe/Amsterdam')` |
25+
| `setDateFormat` | Sets the time format in the main key of one log element in the logging file. Will not be used if V is specified. | `setDateFormat('H:i:s')` <br> `setDateFormat('(Y) H:i:s')` |
26+
| `setItemKey` | Sets the primary key of one log element in the logging file. In this case, the current time will not be indicated. | `setItemKey('custom-key')` |
27+
| `setItemsLimit` | Sets the maximum number of elements in a single logging file. The value must be greater than zero. By default, 1000 keys. | `setItemsLimit(10)` <br> `setItemsLimit(5000)` |
28+
| `setPermissions` | Sets access rights to the logging file. | `setLogFilePermissions(0755)` <br> `setLogFilePermissions(644)` |
29+
| `setFileName` | Sets the name of the logging file. | `setFileName('my-requests-logs')` |
30+
| `error` | Logging any object as an error message. | Similarly as for `custom`. |
31+
| `warning` | Logging any object as a warning. | Similarly as for `custom`. |
32+
| `info` | Logging of any object as an informational message. | Similarly as for `custom`. |
33+
| `custom` | Logging of any object. | `custom(new SomeClass())` <br> `custom('Some message')` <br> `custom(['key' => 'value'])` |
34+
| `exception` | Logging of the exception object with the possibility of adding additional keys. | `exception(new \Exceptions())` <br> `exception(new \Exceptions(), true)` <br> `exception(new \Exceptions(), false, ['key' => 'value'])` |
35+
| `clearLevel` | The requirement to clear the directory where the logging file should be saved from other files. | `clearLevel()` |

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Simple data logging with customize directories.",
44
"type": "library",
55
"keywords": ["php", "log", "logger", "logging"],
6-
"version": "2.0",
6+
"version": "2.1",
77
"require": {
88
"php": "^7.4",
99
"ext-json": "*"

src/Logger.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ public function setItemKey(?string $itemKey): Logger
169169
* saved from other files.
170170
*
171171
* @return Logger
172+
*
173+
* @example clearLevel()
172174
*/
173175
public function clearLevel(): Logger
174176
{
@@ -321,10 +323,9 @@ private function loggingType($data, string $type): void
321323
*
322324
* @return void
323325
*
324-
* @example put((new SomeClass(), sprintf("classes-%s", date('H:i:s')))
325-
* @example put('Some message', 'messages.log')
326-
* @example put('Some message', 'messages')
327-
* @example put(['key' => 'value'], 'arrays')
326+
* @example custom(new SomeClass()
327+
* @example custom('Some message')
328+
* @example custom(['key' => 'value'])
328329
*/
329330
public function custom($data)
330331
{
@@ -378,15 +379,12 @@ public function custom($data)
378379
*
379380
* @return void
380381
*
381-
* @example exception(new \Exceptions(), sprintf("exceptions-%s", date('H:i:s')))
382-
* @example exception(new \Exceptions(), "exceptions", true)
383-
* @example exception(new \Exceptions(), "exceptions", false, ['advanced-key' => 'advanced-value'])
382+
* @example exception(new \Exceptions())
383+
* @example exception(new \Exceptions(), true)
384+
* @example exception(new \Exceptions(), false, ['key' => 'value'])
384385
*/
385-
public function exception(
386-
Throwable $throwable,
387-
bool $withTrace = false,
388-
array $payload = []
389-
) {
386+
public function exception(Throwable $throwable, bool $withTrace = false, array $payload = [])
387+
{
390388
$this->custom(array_merge($payload, [
391389
'message' => $throwable->getMessage(),
392390
'file' => $throwable->getFile(),

0 commit comments

Comments
 (0)