Symfony2 - Logging not working on Production

Active3 hr before
Viewed126 times

9 Answers


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):,The ./logs/prod.log is being writing properly by Symfony. But when I try to write something by myself, it just ignores me.,Everything works well in local. But when moving to production environment, there are some things that don't work the same as local., Thank you for your response. As I said, Symfony engine is writing properly in the file. I can even see the CRITICAL error specified in it. The problem comes when I try to write something by myself using the container logger. – ElPiter Nov 18 '12 at 11:11

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);
load more v

To log a message, inject the default logger in your controller or service:, How to Rotate your Log Files , Handlers: Writing Logs to different Locations Handlers that Modify Log Entries ,Symfony integrates seamlessly with Monolog, the most popular PHP logging library, to create and store log messages in a variety of different places and trigger various actions.

use Psr\ Log\ LoggerInterface;

function index(LoggerInterface $logger) {
   $logger - > info('I just got the logger');
   $logger - > error('An error occurred');

   $logger - > critical('I left the oven on!', [
      // include extra "context" info in your logs
      'cause' => 'in_hurry',

   // ...
load more v

I have a problem, just finished my app, switched to prod mode, but it's not creating prod.log. Created it manually, but it's not updating.,If I change the action_error to debug, it will create the file (prod.log), but log only info, not criticals. If I load webprofiler bundle for prod (don't really want to do this), even if i don't activate the profiler the prod logging works... Anyone else stumble upon this?,With the default configuration (fingers_crossed handler) the file is created / updated only when a log with a level > error occurs. That's why you did not get the file.,I have a similar issue for symfony/monolog-bundle v3.3.1. The renaming/appending of the file does not work either.

APP_ENV = prod
APP_DEBUG = 1 #also tried 0
load more v

The simplest way of logging in Symfony,Finally, it returns the content of the API response.,That’s why in this post, you’ll learn more about logging, why you’d do it, and how to log using the Symfony framework., Logging Best Practices: The 13 You Should Know

You’ll also want to have Composer installed. Composer is a package manager for PHP. You can install it by following their official documentation. From the command line, run the code below to install Symfony client.

curl - sS https: // | bash
load more v

Full Example Configuration,Pre-canned Configurations,For more information, see the nginx+php-cgi security alert,Installing & Configuring NGINX

load more v

For Symfony to know it needs to use the prod environment at all times, it reads from the APP_ENV environment variable. You can set environment variables using the heroku config feature. Running following command will set a configuration variable that lets Symfony to know to run in production mode:,You are now almost ready to deploy the application. Follow the next section to ensure your Symfony app runs with the settings for the right environment.,It is likely that you have to set additional environment variables, enable logging, and so forth, for your application to be functional, so follow the next steps to finalize your deployment.,Using config vars to define environment specific info such as database credentials, log levels, or e-mail gateway information is one of the fundamental principles of the Twelve-Factor App.

After it’s done, Composer has set up a fully functional Symfony website project in the directory you specified, so you can cd to it.

$ composer create - project symfony / website - skeleton symfony - heroku /
   Installing symfony / website - skeleton(v4 .3 .1 .4) -
   Installing symfony / website - skeleton(v4 .3 .1 .4): Downloading(100 % )

Created project in symfony - heroku /
   Loading composer repositories with package information
Installing dependencies(including require - dev) from lock file…

$ cd symfony - heroku
load more v

E_ERROR – These are fatal run-time errors that halt script execution, such as running out of memory or calling a function that does not exist.,E_WARNING – A run-time warning is an error that does not halt script execution but can cause your code to not work as expected. For example, fopen() will return false and trigger an E_WARNING if you try to open a file that does not exist. The rest of your code won’t be able to read or write to the requested file.,If you’re trying to fix a bug but don’t see any errors, search your code for function calls prefixed with one @. You can also install and enable the scream extension which disables this behavior and ensures all errors are reported.,E_STRICT – These errors indicate places in your code that may stop working in future versions of PHP. Using mysql_query() will trigger a strict error because the extension that provides that function is deprecated, and in fact is not bundled in PHP 7.

Retrieves current directive setting.

$displayErrors = ini_get(‘display_errors’);

$errorLogPath = ini_get(‘error_log’);
load more v

Meanwhile, when you are working in a production mode, you must create a smooth workflow to enable PHP error logging, so that the users should not face any glitch during runtime execution.,You can do the whole work of error logging manually, but when you are working in multiple teams and larger projects, you must set up an automated workflow that can log errors in third-party services like Sentry, Slack, Blackfire, etc.,The most important thing is that when you should log errors and how you should do it? When you are working in the dev mode, you can log PHP errors at your will. Either create a PHP error log file or save them as notifications on different channels, you always get the convenience to log errors as per your requirements. ,The above-defined practices work fittingly well when you are working in the dev environment. But, when you take your website live and start working in the production mode, you must hide the errors from the on-screen display and log them within a backend file. You can save these at a specific PHP error logs location whose URL is already described in the php.ini file.

Let’s suppose you are connecting MySQL database with PHP and if it fails to connect with it, you can log errors in PHP like this:

< ? php

// Send error message to the server log if error connecting to the database

if (!mysqli_connect("localhost", "bad_user", "bad_password", "my_db")) {

   error_log("Failed to connect to database!", 0);


// Send email to administrator if we run out of FOO

if (!($foo = allocate_new_foo())) {

   error_log("Oh no! We are out of FOOs!", 1, "[email protected]");


load more v

The Symfony framework used in AtoM includes a number of logging options which can be customized based on developer or system administrator needs.,The Symfony documentation also has suggestions on rotating your logs, for better performance:,You might want to log high-level errors from your production environment, to be able to troubleshoot problems encountered. Logging can impact the performance of your site, so you wouldn’t want to set your production environment to log at DEBUG level - but there may be situations where you want to log WARNING and higher messages to your log.,Logging Example 1: Add a cli factory for increased logging Example 2: Enable high-level logging on production

less log / qubit_cli.log
load more v

Other "working-undefined" queries related to "Symfony2 - Logging not working on Production"