seldaek / monolog Goto Github PK
View Code? Open in Web Editor NEWSends your logs to files, sockets, inboxes, databases and various web services
Home Page: https://seldaek.github.io/monolog/
License: MIT License
Sends your logs to files, sockets, inboxes, databases and various web services
Home Page: https://seldaek.github.io/monolog/
License: MIT License
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'));
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
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
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.
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.
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.
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.
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
ErrorException: Notice: Undefined property: Symfony\Bridge\Monolog\Handler\FirePHPHandler::$sendHeaders in /vagrant/vendor/symfony/symfony/src/Symfony/Bridge/Monolog/Handler/FirePHPHandler.php line 66
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.
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
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
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.
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
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??
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.
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.
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.
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.
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?
The notice and emerg levels are not available in monolog.
http://php.net/manual/fr/function.syslog.php
level setting should be passed as is to the syslog handler, without trying to translate from available monolog log levels.
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?
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?
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!!!
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!
Some locales use , as decimal digit separator instead of . This breaks datetime creation in Logger->addRecord().
I ran across this bugg using:
setlocale(LC_ALL, "sv_SE.utf8", "sv_SE", "sv");
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
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.
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.
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
Swiftmailer handler must have some buffer to send multiple messages per mail.
@see https://groups.google.com/forum/#!topic/symfony-devs/IZ4a_-Oyt2c
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?
The message is assumed to be a string atm, but serializing on the fly might be nice.
:)
It is not possible to use an external syslog server, it can only log to the local syslog server.
My proposal would be to extract that code to a dedicated strategy class, for example ActivationStrategyInterface
, and provide the current behavior as an ErrorLevelActivationStrategy
.
My use case at the moment is to not activate the FingersCrossedHandler on certain 404 errors.
If you like the idea, I can provide an implementation.
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")
Feature request.
Do you have any plans implementing http://www.chromephp.com/ handler?
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
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.
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
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 ?
Hi! I unable to log objects using ChromePHPHandler, because you converting $message to a string. Can you please fix that? Thank you!
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?
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))
Is there any way that i can use Monolog to send log messages to mysql database for reporting purposes.
I wantt o see whats happening on my site
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.
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
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
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
I just install Symfony2.1 when I used composer to update I get the following error:
Loading composer repositories with package information
Updating dependencies
Installing monolog/monolog (dev-master 0f3dc95)
Cloning 0f3dc95
[RuntimeException]
Failed to clone http://github.com/Seldaek/monolog, git was not found, check
that it is installed and in your PATH env.
I do have git and it is the path!!!
Thanks in advanced
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.