Download the PHP package leinonen/yii2-monolog without Composer

On this page you can find all versions of the php package leinonen/yii2-monolog. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-monolog

Latest Stable Version Total Downloads Latest Unstable Version License Scrutinizer Code Quality Code Coverage Build Status SensioLabsInsight

Yii2 Monolog

Yii2 Monolog allows one to use Monolog easily with Yii2. For instructions regarding Monolog itself please refer to the documentation.

Table of contents

Installation

Require this package, with Composer, in the root directory of your project.

Configuration

Configure the leinonen\Yii2Monolog\Yii2Monolog as a bootstrapped component in your application config.

An example configuration of one log channel called myLoggerChannel with a basic StreamHandler and a UidProcessor:

Channels

To see the core concepts about Monolog channels check the Offical Documentation for Monolog.

This component allows registering multiple channels with channel name => configuration array key value pairs with the channels configuration key.

Main channel

The component automatically registers a main channel which is used when requesting Psr\Log\LoggerInterface from the DI container or when fetching a Logger from the component without specifying a channel name.

The main channel is configurable with the configuration key mainChannel

If the main channel is null or not specified at all, the first channel from the channels list will be used as the main channel. With the example config above it would be myFirstChannel.

Handlers

The package supports all official and 3rd party handlers for Monolog. It uses leinonen\Yii2Monolog\CreationStrategies\ReflectionStrategy by default in background to figure out the config values which the handler is to be constructed with. The handlers are defined with a config key handlers in the Monolog configuration. All the handlers are resolved through Yii's DI container making it easier to implement your own custom handlers.

Example handler configuration with a stack of two handlers:

You can find the available handlers from the Monolog\Handler namespace

Yii2 specific handlers

The package also provides a specific creation strategies for couple of handlers to help integrating with Yii2.

StreamHandler

The path config value is resolved through Yii's getAlias() method making it possible to use aliases such as @app in the config. Use this instead of stream

RotatingFileHandler

The path config value is resolved through Yii's getAlias() method making it possible to use aliases such as @app in the config. Use this instead of filename

Formatters

The package supports all official and 3rd party formatters for Monolog. It uses leinonen\Yii2Monolog\CreationStrategies\ReflectionStrategy by default in background to figure out the config values which the formatter is to be constructed with. All the formatters are resolved through Yii's DI container making it easier to implement your own custom formatters.

It's possible to configure a custom formatter for each handler. The formatter is configured with a formatter key in the handler's config array:

You can find available formatters from the Monolog/Formatter namespace.

Processors

The package supports all official and 3rd party processors for Monolog. It uses leinonen\Yii2Monolog\CreationStrategies\ReflectionStrategy by default in background to figure out the config values which the processor is to be constructed with. All the processors are resolved through Yii's DI container making it easier to implement your own custom processors.

The processors can be defined globally for one target or specifically for a handler. Processors are configured with a processors key in the config array with an array of callables:

Or config to a specific handler:

You can find available processors from the Monolog/Processor namespace.

Configuring Handlers/Formatters/Processors after creation

For further customisation it's possible to specify a configure key for all classes that are created with leinonen\Yii2Monolog\CreationStrategies\ReflectionStrategy . The configure key must be a callable which receives the created class instance and config. It also has to return the instance. It is called just after the class has been resolved from Yii's DI container. For example it's possible to customize Monolog\Handler\RotatingFileHandler's filename format:

Usage

Using the component as a Yii's log target

If you want to integrate this component into an existing project which utilizes Yii's own logger, you can configure channels as log targets easily. See Yii's documentation about log targets here.

Example configuration:

In this case all the Yii's loggers messages will go through the handler / processor stack of myFirstChannel logger without touching any of your existing code.

If you leave the channel configuration out the target will use the main channel configured in the component.

Using the component standalone

If you want to not use Yii's logger at all it's possible to use this component as a completely standalone logger.

Fetching a specific logger from the component:

As the main channel is registered as the implementation of the Psr\Log\LoggerInterface you can also use constructor injection in your controllers:


All versions of yii2-monolog with dependencies

PHP Build Version
Package Version
Requires monolog/monolog Version ^1.22
yiisoft/yii2 Version ~2.0.11
php Version ^7.0
tightenco/collect Version ~5.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package leinonen/yii2-monolog contains the following files

Loading the files please wait ....