Could you suggest how to print any debug data into browser console in Symfony 2?
Especially, is it possible to implement with Symfony VarDumper Component?
In Zend Framework you can use tool Zend_Log_Writer_Firebug to do so which is very helpful. Does Symfony has something like this from the box?
Monolog, the logger used by Symfony, has a built-in support for FirePHP and ChromePHP.
In Symfony Standard Edition you can configure monolog handlers in your application configuration.
FirePHP and ChromePHP handlers are even present in config_dev.yml, but are commented out:
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
All you need to do to see your logs in the browser is to uncomment the needed handler.
Currently, the VarDumper component doesn't support dumping anything to the browser's console. However, you can see the dumped values in the web debug toolbar (or in html if you don't use the toolbar).
Related
datadog.conf
log_level: warn
log_file: /var/log/datadog/agent.log
log_to_syslog: no
dd_url: https://app.datadoghq.com
api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
process_config:
enabled: "true"
logs_enabled: true
tags:
- env:stage
- nginx
- webserver
- frontend
- php-fpm
- php
use_dogstatsd: true
dogstatsd_port: 8125
I needed to enable flag logs_enabled: true in order to collect PHP logs but with this, I also collect Nginx logs (access and error logs)
If logs_enabled is set to false then I do not collect even PHP logs.
How can I exclude Nginx logs from being collected?
# php.d/conf.yaml
init_config:
instances:
logs:
- type: file
path: "/var/www/{{ env }}/var/log/app-log.json"
service: php
source: php
sourcecategory: sourcecode
The solution was very simple.
Data dog agent configuration is related to enabling/disabling collecting logs from a webserver.
In order to turn off/on specific service logging, it must be done from the DataDog webservice.
Visit the next URL https://app.datadoghq.com/logs/pipelines/indexes
And then add the exclusion rule.
Simple as that :)
I got an error 500 on production env so I spent a lot of time to search where error was displaying. I found that symfony log errors using logger who send output to stderr by default so apache's error log is used in my case. I want to send messages to symfony's env.log (e.g var/log/dev.log and var/log/prod.log)
Documentation says :
The minimum log level, the default output and the log format can also be changed by passing the appropriate arguments to the constructor of Logger. To do so, override the "logger" service definition.
But I can't figure out how I can change logger's output, for testing purpose I changed logger construct in vendor/symfony/http-kernel/Log/Logger.php as following with success:
public function __construct(string $minLevel = null, $output = 'abspath/to/project/var/log/dev.log', callable $formatter = null)
but I can't edit files in vendor dir.
So How I can override the "logger" service definition ?
Do not edit the vendor files. Those are included by composer, and overwriten on each install/update.
If you want to change the log path you can do this with using monolog and config
composer require symfony/monolog-bundle
monolog:
handlers:
# this "file_log" key could be anything
file_log:
type: stream
# log to var/log/(environment).log
path: "%kernel.logs_dir%/%kernel.environment%.log" #change path here
# log *all* messages (debug is lowest level)
level: debug
syslog_handler:
type: syslog
# log error-level messages and higher
level: error
coming from Java development, I learned to appreciate LogLevel, how to set it in Logback or Log4j.
Monolog is used in my symphony 4.2 project.
I would like to see that from a certain controller/namespace the log entries with level info can also be seen in the production log file without all the other log entries with the info level filling the log file.
Unfortunately I didn't find any explanations.
After a little more research, I configured my monolog.yaml for dev and also prod this way
monolog:
channels: ['appinfo']
handlers:
custom:
channels: ['appinfo']
level: info
max_files: 30
path: "%kernel.logs_dir%/appinfo.log"
type: rotating_file
The important thing is the channel, appinfo in my case.
The handler, custom in my case, can be named any way you like.
Then in the services.yaml one has to define the "type" of the injected logger.
App\Controller\DefaultController:
arguments:
$logger: '#monolog.logger.appinfo'
This works with controllers as with services
I recently discovered that my profiler is not working. Every time I try to open the profiler from /app_dev.php/_profiler/empty/search/results?ip=&limit=10 I get this empty profiler page:
With default and customc onfiguration. Here the custom one:
framework:
profiler:
dsn: 'file:/tmp/symfony-profiler'
And here a more precise configuration:
framework:
profiler:
dsn: "file:%kernel.root_dir%/../var/cache/%kernel.environment%/profiler"
No calls are stored in theprofiler. No log keep trace of what happens under the carpet.
Symfony needs the same file permissions to write the profiling data as it would for logs or the cache. Does Symfony write the files if the DSN is left at the default which would write them into var/cache/dev/profiler (or app/var with an older version).
It's also possible that the profiler service has been overridden, which can be checked with bin/console debug:container profiler and other such tools.
I have a Symfony2 web application.
Everything works well in local. But when moving to production environment, there are some things that don't work the same as local.
Now, to figure out what is going on on Production I am trying to write some logs.
For some reason, I am not getting to write anything to the production log. Could anyone tell me what I am doing wrong? This is my code in the Controller in (nothing too sophisticated, by the way):
$logger = $this -> get("logger");
$logger -> err("My Trace --> " . $my_inspect_variable);
The ./logs/prod.log is being writing properly by Symfony. But when I try to write something by myself, it just ignores me.
My config_prod.yml file:
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
nested:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug