2017 © Pedro Peláez
 

symfony-bundle custom-logger-bundle

A bundle for logging to non-default files in Symfony2/3

image

vkr/custom-logger-bundle

A bundle for logging to non-default files in Symfony2/3

  • Wednesday, May 10, 2017
  • by wladislavk
  • Repository
  • 1 Watchers
  • 0 Stars
  • 217 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

About

This bundle is a small syntactical wrapper on top of Monolog that allows to easily switch between several log files. It does not have any dependencies except for Monolog and Symfony and there is nothing to do at installation., (*1)

Usage

This is how the bundle is meant to be used. From your controller:, (*2)

$logger = $this->get('vkr_custom_logger.logger');
$logger->setLogger('my_log');
$logger->addInfo('hello world');

The 'hello world' message with Monolog's info and timestamp will be printed to the file at /app/logs/my_log.log (/var/logs/my_log.log for Symfony3). If this file does not exist, a FileNotFoundException will be thrown., (*3)

If you are initializing the service manually, you will need to specify the location of your app/ directory without a trailing slash:, (*4)

$logger = new VKR\CustomLoggerBundle\Services\CustomLogger('/my/app/dir');

One more small feature is that you can get the path to the currently used log file - for some reason original Monolog does not allow you to do it., (*5)

$logger->setLogger('my_log');
$loggerHandlers = $logger->getHandlers();
$primaryHandler = $loggerHandlers[0];
$filename = $primaryHandler->getUrl();

If the file has insufficient permissions, this bundle will not give you any exceptions, but Monolog will - when you try to do something like $logger->addInfo()., (*6)

API

*void CustomLogger::__construct(string $rootDir)*, (*7)

Sets path to the app/ directory., (*8)

Monolog\Logger CustomLogger::setLogger(string $logName, string $extension = 'log', string $logDir = null), (*9)

The first argument is a name of the log file without path and extension. If the third argument is not given, the directory will default to /app/logs for Symfony2, and /var/logs for Symfony3., (*10)

string CustomLogger::getLogfile(string $logName = null), (*11)

Displays full path to the log file - in case you forget where it should be. Providing the optional argument is deprecated., (*12)

string StreamHandler::getLogDir(), (*13)

Displays full path to the directory with log files. Should be called only after setLogger()., (*14)

The Versions

10/05 2017

dev-master

9999999-dev https://github.com/wladislavk/CustomLoggerBundle

A bundle for logging to non-default files in Symfony2/3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vladislav Kryshtanovskiy

monolog symfony2 symfony3 logs

10/05 2017

1.3.0

1.3.0.0 https://github.com/wladislavk/CustomLoggerBundle

A bundle for logging to non-default files in Symfony2/3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vladislav Kryshtanovskiy

monolog symfony2 symfony3 logs

23/03 2017

1.2.2

1.2.2.0 https://github.com/wladislavk/CustomLoggerBundle

A bundle for logging to non-default files in Symfony2/3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vladislav Kryshtanovskiy

monolog symfony2 symfony3 logs

14/08 2016

1.2.1

1.2.1.0 https://github.com/wladislavk/CustomLoggerBundle

A bundle for logging to non-default files in Symfony2/3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vladislav Kryshtanovskiy

monolog symfony2 symfony3 logs

14/08 2016

1.1.0

1.1.0.0 https://github.com/wladislavk/CustomLoggerBundle

A bundle for logging to non-default files in Symfony2/3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vladislav Kryshtanovskiy

monolog symfony2 symfony3 logs

14/08 2016

1.2.0

1.2.0.0 https://github.com/wladislavk/CustomLoggerBundle

A bundle for logging to non-default files in Symfony2/3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vladislav Kryshtanovskiy

monolog symfony2 symfony3 logs

17/07 2016

1.0.0

1.0.0.0 https://github.com/wladislavk/CustomLoggerBundle

A bundle for logging to non-default files in Symfony2/3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vladislav Kryshtanovskiy

monolog symfony2 symfony3 logs