codelight / logger
A PHP log wrapper for sending logs to logging system.
Installs: 991
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 1
Type:package
This package is auto-updated.
Last update: 2024-10-22 17:21:56 UTC
README
A PHP log wrapper for sending logs to logging system.
Installing
Run below command to install the package.
composer require codelight/logger dev-master
Simple Usage
<?php include "../vendor/autoload.php"; use Codelight\Logger; use Codelight\Service\GrayLog; try { $logger = new Logger(new GrayLog('logs.codelight.eu')); $logger->setVersion(1) ->setHost('localhost') ->setLevel(1) ->setUserId(12) ->setPayload('some_info', 'foo') ->setPayload('some_env_var', 'bar') ->setPayload('some_array_data', ['foo' => 'bar']); $result = $logger->log('Hello', 'Hello world! this is a log'); var_dump($result); } catch (Exception $e) { echo $e->getMessage(); }
Working with Log Level
try { /** @var GrayLog $logger */ $logger = new Logger(new GrayLog('logs.codelight.eu')); $logger->setVersion(1) ->setHost('localhost') ->setUserId(12) ->setPayload('some_info', 'foo') ->setPayload('some_env_var', 'bar') ->setPayload('some_array_data', ['foo' => 'bar']); $logger->emergency('System is unusable.', 'System is unusable.'); $logger->alert('Entire website down', 'Entire website down, database unavailable'); $logger->critical('Zip extension is not installed', 'Application component unavailable, unexpected exception.'); $logger->error('Error to get user info', 'Runtime errors that do not require immediate action but should typically'); $logger->warning('API deprecated', 'Use of deprecated APIs, poor use of an API, undesirable things'); $logger->notice('WordPress updated', 'Normal but significant events.'); $logger->info('Payment success SQL', 'User logs in, SQL logs.'); $logger->debug('Payment success object', 'Detailed debug information.'); } catch (Exception $e) { echo $e->getMessage(); }