Download the PHP package sebk/small-logger without Composer
On this page you can find all versions of the php package sebk/small-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package small-logger
small-logger
Small logger is a simple php logger you can easily extends for your own need.
Basically, it implements possibility to log to : Standard output File (With log rotates) Http service such as logstash
It it easy to implement your own Formatter or Output writer.
SwitchLogicInterface allow you to implements your own logic to manage multiple log streams.
It also possible to add shortcut to logger for easier use by final developer.
Migrated
This lib has been migrated to framagit project.
A new composer package is available at https://packagist.org/packages/small/small-logger
Future commits will be done on framagit.
Install
Log to standard output
First define the switch loggic :
Then, you are abble to log :
Log to file
You can log to a single file :
Or redirect errors to another file :
In the second case, errors are redirected to the second file.
Then this call will write in '/var/log/my-log.log' :
And this call will write in '/var/log/my-error-log.log' :
Customizing logs
You can easy customize the behaviour of logs by writing your own classes implementing interfaces :
- switch : the switch logic
- formatter : log class diggest to log format
- output : the output writer
For example, we want to write to logstash. We will use the http type with the output factory. To get the best appropriate output for your project, use the output factory :
New we have the output, we can create our switcher :
In the getStream method, you can put your logic to manage more than one stream depends on $log itself or additional $data.
For example, you can set up a stream for error level and a stream for critical level.
If you want, the $data array may inject information to switch in complex architectures.
Now define your switch in logger and log :
Unit tests
To run unit tests, you are require to build unit-test container :
Then the container will build environement for testing and launch tests.
If you want to develop and add unit tests, turn off the BUILD environement var in docker-compose.yml by setting it to 0 :