Coder Social home page Coder Social logo

slim-monolog's Introduction

Monolog Logging for Slim Framework

This repository adds support for logging to Monolog to the Slim Framework.

Installation

MonologWriter takes an array of handlers, an array of processors and a logger name.

$logger = new \Flynsarmy\SlimMonolog\Log\MonologWriter(array(
    'handlers' => array(
        new \Monolog\Handler\StreamHandler('./logs/'.date('Y-m-d').'.log'),
    ),
));

$app = new \Slim\Slim(array(
    'log.writer' => $logger,
));

This example assumes you are autoloading dependencies using Composer. If you are not using Composer, you must manually require the log writer class before instantiating it.

License

The Slim-Monolog is released under the MIT public license.

slim-monolog's People

Contributors

bladi87 avatar cmbrownfield avatar ffflabs avatar flynsarmy avatar joshwillik avatar olivierberro avatar sigjlr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slim-monolog's Issues

Undefined class constants

Hi,

I'm running Slim 2.2.0 and now encounter this error when declaring a new MonologWriter:

Fatal error:  Undefined class constant 'Slim\Log::EMERGENCY'

I get this error for all the new log levels added as part of: 00c4e3b872fbb2250c97bf7fefad326949902686

If I revert the changes everything works again.

Monolog throws error because of constructor

Monolog, as of 1.15.0, tries to create a dir on every log action and raises an exception: https://github.com/Seldaek/monolog/blob/6dd76b944d42d7b27bb3d09cd0f6fa88a80817f5/src/Monolog/Handler/StreamHandler.php#L51

Slim-Monolog creates an unused monolog instance with an invalid log dir in its constructor: https://github.com/Flynsarmy/Slim-Monolog/blob/master/Log/MonologWriter.php#L108

So applications with Monolog 1.15.0 and Slim-Monolog won't work now, I think.

Slim v3 support?

Does this library support Slim v3?

It doesn't mention any version requirement in README.md and I'm getting an error that Slim\Log colud not be found.

I looked in Slim's source, and v2 has a \Slim\Log, while 3v does not.

log directory path concatenation is wrong

The newest commit for monolog 1.15.0 breaks my logging:

$config['app']['log.writer'] = new \Flynsarmy\SlimMonolog\Log\MonologWriter(array(
    'handlers' => array(
        new \Monolog\Handler\StreamHandler(
            realpath(__DIR__ . '/logs')
                .'/'.$_ENV['SLIM_MODE'] . '_' .date('Y-m-d').'.log'
        ),
    ),
));

I get this error:

Fatal error: Uncaught exception 'UnexpectedValueException' with message 'There is no existing directory at "./logs" and its not buildable: Permission denied'

When I output the $stream in StreamHandler->construct() i get:

mylocalhost/mysite/logs/development_2015-07-17.log./logs/15-07-17.log

It seems like the path concatenation is somehow off.

Can you please create a tag for this repo

So that I can atleast include a version number in my composer.json file rather then dev-master, because if a breaking change was to be made in dev-master, my code would be broken at that point.

Installation and usage issues

Are the installation instructions missing something or am I? Shouldn't the install be:

composer require flynsarmy/slim-monolog

The installation instructions in the README shows usage, not installing.

I did the composer require as shown above, as I assume that this was assumed? But then I get the following error:

Fatal error: Uncaught Error: Class 'Slim\Log' not found in /var/www/server/public/index.php:10 Stack trace: #0 {main} thrown in /var/www/server/public/index.php on line 10

I would think there should be clear install instructions and then clear usage instructions. Code that I could drop into a route and it would just work.

Hard coded path in library

There is a hard-coded log location at line 110: https://github.com/Flynsarmy/Slim-Monolog/blob/master/Log/MonologWriter.php#L110

new \Monolog\Handler\StreamHandler('./logs/'.date('y-m-d').'.log'),

Since this hard coded location merges into the other locations array, it could easily cause a lot of problems in light-weight situations (like docker containers) which have virtually no disk space and do all their logging remotely. It also destroys one of the most valuable things about Monolog, that you have fine, granular control over where the logs go.

It really should be 'handlers' => array(),

Worse yet, because this merge is silent & undocumented, it took me about 3 hours to track this down as I didn't have a directory in "." called "logs".....

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.