Skip to content

Commit 2ff4d77

Browse files
author
Wazabii
committed
Guide
1 parent f6bc8ee commit 2ff4d77

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

Handlers/DBHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public function handler(string $level, string $message, array $context, string $
4040

4141
/**
4242
* Execute method bellow once an it will automatically create your table!
43-
* @return void
43+
* @return mixed
4444
*/
45-
public function create(): void
45+
public function create(): mixed
4646
{
4747

4848
$mig = new Create(static::TABLE, Connect::prefix());
@@ -81,6 +81,6 @@ public function create(): void
8181
"index" => "index"
8282
]);
8383

84-
$mig->execute();
84+
return $mig->execute();
8585
}
8686
}

README.md

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,61 @@
1+
12
# MaplePHP - PSR-3 Logger
23
PHP PSR-3 Logger library – your reliable companion for efficient logging in PHP applications. This library adheres to the PSR-3 standard, providing a seamless and standardized approach to logging messages across different components of your application.
34

4-
### Stream/file handler
5+
## Stream/file handler
56

6-
Create simple stream logger
7+
#### Add namespaces
8+
```php
9+
use MaplePHP\Log\Logger;
10+
use MaplePHP\Log\Handlers\StreamHandler;
11+
```
12+
#### Create simple stream logger
713
```php
814
$log = new Logger(new StreamHandler("/path/to/logger.log"));
915
$log->warning("The user {firstname} has been added.", ["firstname" => "John", "lastname" => "Doe"]);
1016
```
11-
17+
#### Rotatable log files
1218
Create simple stream rotatables loggers. Will create a new log file if size is more than MAX_SIZE (5000 KB) and remove log files if total file count is more than MAX_COUNT 10.
1319
```php
1420
$log = new Logger(new StreamHandler("/path/to/logger.log", StreamHandler::MAX_SIZE, StreamHandler::MAX_COUNT));
1521
$log->warning("The user {firstname} has been added.", ["firstname" => "John", "lastname" => "Doe"]);
1622
```
1723

18-
### Database handler
24+
## Database handler
25+
#### Add namespaces
26+
```php
27+
use MaplePHP\Log\Logger;
28+
use MaplePHP\Log\Handlers\DBHandler;
29+
```
30+
31+
#### 1. Connect to the database.
32+
[MaplePHP Query](https://github.com/MaplePHP/Query)
33+
34+
#### 2. Create database table
35+
Execute bellow once to create the database table.
36+
```php
37+
$dbHandler = new DBHandler();
38+
$error = $dbHandler->create();
39+
if (count($error) > 0) {
40+
echo "<pre>";
41+
print_r($error);
42+
echo "</pre>";
43+
}
44+
```
45+
#### 3. Write to database log
1946
```php
2047
$log = new Logger(new DBHandler());
2148
$log->warning("The user {firstname} has been added.", ["user_id" => 4, "firstname" => "Daniel"]);
2249
```
2350

24-
### PHP error log handler (error_log())
51+
## PHP error log handler (error_log())
2552
You can (not required) specify a log file location in ErrorLogHandler. If argument is empty, then server default location.
53+
54+
#### Add namespaces
55+
```php
56+
use MaplePHP\Log\Logger;
57+
use MaplePHP\Log\Handlers\ErrorLogHandler;
58+
```
2659
```php
2760
$log = new Logger(new ErrorLogHandler("/path/to/logger.log"));
2861
$log->warning("The user {firstname} has been added.", ["firstname" => "John", "lastname" => "Doe", "data" => ["city" => "Stockholm", "coor" => "122,1212"]]);

0 commit comments

Comments
 (0)