katzgrau / KLogger

A Simple Logging Class For PHP
http://codefury.net/projects/klogger/
981 stars 284 forks source link

disable logging while leaving methods in place #76

Closed tobsn closed 8 years ago

tobsn commented 8 years ago

Is there any way to turn off logging completely? I want to turn it on/off depending on environment.

currently I'm handling it this way:

$this->log = new Katzgrau\KLogger\Logger(
    __DIR__.'/logs',
    (
        ( getenv('APP_ENV') == 'production' )
        ? Psr\Log\LogLevel::EMERGENCY
        : Psr\Log\LogLevel::DEBUG
    )
);
katzgrau commented 8 years ago

There used to be a log level named ::OFF, but since we switched to implementing the PSR standard it went away.

Adding an enable($bool) method to disable logging would probably be a decent idea, although I'd probably imagine you really would want EMERGENCY errors in any environment, right?

tobsn commented 8 years ago

well... it's deployed to elastic beanstalk so textfile logging is pretty useless since it would happen on any of many servers - error handling is done via bugsnag so that's sorta taken care of. I use it purely locally and on staging (one server) which is why I wanted a nice log file but all that should be silent on production. technically the emergency workaround would work since I only use debug(), notice() etc.

honestly maybe it's not even needed... since the log level set to emergency essentially turns it off unless I use emergency().

(btw. if you know any other way to locally nicely debug... logging is all I came up with so far since it's an API and a worker (no interface, fed by queue))

while we're at it - what kinda bothers me is the issue that I can't pass strings into the second param, only an array - is there some kind of trick to make that work or is that just how it is?

katzgrau commented 8 years ago

There's always xdebug and ChromePHP - found them both pretty useful in the past: http://xdebug.org/

As for the second param - we're just following the logger interface: https://github.com/php-fig/log/blob/master/Psr/Log/AbstractLogger.php