I have a weird issue, when I checked my app/log/dev.log I can see almost all of my queries in my dev.log being logged in real time:
[2015-01-27 06:57:22] doctrine.DEBUG: SELECT t0.username A ....
[2015-01-27 06:57:23] doctrine.DEBUG: SELECT t0.username A ...
[2015-01-27 06:57:23] doctrine.DEBUG: SELECT s0_.id ......
I have no idea why this is happening, since I am running the site on production mode also when I check monolog in my config.yml, this is what I see:
monolog:
handlers:
pictures:
type: stream
path: %kernel.logs_dir%/pictures_%kernel.environment%.log
level: info
instagram:
type: stream
path: %kernel.logs_dir%/instagram_%kernel.environment%.log
level: info
here's what my config_dev.yml looks like:
imports:
- { resource: config.yml }
framework:
router: { resource: "%kernel.root_dir%/config/routing_dev.yml" }
profiler: { only_exceptions: false }
web_profiler:
toolbar: true
intercept_redirects: false
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
firephp:
type: firephp
level: info
assetic:
use_controller: false
hip_mandrill:
disable_delivery: true
any idea how this could be happening?
You should use prod env on your production server. In the prod env doctrine's logging is disabled by default.
But if you want to disable logging at all (in all environments) you need to set up a config.yml like that:
doctrine:
dbal:
connections:
conn1:
driver: ...
...
logging: false
profiling: false
Reference: https://symfony.com/doc/current/bundles/DoctrineBundle/configuration.html
I encountered a similar issue with dev.log being generated on prod environment. I figured out from the log entries that what was causing my issue was a scheduled cron job calling a custom symfony command. Modifying the entry to app/console with --env=prod for my crontab since stopped dev.log being generated. i.e.
app/console --env=prod custom:command
Must have missed that section of the book :)
As I struggled with the same problem and my .log file was increasing its size the straight solution was when running the consumer use the flag --no-debug
php bin/console messenger:consume async_email_handler --no-debug
Related
I am new to Symfony 5.3 and Monolog. The docu explains "the Symfony Framework organizes log messages into channels. By default, there are several channels, including doctrine, event, security, request and more."
Is there any way to find out what channels exactly are configured?
I tried to run php bin/console debug:config monolog but this only shows the channels I configured (e.g. by adding channels: ['myChannelA', 'channelB'] to the monolog.yaml)
I made no changes (beside adding custom channels, see above) to the default monolog config which was created on install:
// config/packages/dev/monolog.yaml
monolog:
channels: ['myChannelA','channelB']
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: ["!event"]
# uncomment to get logging in your browser
# you may have to allow bigger header sizes in your Web server configuration
#firephp:
# type: firephp
# level: info
#chromephp:
# type: chromephp
# level: info
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine", "!console"]
// config/packages/prod/monolog.yaml
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
excluded_http_codes: [404, 405]
buffer_size: 50 # How many messages should be saved? Prevent memory leaks
nested:
type: stream
path: php://stderr
level: debug
formatter: monolog.formatter.json
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine"]
You can try the following command:
php bin/console debug:autowiring | grep monolog
I am working on a web app built using Symfony 2.6 and there are different configuration inside app/config folder. How do I know which one is being used.
Inside app/config I see config.yml config_dev.yml config_prod.yml and the monolog entry I see in config_dev.yml and also in monolog_prod.yml. It is as below.
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
console:
type: console
Now I want to use monolog to input some logs in a controller and put those logs separate form other logs. How can this be done?.
You know which one is used on your environment.
If you are in dev mode you are using config_dev.yml merged with config.yml
You can check it into your virtual host if the file is on app.php you are in prod mode, if the file points to app_dev.php you are in dev mode usually
To log into other files you can create a channel like this:
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
your_handler:
level: debug
type: stream
path: '%kernel.logs_dir%/custom.log'
channels: ['your_channel']
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
console:
type: console
And into your controller you can call it in this way:
$logger = $this->get('monolog.logger.your_handler');
$logger->debug('your custom message into your custom log file');
I have a Symfony instance running on Linux with apache y NGINX. I'am starting the project using the built-in server:start command:
php bin/console server:start
Back to my browser, it loads me the Symfony start page but it also shows me the debug bar.
I have checked the config_dev.yml file and I think it is correct:
imports:
- { resource: config.yml }
framework:
router:
resource: '%kernel.project_dir%/app/config/routing_dev.yml'
strict_requirements: true
profiler: { only_exceptions: false }
web_profiler:
toolbar: true
intercept_redirects: false
However, if I try to access another route that I don't have, the debug bar is also shown:
You can access the prod env with:
http://127.0.0.1:8000/app.php
And accessing http://127.0.0.1:8000/app.php/a will give you an error page without the debug bar.
It is designed like this because the Symfony built-in web server is only meant to be used in development not in production. So the default environment is the "dev" one.
i want the log to behave like the regular php-log in production.
There is a logrotate in place and the server-logs are analyzed with other tools.
So i set up my config_prod.yml like that:
monolog:
use_microseconds: false
handlers:
main:
type: error_log
level: WARNING
deduplicated:
type: deduplication
time: 60
handler: main
Somehow the deprecations (via #trigger_error) appear in my log, too.
Can i disable the logging of the deprecations somehow?
I don't need them in prod but only in dev.
Kind regards.
Patrick
You can try to exclude a channel php from your handler
use_microseconds: false
handlers:
main:
type: error_log
level: WARNING
deduplicated:
type: deduplication
time: 60
handler: main
channels: ['!php']
I just follow this tutorial. I created a new controller but my web debug toolbar doesn't show up. I accessed it via app_dev.php file, like , myurl/web/app_dev/contact/ even if i access my url without the contact the web debug toolbar doesn't show up.
This is my config_dev.yml file:
imports:
- { resource: config.yml }
framework:
router:
resource: "%kernel.root_dir%/config/routing_dev.yml"
strict_requirements: true
profiler: { only_exceptions: false }
web_profiler:
toolbar: true
intercept_redirects: false
monolog:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: [!event]
console:
type: console
channels: [!event, !doctrine]
# uncomment to get logging in your browser
# you may have to allow bigger header sizes in your Web server configuration
#firephp:
# type: firephp
# level: info
#chromephp:
# type: chromephp
# level: info
#swiftmailer:
# delivery_address: me#example.com
Do i need to do some extra settings ? I'm totally lost. Thx in advance.
Double check that you are actually accessing app_dev.php. For example try renaming app_dev.php to a new name 'app_dev_temp.php', then try reloading the page. If you can still access the page you are not where you think you are.
Also check your .htaccess file, if you are using a real server instead of the Symfony built in server, by default the htaccess will direct you to the app.php, not the dev version.