The MonologBundle
provides integration of the Monolog
library into the Symfony framework.
More information in the official documentation.
This bundle is released under the MIT license
Symfony Monolog Bundle
Home Page: symfony.com
License: MIT License
The MonologBundle
provides integration of the Monolog
library into the Symfony framework.
More information in the official documentation.
This bundle is released under the MIT license
Currently, the XML schema doesn't include the excluded-404s
element which was introduced in cb5189e.
I was doing: php composer.phar update
and got
Updating monolog/monolog (dev-master 52b454f => 1.2.1)
Checking out 1.2.1
Updating symfony/monolog-bundle (dev-master v2.1.5 => 2.1.x-dev v2.2.0-BETA1)
Checking out v2.2.0-BETA1
...
PHP Fatal error: Class 'Symfony\Bundle\MonologBundle\MonologBundle' not found in /srv/www/htdocs/icms/app/AppKernel.php on line 10
PHP Stack trace:
...
Fatal error: Class 'Symfony\Bundle\MonologBundle\MonologBundle' not found in /srv/www/htdocs/icms/app/AppKernel.php on line 10
...
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception
[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command.
Now every time I run php app/console cache:clear
now I get the error as well.
I am using this cookbook entry to send logs via email: http://symfony.com/doc/current/cookbook/logging/monolog_email.html
Is there a way to prevent it from sending errors for 503 response codes? I am using 503 response codes so that Google does not delete the site rank. Obviously I don't want to be spammed if 5 pages have been disabled and people are trying to view them.
Am I missing something or there is no way to enable this flag through the configuration?
https://github.com/Seldaek/monolog/blob/master/src/Monolog/Formatter/LineFormatter.php#L47
If that's right - what is the recommended way to enable it? May be we might have an option for that?
Looking at the code I see that there is a return immediately after the service alias is created. Should not be also possible to override whichever formatter the service has to a custom one?
My use case is with the SncRedisBundle, where no formatter is set for the service and monolog doesn't call the setFormatter method either.
Thanks!
The formatter seems to have been accidently removed from the XSD, causing the config file to fail validation when the service container is built.
Hello,
As of Monolog Bundle 2.4 it should be possible to define additional channels in the monolog config:
http://symfony.com/doc/current/cookbook/logging/channels_handlers.html
However, when I define them in XML as per the example on the above page the XSD does not validate:
[ERROR 1871] Element '{http://symfony.com/schema/dic/monolog}channel': This element is not expected. Expected is ( {http://symfony.com/schema/dic/monolog}handler ).
The monolog-1.0.xsd also does not mention the 'channel' element to be allowed in the 'config' element besides the 'handler' element.
Is this a bug?
Hello, since Monolog is based on PSR-3 most classes the depend on a logger can typehint against Psr\Log\LoggerInterface
.
I was wondering if it could be added to the classes to compile (here), I haven't find any discussion about it so I'm not sure what are the arguments against it.
Currently this bundle is at 1.6 of monolog while the monolog repo is currently at 1.8. 1.8 provides newer GELF support as well as a flurry of new handlers. Is there a change that this bundle will get upgraded soon?
Hello.
If I throw a Symfony\Component\Security\Core\Exception\AccessDeniedException
or a Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
I do not want a log about this exception, because I thrown it.
For the security, The Symfony\Component\Security\Core\Exception\AccessDeniedException
is converted to a Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
in the Symfony\Component\Security\Http\Firewall\ExceptionListener::handleAccessDeniedException
.
I think we can extends the configuration to all kind of exception in the namespace Symfony\Component\HttpKernel\Exception\*
, because If I throw an HttpKernel exception, it don't want a log.
What do you think ?
Problem description:
The configuration option for processors per handler is not available.
Docs: http://symfony.com/doc/current/cookbook/logging/monolog.html#adding-a-session-request-token
If you use several handlers, you can also register the processor at the handler level instead of globally.
Example: https://github.com/symfony/MonologBundle/blob/master/DependencyInjection/Configuration.php#L562
Error:
[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]
Unrecognized options "processors" under "monolog.handlers.main"
Config:
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
processors: [@monolog.processor.log]
Notice that no actual configuration option for "processors" can be found in the DI configuration.
Note: this is a copy of symfony/symfony#10704
Hi,
I'm working on a Symfony 2 application, and I'd like to temporary disable logging.
I found that adding the NullHandler
on top of the configured handlers shall do the job.
Here's my monolog XML configuration:
<monolog:config>
<monolog:handler name="null_handler" type="null" />
<monolog:handler name="file_handler" type="stream" level="info" path="%kernel.logs_dir%/%kernel.environment%.log" />
</monolog:config>
However, when I access a web page, this error occured:
InvalidArgumentException in MonologExtension.php line 611:
Invalid handler type "" given for handler "null_handler"
It seems the null
type in the XML parameter is treated as a blank string, and I guess there may be an issue in the Configuration
class of the bundle.
What is your opinion?
Thanks for your help,
BR
Hi,
would it be possible to create a new release (2.6.2 ?) since there are a lot of new supported handlers since 2.6.1 was created on July 21st ? I'm particularly interested in the Slack one.
Thanks !
Since #109 the Swift_Message used for email logging is lazy-loaded. This seems to interact badly with the memory queue strategy, because it clones messages.
It seems only the initial message is properly (lazily) initialized, but the clone is not, so, this might be an error in the lazy load library as well, but I figure I mention it here since this is where I first ran into this effect.
The specific error you'll get is: Fatal error: Uncaught exception 'Swift_TransportException' with message 'Cannot send message without a sender address'
"symfony/symfony": "v2.2.0-RC1",
"symfony/monolog-bundle": "v2.1.7"
or
"symfony/symfony": "v2.2.0-RC1",
"symfony/monolog-bundle": "v2.2.0-BETA1"
result in
PHP Fatal error: Class Symfony\Bridge\Monolog\Logger contains 5 abstract methods and must therefore be declared abstract or implement the remaining methods (Psr\Log\LoggerInterface::emergency, Psr\Log\LoggerInterface::critical, Psr\Log\LoggerInterface::error, ...) in vendor/symfony/symfony/src/Symfony/Bridge/Monolog/Logger.php on line 90
"symfony/symfony": "v2.2.0-RC1",
"symfony/monolog-bundle": "v2.2.0-BETA2"
results in
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for symfony/monolog-bundle v2.2.0-BETA2 -> satisfiable by symfony/monolog-bundle v2.2.0-BETA2.
- symfony/monolog-bundle v2.2.0-BETA2 requires symfony/config >=2.2,<3.0 -> satisfiable by symfony/config 2.2.x-dev, symfony/config 2.3.x-dev.
- don't install symfony/config 2.2.x-dev|don't install symfony/symfony v2.2.0-RC1
- don't install symfony/config 2.3.x-dev|don't install symfony/symfony v2.2.0-RC1
- Installation request for symfony/symfony v2.2.0-RC1 -> satisfiable by symfony/symfony v2.2.0-RC1.
Right now, the client is very hard to customize because of the sha1 on the raven dns,
So I created this code in my application:
<?php
namespace SensioLabs\Bundle\InsightAnalysisBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
/**
* This code may be deprecated one day by
* https://github.com/symfony/MonologBundle/issues/85
*/
class RavenPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('monolog.handler.raven')) {
return;
}
$definition = $container->getDefinition('monolog.handler.raven');
$container->getDefinition($definition->getArgument(0))->setClass('SensioLabs\Shim\Raven\Client');
}
}
Can I submit a PR to "parameterized" a monolog.raven.client.class
?
Thanks
I've creating the following configuration:
monolog:
handlers:
main:
type: fingers_crossed
action_level: critical
handler: nested
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
info:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: info
graylog2:
type: gelf
level: info
publisher:
hostname: %logging_host%
port: 12201
graylog2_ita:
type: gelf
level: info
publisher:
hostname: 151.x.x.x
port: 12201
console:
type: console
The problem is that both messages for graylog2 and graylog2_ita are sent to the last one (duplicated).
I've tried to use also a key "name" inside the handlers and the groupHandler but still they're sent to only one of the servers.
Hi,
normally you add monolog handlers in the config*.yml
files. In my current bundle I want to push my own handler on the top of the stack. I used the PrependExtensionInterface
to configure the handlers. But $container->prependExtensionConfig('monolog', $myHandler);
always create two handlers keys. One contains my definitions, the other the handler definitions from the `config*.yml' file.
I read the docs and found:
If you want to change the config of MonologBundle in another config file you need to redefine the whole stack. It cannot be merged because the order matters and a merge does not allow to control the order.
My bundles monolog handler extends the TestHandler
. I want to collect all messages refers to the bundles webservice communication. The bundle uses that messages to show a user friendly jquery tracelog if something is broken.
Is it possible to add my handler without saying: " _If you want to use my bundle, add the following monolog handler definition to your config_.yml
...* "?
Hi,
I usually use channel filtering in my logging and I just started a new project and noticed that the channels filtering is not working.
Symfony version: ~2.4
Monolog version: 1.10.x-dev (the default for symfony 2.4)
in my config_dev.yml I have this:
monolog:
handlers:
main:
type: group
channels: ["app", "doctrine", "!event"]
members: [streamed, console]
streamed:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
console:
type: console
verbosity_levels:
VERBOSITY_NORMAL: INFO
level: debug
I'm getting "event.DEBUG" and "request.INFO" in my logs, although I've set it to log only app and doctrine stuff and explicitly excluded event.
Did something changed? Am I doing something wrong? Or is this a bug?
Tkx
Cause Symfony 2.3 could catch PHP Fatal errors I'd like to send email notifications when PHP Fatal occurs.
Basically it works well with Monolog bundle and SwiftMailer handler. And currently in my app these emails are sent properly. But I'd like to customize email content to include here a bit more useful information.
What I'm wondering, is here any ability to override core handler class? For example it is impossible to override monolog.handler.swift_mailer.class
(it is need to create separate compiler pass to completely override service definition).
From how I understand it is because handler definitions are built in container extension (just after bundle configuration is processed). From my point it will be more correct to build it in compiler pass.
I could miss something cause I'm looking in MonologBundle source code for first time.
Thanks in advance!
I just upgraded to Symfony 2.4 and Monolog 2.5.0. If you do not use spooling, you receive the following error:
The service "monolog.handler.swift" has a dependency on a non-existent service "swiftmailer.transport.real".
This occurs since the alias never gets created if you do not set the 'spool' value under the Swiftmailer configuration.
In order to "mute" log messages from the "event" channel, I have this configuration in my bundle:
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
channels: [""!event"]
mute:
type: "null"
channels: ["event"]
This is effective, but are there other ways to mute channels? What happens by default with messages that are excluded by any of the handlers? I noticed them popping up in the output of the PHPStorm PHPUnit test runner, but I couldn't find any piece of code in the bundle or the library that could be the cause of this.
Missing handlers:
Using monolog/monolog (25a97a)
(dev-master) for the development purposes with symfony/monolog-bundle @dev
does not fetch psr/log dependency and results in rising exception right after composer update
:
PHP Fatal error: Interface 'Psr\Log\LoggerInterface' not found in
/path/vendor/monolog/monolog/src/Monolog/Logger.php on line 28
Do you have any idea why does it not work properly? Fetching monolog/monolog
and calling composer update
works and psr
is available under vendor
folder.
If we are using several mailers configurations with swiftmailer:
# app/config/config.yml
swiftmailer:
default_mailer: default
mailers:
default:
...
errors:
...
and specifying a non-default mailer in monolog:
# app/config/config_prod.yml
monolog:
handlers:
mail:
type: fingers_crossed
action_level: critical
handler: buffered
buffered:
type: buffer
handler: swift
swift:
type: swift_mailer
# This is the specified mailer service :
mailer: swiftmailer.mailer.errors
from_email: [email protected]
to_email: [email protected]
subject: An Error Occurred!
level: debug
When doing this, the definition of the monolog handler is correct.
But the problem is in the class AddSwiftMailerTransportPass of MonologBundle (current version), this CompilerPass adds the setTransport
method to the handler definition with the default transport. (Here and here)
When using only one mailer, it's working.
When using a non-default mailer in monolog, the mails are not sent because the transport (aka the spool) used is the one of the default mailer.
I made it work but it's not perfect :
<?php
namespace Symfony\Bundle\MonologBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Reference;
class AddSwiftMailerTransportPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$handlers = $container->getParameter('monolog.swift_mailer.handlers');
foreach ($handlers as $id) {
$definition = $container->getDefinition($id);
// This is my current solution
// I'm retrieving the argument n°0 of this monolog handler definition
// (arg n°0 is a reference to the swiftmailer mailer), so when
// calling _toString(), I can retrieve the id of the mailer and use
// it for building the id of the correct transport.
$mailerId = $definition->getArgument(0)->__toString();
if (
$container->hasAlias($mailerId . '.transport.real') ||
$container->hasDefinition($mailerId . '.transport.real')
) {
$definition->addMethodCall(
'setTransport',
array(new Reference($mailerId . '.transport.real'))
);
} elseif (
$container->hasAlias($mailerId . '.transport') ||
$container->hasDefinition($mailerId . '.transport')
) {
$definition->addMethodCall(
'setTransport',
array(new Reference($mailerId . '.transport'))
);
}
}
}
}
What do you think of this solution ?
Does anybody has a better way to fix this bug ?
Monolog and the Monolog-bridge come with some pre-defined processors to use. It would be nice, if one could enable them easily via configuration, like
monolog:
handlers: ~ # define your handlers here (omitted)
processors:
foo:
type: memory_peak_usage
real_usage: true
use_formatting: false
channels: [bar, baz]
bar:
type: psr_log_message
handlers: [mainfile]
monolog:
channels: [grabber]
handlers:
grabber_file:
type: service
id: metal.grabbers.monolog.handler.doctrine_dbal
level: INFO # I cann't get this parameter inside my service
channels: [grabber]
The DebugHandlerPass checks if the profiler is enabled, but I think that this check is incomplete. I'm running a Symfony 2.2 instance and even in production mode the profiler
section is defined in the config, only the profiler.enabled
option is set to false to disable the profiler.
I think that the DebugHandlerPass
class should check if the enabled is set to true and only then add the DebugHandler
. Or is there something I'm missing?
At the moment the channel parameter is taken as-is:
$loggerId = sprintf('monolog.logger.%s', $tag['channel']);
$this->createLogger($tag['channel'], $loggerId, $container);
whereas I find it useful if it was possible to make it a parameter so that you only needed to specify/change it in one place.
Thoughts?
Whey I configure the bundle to use excluded_404s
for a fingers_crossed
handler I get the following error:
RuntimeException in ContainerBuilder.php line 915:
You have requested a synthetic service ("request"). The DIC does not know how to construct this service.
When looking in the code, I think this causes the error (MonologExtension.php line 293-298)
} elseif (!empty($handler['excluded_404s'])) {
$activationDef = new Definition('%monolog.activation_strategy.not_found.class%', array($handler['excluded_404s'], $handler['action_level']));
$activationDef->addMethodCall('setRequest', array(new Reference('request', ContainerInterface::NULL_ON_INVALID_REFERENCE, false)));
$container->setDefinition($handlerId.'.not_found_strategy', $activationDef);
$activation = new Reference($handlerId.'.not_found_strategy');
} else {
I'm using symfony 2.6.7 with monolog-bundle 2.7.1
My guess is that the MonologExtension should use the request stack, but that might not be compatible with older versions of symfony.
Various copyright notices mention a file LICENSE that supposedly is "distributed with this source code". However, I cannot find such file.
Please add this file with appropriate license terms.
I think it would be helpful if the user was allowed to specify the system name (or source) to be used for logging. I use GELF, but would like to use a parameter in my config for the system name not the computers hostname.
After installing Symfony Standard Edition and updating it to 2.3.2
using php composer.phar update
and got the following error when clearing the cache:
[InvalidArgumentException]
Invalid handler type "console" given for handler "console"
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception
just running php app/console
trigger the same error
I've tried to downgrade to 2.3.1
but have the same error.
I believe this is related to this PR: #42
The exact exception I have is the following:
InvalidArgumentException: Invalid handler type "console" given for handler "console"
in /var/www/symfony/vendor/symfony/monolog-bundle/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php line 308
at MonologExtension->buildHandler(object(ContainerBuilder), 'console', array('type' => 'console', 'bubble' => false, 'priority' => '0', 'level' => 'DEBUG', 'path' => '%kernel.logs_dir%/%kernel.environment%.log', 'ident' => false, 'logopts' => '1', 'facility' => 'user', 'max_files' => '0', 'action_level' => 'WARNING', 'activation_strategy' => null, 'stop_buffering' => true, 'buffer_size' => '0', 'title' => null, 'members' => array(), 'to_email' => array(), 'content_type' => null)) in /var/www/symfony/vendor/symfony/monolog-bundle/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php line 51
at MonologExtension->load(array(array('handlers' => array('main' => array('type' => 'stream', 'path' => '/var/www/symfony/app/logs/dev.log', 'level' => 'debug'), 'console' => array('type' => 'console', 'bubble' => false)))), object(ContainerBuilder)) in /var/www/symfony/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php line 50
at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in /var/www/symfony/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/MergeExtensionConfigurationPass.php line 39
at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in /var/www/symfony/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php line 119
at Compiler->compile(object(ContainerBuilder)) in /var/www/symfony/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php line 559
at ContainerBuilder->compile() in /var/www/symfony/app/bootstrap.php.cache line 659
at Kernel->buildContainer() in /var/www/symfony/app/bootstrap.php.cache line 595
at Kernel->initializeContainer() in /var/www/symfony/app/bootstrap.php.cache line 380
at Kernel->boot() in /var/www/symfony/app/bootstrap.php.cache line 411
at Kernel->handle(object(Request)) in /var/www/symfony/web/app_dev.php line 28
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")
I would like to make symfony writes in the file app/logs in prod mode.
To do so, I changed the config of monolog in config_prod.yml
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
nested:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
But, not prod.log file is generated!
Since the log is produced in dev mode, I copied than the monolog config which is available in config_dev.yml to the config_prod.yml. This config is follows:
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
firephp:
type: firephp
level: info
chromephp:
type: chromephp
level: info
But, still no prod.log is written in prod mode.
Is there any idea?
For your information , I am using symfony 2.3.11.
It would be nice if you could configure the SwiftMailerHandler to send emails as HTML. Currently you can send emails only with text/plain.
You could add optional content_type parameter to the configuration, to specify the content type:
swift:
type: swift_mailer
from_email: [email protected]
to_email: [email protected]
subject: An Error Occurred!
content_type: text/html
level: debug
Hi,
I've added Monolog Bundle in my composer like so:
"symfony/monolog-bundle": "~2.4"
But I get these errors:
ContextErrorException: Warning: constant(): Couldn't find constant Monolog\Logger::DEBUG in [path]/symfony/monolog-bundle/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php line 119
Fatal error: Class 'Monolog\Logger' not found in [path]/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/DebugHandlerPass.php on line 42
And I'm also using symfony 2.4.
Defining custom channels for use in controllers right now is impossible since they are created automatically. Having a way to define additional channels from the configuration would be easier to handle. See http://stackoverflow.com/questions/15966140/symfony-2-1-switch-monolog-channel-in-controller
There're no trackable branches for MonologBundle 2.4 and 2.5, even though there are already releases for both branches.
If we decide to keep track of 2.5.X series, we are forced to track dev-master, which will likely result into future changes easily since this is being used as latest development efforts.
@Seldaek The 2.3.1 tag have been made on the master branch instead of the 2.3 branch.
Now when installing symfony 2.3.1 monolog-bundle require monolog-brige >=2.4-dev
Problem 1
- Installation request for symfony/monolog-bundle 2.3.1 -> satisfiable by symfony/monolog-bundle[v2.3.1].
- symfony/monolog-bundle v2.3.1 requires symfony/monolog-bridge >=2.4-dev,<3.0 -> no matching package found.
Hi,
I use monologBundle to log into GrayLog2. So I use GelfHandler and GelfMessageFormatter given by monolog. It work very well but I encoutered a limitation.
In GrayLog, it's possible to send extra additional fields
In GelfMessageFormatter.php
foreach ($record['extra'] as $key => $val) { $message->setAdditional($this->extraPrefix . $key, is_scalar($val) ? $val : $this->toJson($val)); }
But in Monolog/Logger addRecord function the extra field is set to array().
$record = array( 'message' => (string) $message, 'context' => $context, 'level' => $level, 'level_name' => static::getLevelName($level), 'channel' => $this->name, 'datetime' => \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), static::$timezone)->setTimezone(static::$timezone), 'extra' => array(), );
So I can't send extra field to GrayLog.
Do you have a solution or can you fix this ?
Hi,
since Monolog-Bundle switched to PSR-4 we get this error in our symfony 2.5 app:
*32004 FastCGI sent in stderr: "PHP message: PHP Warning: require(/src/vendor/symfony/monolog-bundle/Symfony/Bundle/MonologBundle/MonologBundle.php): failed to open stream: No such file or directory in /src/app/bootstrap.php.cache on line 2683
vendors are installed with php composer.phar install --no-dev --optimize-autoloader
composer.json entry:
"symfony/monolog-bundle": "~2.4"
Hi.
The channel for logger not activate, if i use DefinitionDecorator instance for create service.
As example:
<service id="api.subscriber.logger_abstract" class="%api.subscriber.logger.class%" abstract="true" public="false">
<argument type="service" id="logger" />
</service>
And after i create a DefinitionDecorator and add monolog.logger tag for this service and inject to container.
$subscriberDefinition = new DefinitionDecorator('api.subscriber.logger_abstract');
$subscriberDefinition->addTag('monolog.logger', [
'channel' => $this->getLoggerChannelForHandler($handlerKey)
]);
$container->setDefinition($subscriberId, $subscriberDefinition);
The problem in DefinitionDecorator, because here not have a arguments. Argument and another definition options will be processed on ResolveDefinitionTemplatesPass
(Optimization layer on compiler pass).
Maybe add LoggerChannelPass to optimization layer on CompilerPass?:
$container->addCompilerPass($channelPass = new LoggerChannelPass(), PassConfig::TYPE_OPTIMIZE);
$container->addCompilerPass(new DebugHandlerPass($channelPass), PassConfig::TYPE_OPTIMIZE);
Thank.
I should be able to config the format of monolog simply, to be able to output for example class and method. This works, in that it does make the format as described int he arguments:
services:
my_log_formatter:
class: Monolog\Formatter\LineFormatter
arguments: ["[%%datetime%%] %%channel%%.%%level_name%%: %%message%% %%context%% %%extra%%\n"]
monolog:
handlers:
file:
type: stream
level: debug
formatter: my_log_formatter
...but trying to add %O (class) or %M (method) to the arguments, which are supported by Monolog, does not configure the logger format.
I have a long running console command for testing:
protected function execute(InputInterface $input, OutputInterface $output)
{
$container = $this->getContainer();
$logger = $container->get('logger');
$lim = 5000;
$count = 0;
while (true){
$count++;
$logger->debug("line one");
$logger->debug("line two");
$logger->debug("line three");
#var_export($logger);
if ($count >= $lim){
break;
}
}
}
and my prod config looks like this:
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
buffer_size: 30
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
The elements in the buffer do not exceed the limit, but the overall memory usage of the process is still increasing with every iteration.
If I let the process run for a few minutes it gets over 1gb and i have no idea where the memory increase comes from.
I also did some profiling with xdebug but it doesn't help too much:
function #calls time memory time memory
----------------------------------------------------------------------------------------------------------------------------------------
Monolog\Logger->addRecord 15000 19.2248 -2024304 6.6741 12480632
Composer\Autoload\includeFile 245 0.6489 7826512 0.2820 5104360
sprintf 15002 1.0057 3840680 1.0057 3840680
Monolog\Logger->debug 15000 21.0143 736080 1.7896 2760384
Symfony\Component\HttpKernel\Kernel->initializeContainer 1 0.0147 1717064 0.0099 1478920
DateTime::createFromFormat 15000 1.1265 960000 1.1265 960000
Monolog\Handler\FingersCrossedHandler->isHandling 15000 0.9998 720000 0.9998 720000
Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy->isHandlerActivated 15000 1.0250 720000 1.0250 720000
include 245 0.3669 2722152 0.0159 509520
FilesystemIterator->current 85 0.0058 383728 0.0058 383728
Symfony\Component\Finder\Expression\Regex::create 30 0.0296 380840 0.0105 351632
appProdProjectContainer->getDefaultParameters 1 0.0002 179504 0.0002 179504
composerRequireee80ec58e11a2d87b2e216687850288a 8 0.0186 288168 0.0125 162928
Symfony\Component\Finder\Adapter\PhpAdapter->searchInDirectory 15 0.1565 348440 0.0056 76840
ComposerAutoloaderInitee80ec58e11a2d87b2e216687850288a::loadClassLoader 1 0.0011 63872 0.0010 63824
appProdProjectContainer->__construct 1 0.0008 237344 0.0003 57712
strtr 639 0.0421 41256 0.0421 41256
substr 765 0.0475 33600 0.0475 33600
Symfony\Component\Finder\Finder->addAdapter 45 0.0242 34840 0.0075 31240
explode 88 0.0053 30936 0.0053 30936
Symfony\Component\Finder\Finder->Symfony\Component\Finder\{closure} 135 0.0089 29928 0.0089 29928
Composer\Autoload\ClassLoader->set 53 0.0038 29928 0.0038 29928
require_once 5 0.0477 719696 0.0009 29080
FilterIterator->key 248 0.0200 27688 0.0200 27688
stream_get_meta_data 17 0.0010 24752 0.0010 24752
Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator->__construct 15 0.0172 29520 0.0082 23280
ReflectionClass->getConstructor 74 0.0047 23096 0.0047 23096
str_replace 113 0.0070 22448 0.0070 22448
Symfony\Component\Console\Input\InputDefinition->setArguments 109 0.0405 32168 0.0159 22328
Symfony\Component\Console\Input\InputDefinition->setOptions 108 0.0707 37224 0.0120 21552
ReflectionClass->__construct 82 0.4401 3963992 0.0088 21024
preg_match 1061 0.0719 20400 0.0719 20400
Symfony\Component\Console\Input\InputOption->isArray 412 0.0253 19776 0.0253 19776
array_merge 32 0.0019 19712 0.0019 19712
Symfony\Component\Console\Application->add 76 0.1666 504288 0.0231 19584
Symfony\Component\Console\Command\Command->__construct 76 0.5897 560088 0.0121 19112
ReflectionClass->newInstance 74 0.5825 572240 0.0080 19056
RecursiveDirectoryIterator->hasChildren 85 0.0574 18216 0.0574 18216
SplFileInfo->__construct 85 0.0065 16528 0.0065 16528
Symfony\Component\Finder\Finder->__construct 15 0.0938 349816 0.0089 16208
Any help would be much appreciated,
Tibor
symfony/symfony#11448 fixes 227bbee for everyone so it's best to go back to the subscriber.
A simple class that avoids triggering the FingersCrossedHandler on 404 errors would be nice. It should still trigger on other 4xx though. This should be made optional I suppose, unless everyone agrees it's a better default. /cc @stof @schmittjoh @fabpot
I'm trying to use excluded_404s with rotating_file
monolog:
. . . . handlers:
. . . . . . . . main:
. . . . . . . . . . . . type: rotating_file
. . . . . . . . . . . . action_level: ERROR
. . . . . . . . . . . . path: "%kernel.logs_dir%/%kernel.environment%.log"
. . . . . . . . . . . . max_files: 10
. . . . . . . . . . . . handler: grouped
. . . . . . . . . . . . excluded_404s:
. . . . . . . . . . . . . . . . - ^/*
. . . . . . . . . . . . channels: !doctrine
I still got NotFoundHttpException in my logs, what did I miss ?
When storing message in file it will be serialized with class name like Swift_Message_000000003b027a18000000005cb90b1f
. After container rebuild this name will change. So if cache was cleared after message stored but before swiftmailer:spool:send
command executed there will be error Catchable Fatal Error: Argument 1 passed to Swift_Transport_MailTransport::send() must implement interface Swift_Mime_Message, instance of __PHP_Incomplete_Class given
.
This is a rare but troublesome case.
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.