Download the PHP package germania-kg/logger without Composer
On this page you can find all versions of the php package germania-kg/logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download germania-kg/logger
More information about germania-kg/logger
Files in germania-kg/logger
Package logger
Short Description Our Company's default logging solution: Pimple Service Provider for Logging with Monolog
License MIT
Informations about the package logger
Germania KG · Logger
Default logging solution for our websites: Service Provider for Logging with Monolog 1 and 2.
Installation with Composer
The major release 4 requires PHP 7.2+. The older release 3 supports Monolog 2.
Basics
Class LoggerServiceProvider is a Pimple ServiceProviderInterface and can be registered to any Pimple DI container (or array or \ArrayAccess). Its constructor requires the App or Logger name. – Optionally, the $_SERVER
context may pe passed. An optional third parameter turns on IP address anonymizing:
Pimple is not required.
The service providers cope with Arrays and \ArrayAccess instances as well.
Work with an array as base for another, more modern DI container. The register method amends and returns the passed array:
Or pass another DI container which implements \ArrayAccess:
Services provided
This Monolog Logger instance is your PSR-3 Logger:
This Monolog Handlers array is empty per default; it will be filled by one or more of the specialised Service Providers below.
Unless you want to add other handlers than those configured by the specialised Service providers you won't need to use these.
This Monolog Processors array contains per default just Monolog's WebProcessor with ip
, method
and url
extra context variables.
Unless you want to add other processors than those configured by the specialised Service providers you won't need to use these.
Adding processors to handlers
Monolog handlers are provided by Pimple services. Grab the handler instance and add another Monolog Processor by extending the service definition:
Specialised Service Providers
Log to Logfile
Class FileLoggerServiceProvider requires a logfile path. Optionally, you may pass a custom maximum number of logfiles (default: 30).
To set the loglevel, pass Monolog Loglevel constant or PSR-3 LogLevel (e.g. Monolog\Logger::DEBUG
or \Psr\Log\LogLevel::INFO
). Default is Monolog\Logger::DEBUG
.
Retrieve the Monolog handler
This handler is an instance of \Monolog\Handler\RotatingFileHandler
Log to StdErr (stream)
Class StreamLoggerServiceProvider accepts optional parameters for an output stream (default: php://stderr
) and a loglevel, either Monolog Loglevel constant or PSR-3 LogLevel (e.g. Monolog\Logger::DEBUG
or \Psr\Log\LogLevel::INFO
). Default is Monolog\Logger::DEBUG
.
Retrieve the Monolog handler
This handler is an instance of \Monolog\Handler\StreamHandler
Log using SwiftMailer
This service requires service definitions for SwiftMailer and SwiftMailer.HtmlMessage. Germania KG's germania-kg/mailer will provide those.
Class SwiftMailerLoggerServiceProvider accepts optional parameters for outer log level and inner loglevel, both either Monolog Loglevel constant or PSR-3 LogLevel (e.g. Monolog\Logger::DEBUG
or \Psr\Log\LogLevel::INFO
).
The outer loglevel (default: Monolog\Logger::WARNING
) will trigger Monolog's FingersCrossedHandler which in turn uses Monolog's BufferHandler to send an log messages digest using Monolog's SwiftMailerHandler. Any log message in the email sent will be of inner loglevel upwards (default: Monolog\Logger::DEBUG
)
Retrieve the Monolog handler
Despite its name, the handler is actually an instance of Monolog\Handler\FingersCrossedHandler
which wraps an instance of Monolog\Handler\BufferHandler
which wraps an instance of Monolog\Handler\SwiftMailerHandler
Log using CLImate Logger
This requires CLImate, available with Composer: league/climate
Class ClimateLoggerServiceProvider requires a Monolog Loglevel constant or PSR-3 LogLevel (e.g. Monolog\Logger::DEBUG
or \Psr\Log\LogLevel::INFO
).
Retrieve the Monolog handler
N.B. This is actually a Monolog\Handler\PsrHandler
instance which wraps a Climate Logger League\CLImate\Logger
Log using BrowserConsole Logger
Class BrowserConsoleLoggerServiceProvider optionally accepts a Monolog Loglevel constant or PSR-3 LogLevel (e.g. Monolog\Logger::DEBUG
or \Psr\Log\LogLevel::INFO
). If left out or set to null
, logging to browser console will be skipped.
Retrieve the Monolog handler
The handler is an instance of Monolog\Handler\BrowserConsoleHandler
Log to Microsoft Teams
Sends nicely formatted log messages to Microsoft Teams using Monolog's HtmlFormatter.
This requires CMDISP's monolog-microsoft-teams package, available via Composer: cmdisp/monolog-microsoft-teams.
Class TeamsLoggerServiceProvider requires a Incoming Webhook URL string, and optionally a Monolog Loglevel constant or PSR-3 LogLevel (e.g. Monolog\Logger::DEBUG
or \Psr\Log\LogLevel::INFO
). Registering this ServiceProvider to a Pimple DI container will silently skip if the Webhook URL is empty.
Deprecation notice
Class Germania\Logger\HtmlFormattedTeamsLogHandler
was an extension of the CMDISP\MonologMicrosoftTeams\TeamsLogHandler
class and provided better log message formatting. As of the v1.1 release of CMDISP's monolog-microsoft-teams package, this extension is not needed any longer and will be removed as of major release 5.
Retrieve the Monolog handler
The handler is an instance of \CMDISP\MonologMicrosoftTeams\TeamsLogHandler
Log to Slack channel
Class SlackLoggerServiceProvider requires Slack token, channel, and username. It optionally accepts a Monolog Loglevel constant or PSR-3 LogLevel (e.g. Monolog\Logger::DEBUG
or \Psr\Log\LogLevel::INFO
).
For more information on using Slack as Logger, see these links:
- https://blog.tschelhas.de/symfony/slack-als-logger-fuer-symfony-nutzen/
- https://github.com/Seldaek/monolog/blob/master/src/Monolog/Handler/SlackHandler.php
Retrieve the Monolog handler
The handler is an instance of \Monolog\Handler\SlackHandler
Usage Example
Development and Unit tests
Either copy phpunit.xml.dist
to phpunit.xml
and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:
All versions of logger with dependencies
pimple/pimple Version ^3.0
psr/log Version ^1.0
monolog/monolog Version ^1.16|^2.0
bramus/monolog-colored-line-formatter Version ^2.0|^3.0