Download the PHP package oasis/logging without Composer
On this page you can find all versions of the php package oasis/logging. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download oasis/logging
More information about oasis/logging
Files in oasis/logging
Package logging
Short Description Wrapper of monolog/monolog. Should be easier to use/configure than monolog
License MIT
Informations about the package logging
MLogger - logging for Oasis projects
oasis/logging provides classes and functions used to write logs.
The component can be referred to as MLog or MLogger in short.
There are a list of log handlers provided by default:
- Console Handler
- Local File Handler
- Local Error Handler
- AWS SNS Handler
MLog adhere strictly to the PSR-3 standard and uses monolog/monolog as its underlying implementation.
Installation
Install the latest version with command below:
Basic Usage
It is easy to use MLogger withour any configuration:
Using the Logger directly
A Monolog\Logger
can be used directly. This provides the freedom to
integrate MLog with other PSR-3 compatible components who need logging
tools.
Add Handler
Thanks to the mature community of monolog/monolog, MLog can take use of all the existing Handlers for monolog.
In addition, you can also write your own handler that implements the
Monolog\Handler\HandlerInterface
interface.
Adding a handler to MLog is as simple as:
Use auto-rotated-timestamp for file handler
The Oasis\Mlib\Logging\LocalFileHandler
can be easily configured to rotate its filename based on time changes. This is a very useful feature if your script is a longlive script which runs more than just a few seconds. Provided the correct name pattern, the local filename will rotate each time the preset interval has passed. Here is an example:
The supported name patterns are:
pattern | meaning |
---|---|
%date% | substituted by date of now, in the format: yyyymmdd |
%hour% | substituted by hour of now, in the format: HH (00-23) |
%minute% | substituted by minute of now, in the format: ii (00-59) |
%second% | substituted by second of now, in the format: ss (00-59) |
%script% | substituted by name of current script, filename only without directory names |
%pid% | substituted by current process ID |
Using AWS SNS to auto handle alert
The Oasis\Mlib\Logging\AwsSnsHandler
provides a handler which is only
processed when log above certain level (default to ALERT) is triggered.
It is an especially useful tool under production environment. It buffers all the logs and discard them if the script exits without error. If anything like a fatal error has put the script to exit abnormally, the handler will publish all the buffer as well as an ALERT log to the specified AWS SNS topic.
The AwsSnsHandler is an optional feature and it depends on the oasis/aws-wrappers component:
To use the AwsSnsHandler, try the code below:
All versions of logging with dependencies
bramus/monolog-colored-line-formatter Version ^2.0
oasis/utils Version ^1.6