Download the PHP package originphp/log without Composer
On this page you can find all versions of the php package originphp/log. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download originphp/log
More information about originphp/log
Files in originphp/log
Informations about the package log
Log
There are 4 built in Log Engines, and it is easy to implement your own. You can use the Log
static class or PSR-3 Logger
class.
Installation
To install this package
File
- Logs messages to filesConsole
- Displays the log messages to the console screenEmail
- Sends log messages via emailSyslog
- Recommended for production systems
First you need to configure the Log library, in your application bootstrap or configuration.
Then to log
This will produce something like this in /var/www/logs/application.log
.
Channels
To group your log messages, set a channel name.
This will create a log entry like this
Placeholders
You can also use placeholders in the message.
Adding data to messages
After placeholders any have been replaced, any remaining data will be converted to a JSON string.
Which will output like this
Log Levels
Log works with all the different levels as defined in the RFC 5424 specifications.
Configuration
You can use a single engine or multiple engines at once, and you can also customize which levels to Log on.
File Engine
To configure the file engine logging
Options for the File Engine are:
- file: file with full path
- levels: default
[]
. If you want to restrict this configuration to only certain levels, add the levels to an array e.g.['critical','emergency','alert']
- channels: default
[]
. If you want to restrict this configuration to only certain channels, add the channels to an array e.g.['invoices','payments']
- size: number of bytes when to rotate log, or you can use MB or GB, e.g. 10MB. To disable log rotation set this to
0
. - rotate: the number of times to rotate, if set to 0, then it will delete once it reaches that size.
Email Engine
To configure email logging
Options for the Email Engine are:
- levels: default
[]
. If you want to restrict this configuration to only certain levels, add the levels to an array e.g.['critical','emergency','alert']
- channels: default
[]
. If you want to restrict this configuration to only certain channels, add the channels to an array e.g.['invoices','payments']
- to: The to email address or an array with the email address and name which will be used. e.g.
[email protected]
or['[email protected]','Tony Robbins']
. - from: The from email address or an array with the email address and name which will be used. e.g.
[email protected]
or['[email protected]'=>'System Notifications']
. - host: this is SMTP server hostname
- port: port number default 25
- username: the username to access this SMTP server
- password: the password to access this SMTP server
- ssl: default is false, set to true if you want to connect via SSL
- tls: default is false, set to true if you want to enable TLS
- timeout: how many seconds to timeout
You should always test your email configuration first, if an exception occurs when trying to send the email, it is caught and is not logged to prevent recursion.
Console Engine
To configure the Console Engine
Options for the Console Engine are:
- stream: default:
php://stderr
this is the stream to use - levels: default
[]
. If you want to restrict this configuration to only certain levels, add the levels to an array e.g.['critical','emergency','alert']
- channels: default
[]
. If you want to restrict this configuration to only certain channels, add the channels to an array e.g.['invoices','payments']
Syslog Engine
You should use the Syslog engine on your production server. To configure the Syslog engine.
Options for the Syslog Engine are:
- levels: default
[]
. If you want to restrict this configuration to only certain levels, add the levels to an array e.g.['critical','emergency','alert']
- channels: default
[]
. If you want to restrict this configuration to only certain channels, add the channels to an array e.g.['invoices','payments']
You can also pass settings to the openlog
command, these are identity
,option
,facility
, see openlog for more information on what these do.
Example
Lets say you want to configure the logger to log all events in a file as normal, send critical log entires by email and create a separate log for just payments.
Creating a Custom Log Engine
To create a custom Log Engine, create the folder structure app/Log/Engine
, and create an engine class with the method log
.
Then in your bootstrap configuration
PSR-3 Logger
The Log library uses a PSR-3 Logger that you may want to use instead of the static Log
class.
When you create the Logger
instance you can pass a single engine configuration, which is common when just starting on a new app.
To change the settings for an engine, or add additional engines or configurations of engines
All versions of log with dependencies
originphp/configurable Version ^2.0.0
originphp/email Version ^2.0
psr/log Version ^1.0.1 || ^2.0