productsupcom / flexilog
Flexible PSR-3 Compatible Logger
Installs: 1 416
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 15
Forks: 0
Open Issues: 1
Requires
- php: >=5.6.0
- psr/log: ^1.0
Requires (Dev)
- escapestudios/symfony2-coding-standard: ~2.0
- phpunit/phpunit: ^5.4
- raulfraile/ladybug: ^1.0
- victorjonsson/markdowndocs: dev-master
Suggests
- graylog2/gelf-php: Required for GelfHandler, if you want to write to Graylog
- league/climate: Required for ShellHandler, if you want to write to the Shell using multi-color
- dev-master
- v0.1.2
- v0.1.1
- v0.1.0
- v0.0.9
- v0.0.8
- v0.0.7
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
- dev-processor
- dev-v2_future
- dev-untangle2
- dev-gelf_untangle
- dev-contextKeyFix
- dev-autoremove
- dev-saver_filehandler
- dev-slackhandler
- dev-extendable_redishandler2
- dev-extendable_redishandler
- dev-DEV-1380
- dev-patch-1
- dev-ACC-973
- dev-symfony_notice_fix
- dev-symfonyhandler
- dev-synfonyhandler
- dev-phpcs
- dev-loginfo
- dev-loginfo_sol
- dev-werner
- dev-namespace
This package is auto-updated.
Last update: 2025-02-23 22:41:07 UTC
README
<?php require_once('vendor/autoload.php'); use Productsup\Flexilog\Logger; use Productsup\Flexilog\Info; use Productsup\Flexilog\Handler; // this is optional // a Info class allows you to set certain properties that you always // want to include in your Log output (e.g. Gelf or Shell) // this is an expanditure to the `$context`. // You can define specific requiredData for the Info so you can enforce // certain properties to be available. $logInfo = new Info\GenericInfo(); $logInfo->setRequiredData(['foo']); $logInfo->setProperty('foo', 'bar'); // pick a cool handler $shellHandler = new Handler\ShellHandler('trace', 2); // set the Handler and the optional $logInfo $logger = new Logger([$shellHandler], $logInfo); $logger->notice('Hello World');
$context = array( 'fullMessage' => 'Blablablabla bla blaaaa blaaaa {foo} blaa', 'foo' => 'bar', //'exception' => new \Exception('wut', 0, new \Exception('Previous')), 'someArray' => array('yo, sup', 'nm nm', 'a' => array('foo', 'bar' => 'baz')), 'date' => new \DateTime() ); $logger->message('default message', $context); $logger->message('critical message', $context, 'critical');
The above will output to the Shell:
NOTICE: default message
Full Message: Blablablabla bla blaaaa blaaaa bar blaa
Extra Variables:
foo: bar
someArray: {"0":"yo, sup","1":"nm nm","a":{"0":"foo","bar":"baz"}}
site: 397
process: somepid
_date: 2015-07-07T16:39:55+02:00
CRITICAL: critical message
Full Message: Blablablabla bla blaaaa blaaaa bar blaa
Extra Variables:
foo: bar
someArray: {"0":"yo, sup","1":"nm nm","a":{"0":"foo","bar":"baz"}}
site: 397
process: somepid
_date: 2015-07-07T16:39:55+02:00
Or to Graylog: http://yourgrayloginstance.com/messages/graylog2_312/23a5e2b0-24b6-11e5-b0b9-001e67b4d4d0 (example might have some other sample data).
or PSR-3 compatible:
$logger->critical('critical message', $context);
Check the generated API docs for more info.
Muting Messages for Handlers
Sometimes you want to initialise multiple Handlers but not send a message to each. This can be done using the Mute option.
// initialise a few Handlers, use the default verbosity set in the Handler $shellHandler = new Handler\ShellHandler('trace'); // set the Verbosity to -1, which allows it to be muted $arrayHandler = new Handler\ArrayHandler('debug', -1); $logger = new Logger([$shellHandler, $arrayHandler]); // now send a message where $muted is set to true $logger->log('debug', 'foobar', ['baz'=>'bar'], true);
The result will be that ShellHandler will output the message "foobar", however the ArrayHandler will not receive the message.
This is useful if you always want to log messages to a centralised logging system but the production environment that the client can see doesn't need to see that message.
Trace level
The Flexilog adds one more level lower then debug
, the trace
level. To keep it compatible with the PSR\NullLogger
you need to call it in the following way:
$logger->log('trace', $message, $context);
The PSR\NullLogger
will then just ignore it.
Symfony Console
public function execute(InputInterface $input, OutputInterface $output)
{
$logger = new \Productsup\Logger(
array(
'Console' => new \Productsup\Handler\SymfonyConsoleHandler('debug', 2, $output)
)
);
$logger->message('message');
$logger->error('errrooorrr');
}
Outputs
[notice] message
[error] errrooorrr
Caveats
Depending on the Info object in use there might be some reserved keywords. Check the Info object you're using for the list of reserved keywords.