Recommend this page to a friend! |
Classes of Smoren Freelight | PHP Simple Log Class | README.md | Download |
|
DownloadSimpleLogPowerful PSR-3 logging. So easy, it's simple!SimpleLog is a powerful PSR-3 logger for PHP that is simple to use. Simplicity is achieved by providing great defaults. No options to configure! Yet flexible enough to meet most logging needs. And if your application's logging needs expand beyond what SimpleLog provides, since it implements PSR-3, you can drop in another great PSR-3 logger like MonoLog in its place when the time comes with minimal changes. It is actively under development with development (0.y.z) releases. Features* Power and Simplicity * PSR-3 logger interface * Multiple log level severities * Log channels * Process ID logging * Custom log messages * Custom contextual data * Exception logging Setup Add the library to your
Use composer to install the library:
Composer will install SimpleLog inside your vendor folder. Then you can add the following to your .php files to use the library with Autoloading.
Alternatively, use composer on the command line to require and install SimpleLog:
Minimum Requirements* PHP 7 UsageSimple 20-Second Getting-Started Tutorial
That's it! Your application is logging! Extended Example
Logger output
Log OutputLog lines have the following format:
Log lines are easily readable and parsable. Log lines are always on a single line. Fields are tab separated. Log LevelsSimpleLog has eight log level severities based on PSR Log Levels.
By default all log levels are logged. The minimum log level can be changed in two ways: * Optional constructor parameter * Setter method at any time
Contextual DataSimpleLog enables logging best practices to have general-use log messages with contextual support data to give context to the message. The second argument to a log message is an associative array of key-value pairs that will log as a JSON string, serving as the contextual support data to the log message.
Logging ExceptionsExceptions are logged with the contextual data using the key exception and the value the exception variable.
Log ChannelsThink of channels as namespaces for log lines. If you want to have multiple loggers or applications logging to a single log file, channels are your friend. Channels can be set in two ways: * Constructor parameter * Setter method at any time
Debug FeaturesLogging to STDOUTWhen developing, you can turn on log output to the screen (STDOUT) as a convenience.
Dummy LoggerSuppose you need a logger to meet an injected dependency during a unit test, and you don't want it to actually log anything.
You can set the log level to
Unit Tests
StandardsSimpleLog conforms to the following standards: * PSR-3 - Logger Interface (http://www.php-fig.org/psr/psr-3/) LicenseSimpleLog is licensed under the MIT License. |