Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8845771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:48:47+00:00 2026-06-14T11:48:47+00:00

I have started learning Symfony2 and currently I am dealing with a command that

  • 0

I have started learning Symfony2 and currently I am dealing with a command that I want to log separately.

My goal is to use a custom logger and get a clean log file for my command.
I work on a project that uses xml configuration files but I don’t get how to translate some .yml parameters and options.

I have read How to write logs from one service into separate file? and got a working separate log file.

<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

    <services>
        <service id="myproject_mycommand.logger" class="Symfony\Bridge\Monolog\Logger">
            <argument>myproject_mycommand.logger</argument>
            <call method="pushHandler">
                <argument type="service" id="myproject_mycommand.logger_handler" />
            </call>
        </service>

        <service id="myproject_mycommand.logger_handler" class="Monolog\Handler\StreamHandler">
            <argument>%kernel.logs_dir%/my_custom_file_log.log</argument>
        </service>
    </services>
</container>

After looking Symfony2 : use Processors while logging in different files I’m trying to pass only my desired fields to the monolog line formatter, something like “[%%datetime%%] %%message%%\n”

I guess that I would have to add something like:

container
...
    xmlns:monolog="http://symfony.com/schema/dic/monolog"
... 

and

<service id="myproject_mycommand.logger.formatter" class="Monolog\Formatter\LineFormatter">
    <argument>"[%%datetime%%] %%message%%\n"</argument>
</service>

but I don’t get how to configure this simple formatter in the xml file.

Thanks for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:48:48+00:00Added an answer on June 14, 2026 at 11:48 am

    You need to create your formatter and extend it from FormatterInterface and implement format and formatBatch.

    Then add service definition

    <service id="myproject_mycommand.logger.formatter" class="MyBundle\Formatter\XmlFormatter">
        <argument>some arguments if you need one</argument>
    </service>
    
    <service id="myproject_mycommand.logger_handler" class="Monolog\Handler\StreamHandler">
        <argument>%kernel.logs_dir%/my_custom_file_log.log</argument>
        <call method="setFormatter">
            <argument type="service" id="myproject_mycommand.logger.formatter"/>
        </call>    
    </service>
    

    That’s about it. For idea of how to format you can check examples of different formatters inside monolog bundle sources.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have started learning python and want to use it to do something
Recently I have started learning rails and was a little surprised that the default
I have started learning Canvas in HTML5 and I have a question. I want
I have started learning Excel more recently. I am learnng to use Excel Formulas.
I have started learning Objective-C, and I just wanted to verify that my understanding
I have started learning Java and am having problem with a simple program that
I have recently started learning Fortran for the fun of it, and I want
I have started learning TCL scripting language. I use ActivateState Tcl Devkit 5.3.0. When
I have just started learning PHP and I want to create a website with
I have started learning Java and I have 1 issue: I write a simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.