GithubHelp home page GithubHelp logo

seldaek / monolog Goto Github PK

View Code? Open in Web Editor NEW
20.8K 20.8K 1.9K 4.63 MB

Sends your logs to files, sockets, inboxes, databases and various web services

Home Page: https://seldaek.github.io/monolog/

License: MIT License

PHP 100.00%
hacktoberfest logger logging php psr-3

monolog's Introduction

Monolog

Monolog - Logging for PHP Continuous Integration

Total Downloads Latest Stable Version

Note This is the documentation for Monolog 3.x, if you are using older releases see the documentation for Monolog 2.x or Monolog 1.x

Monolog sends your logs to files, sockets, inboxes, databases and various web services. See the complete list of handlers below. Special handlers allow you to build advanced logging strategies.

This library implements the PSR-3 interface that you can type-hint against in your own libraries to keep a maximum of interoperability. You can also use it in your applications to make sure you can always use another compatible logger at a later time. As of 1.11.0 Monolog public APIs will also accept PSR-3 log levels. Internally Monolog still uses its own level scheme since it predates PSR-3.

Installation

Install the latest version with

composer require monolog/monolog

Basic Usage

<?php

use Monolog\Level;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler('path/to/your.log', Level::Warning));

// add records to the log
$log->warning('Foo');
$log->error('Bar');

Documentation

Support Monolog Financially

Get supported Monolog and help fund the project with the Tidelift Subscription or via GitHub sponsorship.

Tidelift delivers commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use.

Third Party Packages

Third party handlers, formatters and processors are listed in the wiki. You can also add your own there if you publish one.

About

Requirements

  • Monolog ^3.0 works with PHP 8.1 or above.
  • Monolog ^2.5 works with PHP 7.2 or above.
  • Monolog ^1.25 works with PHP 5.3 up to 8.1, but is not very maintained anymore and will not receive PHP support fixes anymore.

Support

Monolog 1.x support is somewhat limited at this point and only important fixes will be done. You should migrate to Monolog 2 or 3 where possible to benefit from all the latest features and fixes.

Submitting bugs and feature requests

Bugs and feature request are tracked on GitHub

Framework Integrations

Author

Jordi Boggiano - [email protected] - http://twitter.com/seldaek
See also the list of contributors who participated in this project.

License

Monolog is licensed under the MIT License - see the LICENSE file for details

Acknowledgements

This library is heavily inspired by Python's Logbook library, although most concepts have been adjusted to fit to the PHP world.

monolog's People

Contributors

adlawson avatar akalongman avatar cbergau avatar cordoval avatar ericclemmons avatar glensc avatar gmponos avatar hkdobrev avatar jeroendedauw avatar lenar avatar lyrixx avatar mimmi20 avatar mintobit avatar mpdude avatar msabramo avatar naderman avatar nicolas-grekas avatar odino avatar paulstatezny avatar pomaxa avatar pryazhnikov avatar rgustbardon avatar rpkamp avatar rvanlaak avatar seldaek avatar sgoettschkes avatar staabm avatar stof avatar tatarko avatar timmow 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  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

monolog's Issues

Calculating a hash identifying the message

Monolog should be able to calculate a hash identifying a message. This would allows storing them in a storage when an error occur and flushing them in an handler only once instea dof having one message per request.

Weird severity levels - RFC 5424

How did you arrive at the weird numerical values for the logging levels?

RFC5424 still defines the values as 7 for debug to 0 for emergency.
Pretty much every system I know uses those values.

The priority according to 5424 is Facility*8 + severity, but you are obviously not using that either.

GELF handler

Hi,

I would like to add a GELF handler to the stack, but I'm missing a feature that you might can help me add.

I plan to use https://github.com/Graylog2/gelf-php as base for the gelf handler

I noticed that addRecord has an "extra" array key, but its unused? Whats the plan for it?

Non-Blocking options

Hi Jordi,

Are there any non-blocking options for this library? I'd like to use the streams/socket handlers perhaps if they support non-blocking.

Thanks.

update of symfony-standard with master branch dont update monolog to master

i dont know if this was intended, but i tried to update the monolog library in the symfony-standard-package (from master).
monolog version stays at 1.02 maybe because of the requirement in the composer file of symfony/monolog-bridge (master):
monolog/monolog: 1.*
it should be changed to "dev-master"

i create the issue here, because it was not possible to create an issue in symfony / MonologBridge
and seldaek is the same maintainer.

writing to doctrine database

So I wrote a custom handler in symfony2:

<?php

namespace Kunstmaan\AdminBundle\Modules;

use Symfony\Component\DependencyInjection\Container;

use Doctrine\ORM\EntityManager;

use Kunstmaan\AdminBundle\Entity\LogItem;
use Monolog\Logger;
use Monolog\Handler\AbstractProcessingHandler;

class LogHandler extends AbstractProcessingHandler
{
    private $initialized = false;
    private $container;

    public function __construct(Container $container, $level = Logger::DEBUG, $bubble = true){
        $this->container = $container;
        parent::__construct($level, $bubble);
    }

    protected function write(array $record){
        if (!$this->initialized) {
            $this->initialize();
        }

        $logitem = new LogItem();        
        $logitem->setChannel($record['channel']);
        $logitem->setLevel($record['level']);
        $logitem->setMessage($record['formatted']);
        $logitem->setCreatedAt($record['datetime']);

        $em = $this->container->get('doctrine')->getEntityManager();
        $em->persist($logitem);
        $em->flush();
    }

    private function initialize(){
        $this->initialized = true;
    }
}

In my config I defined this handler:

    kunstmaan_admin.handler.log:
        class: Kunstmaan\AdminBundle\Modules\LogHandler
        arguments:
            - @service_container 
        tags:
            - { name: log_handler }

and I add it to the monolog:

monolog:
    handlers:
        main:
            type: stream
            path: %kernel.logs_dir%/%kernel.environment%.log
            level: debug
        doctrine:
            type: service
            id: kunstmaan_admin.handler.log
            level: info

I get the following error:

Fatal error: Maximum function nesting level of '100' reached, aborting! in /home/projects/bancontact/data/bancontact/vendor/doctrine-dbal/lib/Doctrine/DBAL/Logging/DebugStack.php on line 54

Think this is because doctrine tries to write to the log, and I use doctrine to safe a logitem, etc.

Is there a way around?

date_default_timezone_get() error

I have recently run the composer update and got the following error:

date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in ...vendor/monolog/monolog/src/Monolog/Logger.php line 112

WebProcessor in command line

I don't know if it's a bug or not so i'll submit it anyway.

I just configured my application to log in a file when in 'dev' environment with a WebProcessor associated.
It works fine in a navigator, but when i launched a command in the command line i get this error:
Notice: Undefined index: REQUEST_URI in /home/mailloud/workspace/referentiel/vendor/monolog/src/Monolog/Processor/WebProcessor.php line 46

It's normal that 'REQUEST_URI' doesn't exist while w're not in a http process, and so no uri.

I think when call in command line this kind of processor should not work, and the fact that the command is launched in 'dev' mode should not change that.

With the option 'no-debug' the command works without problem bu at this time no log, not wanted if log are configured.

write error (race condition?)

I've been getting this message regularly when hitting the app w/ batch processes (nb., /path/to/log/file.log IS valid & writeable and was successfully written to by the 800 or so operations previous to this):

Fatal error: Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/path/to/log/file.log" could not be opened; it may be invalid or not writable.' in /var/www/daseframework/lib/Monolog/Handler/StreamHandler.php:67
Stack trace:
#0 /var/www/daseframework/lib/Monolog/Handler/AbstractProcessingHandler.php(41): Monolog\Handler\StreamHandler->write(Array)
#1 /var/www/daseframework/lib/Monolog/Logger.php(191): Monolog\Handler\AbstractProcessingHandler->handle(Array)
#2 /var/www/daseframework/lib/Monolog/Logger.php(294): Monolog\Logger->addRecord(100, 'INSERT INTO ite...', Array)
#3 /var/www/daseframework/lib/Dase/DBO.php(190): Monolog\Logger->debug('INSERT INTO ite...')
#4 /var/www/daseframework/lib/Dase/DBO/Item.php(162): Dase_DBO->insert()

perhaps there is a race condition??

improve error reporting for inexisting handler type

when i set the handler for a logger to a not existing one, i get a fatal exception that is confusing. the best would be an exception along "Did not find the handler you specified: $type. Available handlers are: ... . If you are adding your own handler, define the property monolog.handler.XXX.class."

PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'The parameter "monolog.handler.fingers_crossed_whatever.class" must be defined.' in /home/david/tmp/cmf-sandbox/vendor/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:77
Stack trace:
#0 /home/david/tmp/cmf-sandbox/vendor/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php(141): Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->get('monolog.handler...')
#1 /home/david/tmp/cmf-sandbox/vendor/symfony/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php(99): Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->resolveValue('%monolog.handle...')
#2 /home/david/tmp/cmf-sandbox/vendor/symfony/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php(83): Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass->resolveString('%monolog.handle...')
#3 /home/david/tmp/cmf-sandbox/vendor/s in /home/david/tmp/cmf-sandbox/vendor/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php on line 77

IntrospectionProcessor and LineFormatter invalid JSON

The introspection processor adds the class name to the extra paramters - if this name is namespaced (has a ) then the json that results from LineFormatter is invalid and cannot be re-assembled using json_decode.

eg:

{
    "file": "/src/Name/NameClass.php",
    "class": "Name\NameClass"
}

Its possible this is addressed in PHP 5.4 using the JSON_UNESCAPED_SLASHES - but it should be backwards compatible as well. I assume this would be an issue for any unescape slashes added by any of the processors.

Exclude library from logger

Hello,

Is it possible to exclude some librairies (by namespace) from logging?

Example:

I would like to have all logs in debug level excluding the ones coming from Assetic.

New tag

Hi @Seldaek

Please consider tagging a new release of Monolog so that MonologBundle can be in sync with it.
If we try to use ChromePHPHandler at the moment with Symfony SE master we have this error because composer forces download of version 1.0.2:

Fatal error: Class 'Monolog\Handler\ChromePHPHandler' not found in /path/to/project/vendor/symfony/symfony/src/Symfony/Bridge/Monolog/Handler/ChromePhpHandler.php on line 25

PushoverHandler cannot send multiple/ concurrent messages in quick succession

Hi!

We use the PushoverHandler, but found that sending messages to multiple users failed:

$logger->pushHandler(new PushoverHandler('app_key', 'user1_key', 'Error', self::CRITICAL));
$logger->pushHandler(new PushoverHandler('app_key', 'user2_key', 'Error', self::CRITICAL));

User 1 always receives the message, user 2 never receives the message.
Upon investigation of the problem, it looks like the stream is never closed, whilst the second call creates a new stream. Perhaps Pushover.net doesn't like this?

We found that posting the message using cURL solved the problem (being sure to curl_close() the channel. Here's the code we wrote to do so:

<?php

namespace acme\log\handlers;

use Monolog\Logger;
use Monolog\Handler\AbstractProcessingHandler;

class PushoverHandler extends AbstractProcessingHandler
{
    private $token;
    private $user;
    private $title;

    /**
     * @param string  $token  Pushover api token
     * @param string  $user   Pushover user id the message will be sent to
     * @param string  $title  Title sent to Pushover API
     * @param integer $level  The minimum logging level at which this handler will be triggered
     * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
     */
    public function __construct($token, $user, $title = null, $level = Logger::CRITICAL, $bubble = true)
    {
        parent::__construct($level, $bubble);

        $this->token = $token;
        $this->user = $user;
        $this->title = $title ?: gethostname();
    }

    protected function write(array $record)
    {
        curl_setopt_array($ch = curl_init(), array(
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_URL => 'https://api.pushover.net/1/messages.json',
            CURLOPT_POSTFIELDS => array(
                'token' => $this->token,
                'user' => $this->user,
                'message' => substr($record['message'], 0, 512 - strlen($this->title)),
                'title' => $this->title,
                'timestamp' => $record['datetime']->getTimestamp(),
            ),
        ));
        curl_exec($ch);
        curl_close($ch);
    }
}

Perhaps closing the stream connection in the original handler code also solves this problem, but we didn't test that.

Regards,
Alex

Pushover handler (maybe a generic Webservice Handler)

I was thinking about implementing a Pushover handler to announce critical errors through their api (which is a very simple http api). This would be cheaper than SMS, had the same effect (instant notice on the phone) and could be configured a bit more (Pushover has quiet hours if that's needed, for example).

I am not sure if it's better to implement a specific Pushover handler or a more generic WebService handler, which can be configured as needed. Such a generic handler could be used to send emails (e.g. postmark), sms (twilio) or to connect monolog with own solutions.

If you think this is a good idea (one of both or even both) and I would start to implement it, how should the http request be done? Is it ok to require something as curl or should it be done using low level php stuff like file_get_contents to ensure it's working without special requirements?

AbstractCurl setOptionsFromRequest

When using the Curl client and server has open_basedir() defined, using CURL_FOLLOWLOCATION stops the script.

As I read on the web, this has been fixed by cURL but it seens that PHP doesn't updated it yet.

A solution exists (read: http://stackoverflow.com/questions/3890631/php-curl-with-curlopt-followlocation-error)

So, I extended your \Buzz\Client\Curl class and override your prepare() method, but setOptionsFromRequest() is private and so I can't call it from my class. So I opened \Buzz\Client\AbstractCurl and changed it to protected for enabling the method call.

Great library by the way!!!

Different actions for different error levels

Hi,

Im not sure this really qualifies as an issue but my SO post got no replies so not sure where else to turn (http://stackoverflow.com/questions/13478573/symfony2-monolog-different-actions-for-different-error-levels).

I have set up Monolog for our Symfony2 project to email out critical errors to us when they occur.

However I would also like to log non-critical errors also, and to email these errors out to different recipients. I am struggling to see this in the documentation however it looks like it should be possible. I have set up the config as follows:

parameters:
    error_mail_sender: [email protected]
    error_mail_recipients: [[email protected]]
    critical_error_mail_recipients: [[email protected], [email protected]]

monolog:
    handlers:
        main_critical:
            type:         fingers_crossed
            action_level: critical
            handler:      grouped_critical
            bubble:       false
        main_error:
            type:         fingers_crossed
            action_level: error
            handler:      grouped_error
        grouped_critical:
            type:    group
            members: [streamed, buffered_critical]
        grouped_error:
            type:    group
            members: [streamed, buffered_error]
        streamed:
            type:  stream
            path:  "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
        buffered_critical:
            type:    buffer
            handler: swift_critical
        buffered_error:
            type:    buffer
            handler: swift_error
        swift_critical:
            type:       swift_mailer
            from_email: %error_mail_sender%
            to_email:   %error_mail_recipients%
            subject:    Critical error occurred!
            level:      debug
        swift_error:
            type:       swift_mailer
            from_email: %error_mail_sender%
            to_email:   %critical_error_mail_recipients%
            subject:    Non-critical error occurred
            level:      debug

With this set up we receive the critical errors but don't get the non-critical errors.

This set up was loosely based on the (unaccepted) answer to this question: http://stackoverflow.com/questions/12481353/how-to-include-the-severity-of-a-log-in-the-e-mail-subject.

Can anyone spot what is wrong with this? Or if it is not possible to do what I am trying?

Thanks a lot!

Can i have custom Levels in monolog

Currently i am using custom entity manager to write my logs
But i only want to log those things which i manually want to log.

logger1:
type: stream
path: /var/log/file1.log
level: MY_CUSTOM_LEVEL

logger1:
type: stream
path: /var/log/file2.log
level: MY_CUSTOM_LEVEL2

$logger.log("This is for level 1","MY_CUSTOM_LEVEL")

Flushing buffers on request

I am looking for options to force all buffering handlers to write their buffers manually. What would be the best method to accomplish that?

The use case for my request is a long running background worker. Due the current BufferHandler implementation, all buffers are written when the script ends. I have a SwiftMailerHandler to alert by email when something erroneous happens, but in the current setup, the emails never arrive (before the worker is closed).

Any comments?

Monolog swiftmailer handler sends one mail per log entry

with this configuration:

    mail:
      type: fingers_crossed
      action_level: error
      handler: mailed
      buffer_size: 100
    mailed:
      type: swift_mailer
      from_email: error_box @ gmail.com
      to_email: error_box @ gmail.com
      subject: Errors logged
      level: debug
      formatter: my_formatter

seems like swiftmailer is used to send one log line per message. That is really a bad idea since

  1. Some mail servers may start blocking send requests sent that often
  2. Some mail servers that receive such a big amount of mail may consider it is spam
  3. It creates bigger traffic and is longer to send 100 mails instead of 1

Swiftmailer handler must have some buffer to send multiple messages per mail.

@see https://groups.google.com/forum/#!topic/symfony-devs/IZ4a_-Oyt2c

configuration file support

Hi

Monolog looks very light and simple what makes it attractive to use in other projects not related to Symfony.
Is it possible to add configuration file to allow specify some channel options.
For the channel name

  • Handlers to push
  • Message level

Some thing like is done in Symfony2 config but in very simple way.

May be it is a goo idea to create factory method to get loggers by the channel name.

Hope you find that issue reasonable.

ChromePHPHandler and Objects

Hi! I unable to log objects using ChromePHPHandler, because you converting $message to a string. Can you please fix that? Thank you!

use platform end of line for lineformatter

Improvement

class LineFormatter implements FormatterInterface
{
const SIMPLE_FORMAT = "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n";

replaces by

class LineFormatter implements FormatterInterface
{
const SIMPLE_FORMAT = "[%datetime%] %channel%.%level_name%: %message% %context% %extra%" . PHP_EOL;

so that it works better on Windows where end of line is /r/n.

Can't inherit abstract function error

Hi,

On one of my servers that is running PHP 5.3.3-7, since the commit d345993, I get the following error :

Fatal error:  Can't inherit abstract function Symfony\Component\HttpKernel\Log\LoggerInterface::alert() (previously declared abstract in Psr\Log\LoggerInterface) in /var/www/tracker.primoapp.fr/releases/20130107094001/vendor/symfony/symfony/src/Symfony/Bridge/Monolog/Logger.php on line 23

I don't get the error on my local server (running PHP 5.3.10-1) so I guess that it is linked to a PHP issue. Could you tell me if there is any workaround or if I really have to upgrade my PHP version.

Thanks for your help,
Arnaud

Feature request: MemoryUsageProcessor(s)

Something that would be helpful in debug output is a processor that adds the output from memory_get_peak_usage and or memory_get_usage and returns it in a nice human readable format

Install

I just install Symfony2.1 when I used composer to update I get the following error:

Loading composer repositories with package information
Updating dependencies

I do have git and it is the path!!!

Thanks in advanced

FirePHPHandler as known FirePHP plugin

The FirePHPHandler currently uses the plugin URI of the Zend library as only known plugins can log to FirePHP.
It may be possible to have Monolog as a recognized plugin.

Allow to know if the logger has handlers which handle a level

Hi,

I'm currently integrating Monolog in a project which needs to know if the logger has handlers for a specific level. In this case, my app will create some specific objects in order to debug more precisely what's happened.

Currently, I must override the logger for being able to acces handlers.

If you're OK with this feature, I will create a PR.

GelfHandlerTest fails with an error when mlehner/gelf-php is not installed

It looks like GelfHandlerTest has the same issue as pointed out by @stof in a code review for RavenHandler:

~/Sites/sentry-test/vendor/monolog/monolog$ mv vendor/mlehner vendor/_mlehner 
~/Sites/sentry-test/vendor/monolog/monolog$ ls -ld vendor/mlehner
ls: cannot access vendor/mlehner: No such file or directory
~/Sites/sentry-test/vendor/monolog/monolog$ phpunit
PHP Fatal error:  Class 'Gelf\MessagePublisher' not found in /Users/marca/Sites/sentry-test/vendor/monolog/monolog/tests/Monolog/Handler/GelfHandlerTest.php on line 21
PHP Stack trace:
PHP   1. {main}() /Users/marca/pear/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /Users/marca/pear/bin/phpunit:46
PHP   3. PHPUnit_TextUI_Command->run() /Users/marca/pear/share/pear/PHPUnit/TextUI/Command.php:130
PHP   4. PHPUnit_TextUI_Command->handleArguments() /Users/marca/pear/share/pear/PHPUnit/TextUI/Command.php:139
PHP   5. PHPUnit_Util_Configuration->getTestSuiteConfiguration() /Users/marca/pear/share/pear/PHPUnit/TextUI/Command.php:671
PHP   6. PHPUnit_Util_Configuration->getTestSuite() /Users/marca/pear/share/pear/PHPUnit/Util/Configuration.php:768
PHP   7. PHPUnit_Framework_TestSuite->addTestFiles() /Users/marca/pear/share/pear/PHPUnit/Util/Configuration.php:848
PHP   8. PHPUnit_Framework_TestSuite->addTestFile() /Users/marca/pear/share/pear/PHPUnit/Framework/TestSuite.php:419
PHP   9. PHPUnit_Util_Fileloader::checkAndLoad() /Users/marca/pear/share/pear/PHPUnit/Framework/TestSuite.php:358
PHP  10. PHPUnit_Util_Fileloader::load() /Users/marca/pear/share/pear/PHPUnit/Util/Fileloader.php:79
PHP  11. include_once() /Users/marca/pear/share/pear/PHPUnit/Util/Fileloader.php:95

Fatal error: Class 'Gelf\MessagePublisher' not found in /Users/marca/Sites/sentry-test/vendor/monolog/monolog/tests/Monolog/Handler/GelfHandlerTest.php on line 21

Call Stack:
    0.0003     633432   1. {main}() /Users/marca/pear/bin/phpunit:0
    0.0041    1150600   2. PHPUnit_TextUI_Command::main() /Users/marca/pear/bin/phpunit:46
    0.0042    1151328   3. PHPUnit_TextUI_Command->run() /Users/marca/pear/share/pear/PHPUnit/TextUI/Command.php:130
    0.0042    1151328   4. PHPUnit_TextUI_Command->handleArguments() /Users/marca/pear/share/pear/PHPUnit/TextUI/Command.php:139
    0.0164    3191376   5. PHPUnit_Util_Configuration->getTestSuiteConfiguration() /Users/marca/pear/share/pear/PHPUnit/TextUI/Command.php:671
    0.0164    3192408   6. PHPUnit_Util_Configuration->getTestSuite() /Users/marca/pear/share/pear/PHPUnit/Util/Configuration.php:768
    0.0232    3560352   7. PHPUnit_Framework_TestSuite->addTestFiles() /Users/marca/pear/share/pear/PHPUnit/Util/Configuration.php:848
    0.0596    6247784   8. PHPUnit_Framework_TestSuite->addTestFile() /Users/marca/pear/share/pear/PHPUnit/Framework/TestSuite.php:419
    0.0597    6248384   9. PHPUnit_Util_Fileloader::checkAndLoad() /Users/marca/pear/share/pear/PHPUnit/Framework/TestSuite.php:358
    0.0597    6248544  10. PHPUnit_Util_Fileloader::load() /Users/marca/pear/share/pear/PHPUnit/Util/Fileloader.php:79
    0.0600    6392056  11. include_once('/Users/marca/Sites/sentry-test/vendor/monolog/monolog/tests/Monolog/Handler/GelfHandlerTest.php') /Users/marca/pear/share/pear/PHPUnit/Util/Fileloader.php:95

Buffer repeated messages

It would be nice to have some kind of buffer which group same messages together with counting.

For example, on a production webserver, if the homepage generates an error, and the mail handler is being used. The operation team would receive as many emails as requests.

It should be nice to receive only 1 mail of the same error every N occurrences the error.

It is different from the BufferHandler because of the BufferHandler actually outputs every message log, even if they're identical, and this results in a HUGE mail, too much noise. I only need the relevant information once, not repeated N times.

Problems with \Guzzle\Http\Exception\BadResponseException

When logging the Exception via $logger->addCritical($e->getMessage(), $e->getTrace()) (within Symfony2) following happens:

Warning: get_class() expects parameter 1 to be object, resource given in /var/www/localhost/vendor/monolog/src/Monolog/Formatter/NormalizerFormatter.php line 79

When looking at the type of $data in normalize() it says "unknown type".

The Traceback of the Exception:

#0 /var/www/localhost/vendor/Guzzle/src/Guzzle/Http/Message/Request.php(194): Guzzle\Http\Exception\BadResponseException::factory(Object(Guzzle\Http\Message\EntityEnclosingReque
st), Object(Guzzle\Http\Message\Response))
#1 [internal function]: Guzzle\Http\Message\Request::onRequestError(Object(Guzzle\Common\Event))
#2 /var/www/localhost/vendor/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php(148): call_user_func(Array, Object(Guzzle\Common\Event))
#3 /var/www/localhost/vendor/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php(49): Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(Array, 'request
.error', Object(Guzzle\Common\Event))
#4 /var/www/localhost/vendor/Guzzle/src/Guzzle/Http/Message/Request.php(889): Symfony\Component\EventDispatcher\EventDispatcher->dispatch('request.error', Object(Guzzle\Common\E
vent))
#5 /var/www/localhost/vendor/Guzzle/src/Guzzle/Http/Message/Request.php(557): Guzzle\Http\Message\Request->processResponse()
#6 /var/www/localhost/vendor/Guzzle/src/Guzzle/Http/Curl/CurlMulti.php(540): Guzzle\Http\Message\Request->setState('complete')
#7 /var/www/localhost/vendor/Guzzle/src/Guzzle/Http/Curl/CurlMulti.php(410): Guzzle\Http\Curl\CurlMulti->processResponse(Object(Guzzle\Http\Message\EntityEnclosingRequest), Obje
ct(Guzzle\Http\Curl\CurlHandle), Array)
#8 /var/www/localhost/vendor/Guzzle/src/Guzzle/Http/Curl/CurlMulti.php(292): Guzzle\Http\Curl\CurlMulti->perform()
#9 /var/www/localhost/vendor/Guzzle/src/Guzzle/Http/Client.php(474): Guzzle\Http\Curl\CurlMulti->send()
#10 /var/www/localhost/vendor/Guzzle/src/Guzzle/Http/Message/Request.php(286): Guzzle\Http\Client->send(Object(Guzzle\Http\Message\EntityEnclosingRequest))

Buffer handler not working as expected on php 5.3.10

The Buffer handler depends on the __destruct() method to push the buffered records to the sub-handler. looks like this doesn't always work on PHP 5.3.10 as destructors don't run on shutdowns caused by fatal errors.

the solution would require adding this line to the constructor of the AbstractHandler

register_shutdown_function(array($this, '__destruct'));

Ability to customize subject line of emails in processor

Hi,

Is there any way we could have the subject line of an error email being sent via a swift mailer instance using the processor? currently all of the error emails have the same subject line of "Error email" regardless of what sort of exception it has caught. Ultimately I would like the exception name to be in the subject line.

Even if we could just have key'd parameters inside the subject: configuration inside config.yml, which can then be set by the processor (similar to a prepared statement in sql) that would be excellent.

Cheers

make monolog installable through pear

as @fabpot planning to provide a pear package for Silex, it was brought up, that it would be good, if the dependencies could be also provided through pear:
https://github.com/fabpot/Silex/issues/82
I know that Monolog is/will be available through composer, but I think it would be a good idea, if the dependencies for Symfony2/Silex could be managed through one tool.
As Symfony2 and most of its dependencies available through pear, I think it would be logical to have a pear package for Monolog.

Display microseconds is not possible

LineFormatter configured with the "Y-m-d H:i:s:u" - format-parameter shows microseconds as 0 cause the php-constructorof the DateTime-object dont save the microseconds.
maybe we can adjust in the Logger-class, addRecord-function as follows (see the 'datetime' part):

    $record = array(
        'message' => (string) $message,
        'context' => $context,
        'level' => $level,
        'level_name' => self::getLevelName($level),
        'channel' => $this->name,
        'datetime' => date_create_from_format('U.u', microtime(true)),
        'extra' => array(),
    );  

reference: http://www.php.net/manual/en/datetime.createfromformat.php#107438

FirePHPHandler Log arrays as Firephp "table"

Hi,

Firephp has a good way to render "tables" http://www.firephp.org/HQ/Use.htm
I was triying to figure how to send arrays to a debug message and make it appear as the firephp "table" format. But I ended at line 191 on Logger.php 'message' => (string) $message,.
All records are cast to strings? How can I send different types of variables?

Why can't this logger log objects? Why only arrays?

FirePHP supports objects. ChromePHP supports objects. In fact, some objects even have toString methods just for this very purpose. So, why can't we send objects to the logs or can we and I'm missing something. It better not be for some silly reason like "saving file space in text logs" or something. I may have to fork this project to integrate that change if there isn't a way to do it natively that I'm missing.

Monolog not writing to log files using base sf2 config?

Hey guys,

Since approx last saturday I've noticed that monolog is refusing to write log files to my dev site, I thought I may have messed up my dev config files but I've just tried using a clean SF2 setup and it works fine. I tried an older project of mine (thath as older deps) and it seems that doing $this->get('logger')->err('foo'); logs to a file just fine, but any project with the current deps of SF2 / Monolog are refusing to write errors logs.

If anyone can please try $container->get('logger')->err('message'); inside their symfony2 project, and tell me if their project is in fact writing error logs?

I've put together this for anyone who can please tell me if they actually get the message 'foo bar' written out to their /app/logs/dev.log

I've somewhat narrowed it down to the monolog instance having no 'processors' when it goes to write its log files, but I can't believe that no one has picked this up? I've got a fairly big website going live with this in ~12 hours so I would much appreciate some assistance.

cheers

New commit 01721704fda causes FireBug to break

ErrorException: Notice: Undefined property: Symfony\Bridge\Monolog\Handler\FirePHPHandler::$sendHeaders in /vagrant/vendor/symfony/symfony/src/Symfony/Bridge/Monolog/Handler/FirePHPHandler.php line 66

Always do count on buffer array not a good idea

This issue for all buffered handlers.

    $this->buffer[] = $record;
    if ($this->bufferSize > 0 && count($this->buffer) > $this->bufferSize) {
        array_shift($this->buffer);
    }

Better its shoud be independent counter and change the name "size" to "limit"

    $this->buffer[] = $record;
    $this->bufferSize++;
    if ($this->bufferLimit > 0 && $this->bufferSize === $this->bufferLimit) {
        array_shift($this->buffer);
        $this->bufferSize--;
    }

Or add option to flush records if buffer is full

Add Success level

Sometimes we want to log successful operations. There are 5 level of errors and 0 indicating positive result. I suggest adding another log level of success.

Your opinion before implementation ?

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.