Skip to content

Commit 4b2ab79

Browse files
committed
Refactoring and improvements to logger configuration and creation
- Updated LoggerConfiguration class for better handling of nested keys and configuration values. - Implemented the set function to define nested values in the configuration. - Implemented the get function to retrieve nested values from the configuration, with support for default values. - Added the load function to load the configuration from a file and validate its format. - Improved helper functions for handling nested keys and values. - Updated LoggerFactory class to correctly utilize logger configurations. - Modified the createLogger function to support different types of handlers and formatters. - Updated createQueryLogger, createPerformanceLogger, and createErrorLogger functions to use complete configurations. - Updated LoggerServiceProvider class to register additional loggers based on configurations. - Added support to register query, performance, and error loggers based on provided configurations. - Checked for the presence of configurations and initialized additional loggers as needed. - Updated EnvLoader and EnvParser classes for better support of environment variable loading and parsing. - Added load function in EnvLoader to load environment variables from a .env file. - Added parse function in EnvParser to interpret environment values as booleans, integers, floats, or strings. - Added checks and exception handling to ensure robustness of the code.
1 parent 55e8cc9 commit 4b2ab79

File tree

12 files changed

+3051
-175
lines changed

12 files changed

+3051
-175
lines changed

.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ KARIRICODE_PHP_VERSION=8.3
33
KARIRICODE_PHP_PORT=9303
44

55
# Canal de log padrão
6-
LOG_CHANNEL=stack
6+
LOG_CHANNEL=single
77

88
# Nível de log padrão
99
LOG_LEVEL=debug
@@ -25,7 +25,7 @@ ELASTIC_LOG_INDEX=logging-logs
2525
ASYNC_LOG_ENABLED=true
2626

2727
# Habilitar logs de consulta
28-
QUERY_LOG_ENABLED=false
28+
QUERY_LOG_ENABLED=true
2929
QUERY_LOG_CHANNEL=daily
3030
QUERY_LOG_THRESHOLD=100
3131

config/logging.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use KaririCode\Logging\Formatter\JsonFormatter;
34
use KaririCode\Logging\LogLevel;
45
use KaririCode\Logging\Util\ConfigHelper;
56

@@ -9,13 +10,13 @@
910
'channels' => [
1011
'stack' => [
1112
'driver' => 'stack',
12-
'channels' => ['daily', 'slack'],
13+
'channels' => ['daily', 'slack', 'syslog'],
1314
'ignore_exceptions' => false,
1415
],
1516

1617
'single' => [
1718
'driver' => 'single',
18-
'path' => ConfigHelper::storagePath('logs/logging.log'),
19+
'path' => ConfigHelper::storagePath('logs/single.log'),
1920
'level' => ConfigHelper::env('LOG_LEVEL', 'debug'),
2021
'bubble' => true,
2122
'permission' => 0664,
@@ -24,7 +25,7 @@
2425

2526
'daily' => [
2627
'driver' => 'daily',
27-
'path' => ConfigHelper::storagePath('logs/logging.log'),
28+
'path' => ConfigHelper::storagePath('logs/daily.log'),
2829
'level' => ConfigHelper::env('LOG_LEVEL', 'debug'),
2930
'days' => 14,
3031
'bubble' => true,
@@ -53,7 +54,7 @@
5354
],
5455
],
5556

56-
'stderr' => [
57+
'console' => [
5758
'driver' => 'monolog',
5859
'level' => ConfigHelper::env('LOG_LEVEL', 'debug'),
5960
'handler' => \KaririCode\Logging\Handler\ConsoleHandler::class,
@@ -135,6 +136,9 @@
135136
'enabled' => ConfigHelper::env('QUERY_LOG_ENABLED', false),
136137
'channel' => ConfigHelper::env('QUERY_LOG_CHANNEL', 'daily'),
137138
'threshold' => ConfigHelper::env('QUERY_LOG_THRESHOLD', 100), // in milliseconds
139+
'path' => ConfigHelper::storagePath('logs/query.log'),
140+
'level' => LogLevel::DEBUG,
141+
'formatter' => ['class' => JsonFormatter::class],
138142
],
139143

140144
'performance_logger' => [
@@ -146,7 +150,12 @@
146150
'error_logger' => [
147151
'enabled' => ConfigHelper::env('ERROR_LOG_ENABLED', true),
148152
'channel' => ConfigHelper::env('ERROR_LOG_CHANNEL', 'daily'),
149-
'levels' => [LogLevel::ERROR, LogLevel::CRITICAL, LogLevel::ALERT, LogLevel::EMERGENCY],
153+
'levels' => [
154+
LogLevel::ERROR,
155+
LogLevel::CRITICAL,
156+
LogLevel::ALERT,
157+
LogLevel::EMERGENCY
158+
],
150159
],
151160

152161
'log_cleaner' => [

0 commit comments

Comments
 (0)