What is “channel” in Monologger?












0















I am trying to learn monolog and I am following this tutorial: https://stackify.com/php-monolog-tutorial/



It says




First, when you create a logger, channel name should be included, so that you can distinguish your list of loggers.



$logger = new MonologLogger('channel-name');
$app->container->logger = $logger;



In the example above, ‘channel-name’ should be included in every log entry. This way you can easily look up and filter the entries; create another channel for each component. Examples of these channels might include ‘database’, ‘security’, ’business’, and others.




So what exactly are channels and how should I use them?










share|improve this question

























  • symfony.com/doc/current/logging/channels_handlers.html

    – ggdx
    Nov 27 '18 at 13:30
















0















I am trying to learn monolog and I am following this tutorial: https://stackify.com/php-monolog-tutorial/



It says




First, when you create a logger, channel name should be included, so that you can distinguish your list of loggers.



$logger = new MonologLogger('channel-name');
$app->container->logger = $logger;



In the example above, ‘channel-name’ should be included in every log entry. This way you can easily look up and filter the entries; create another channel for each component. Examples of these channels might include ‘database’, ‘security’, ’business’, and others.




So what exactly are channels and how should I use them?










share|improve this question

























  • symfony.com/doc/current/logging/channels_handlers.html

    – ggdx
    Nov 27 '18 at 13:30














0












0








0








I am trying to learn monolog and I am following this tutorial: https://stackify.com/php-monolog-tutorial/



It says




First, when you create a logger, channel name should be included, so that you can distinguish your list of loggers.



$logger = new MonologLogger('channel-name');
$app->container->logger = $logger;



In the example above, ‘channel-name’ should be included in every log entry. This way you can easily look up and filter the entries; create another channel for each component. Examples of these channels might include ‘database’, ‘security’, ’business’, and others.




So what exactly are channels and how should I use them?










share|improve this question
















I am trying to learn monolog and I am following this tutorial: https://stackify.com/php-monolog-tutorial/



It says




First, when you create a logger, channel name should be included, so that you can distinguish your list of loggers.



$logger = new MonologLogger('channel-name');
$app->container->logger = $logger;



In the example above, ‘channel-name’ should be included in every log entry. This way you can easily look up and filter the entries; create another channel for each component. Examples of these channels might include ‘database’, ‘security’, ’business’, and others.




So what exactly are channels and how should I use them?







php monolog






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 '18 at 14:28









user6437700

6919




6919










asked Nov 27 '18 at 13:28









annetekaanneteka

44




44













  • symfony.com/doc/current/logging/channels_handlers.html

    – ggdx
    Nov 27 '18 at 13:30



















  • symfony.com/doc/current/logging/channels_handlers.html

    – ggdx
    Nov 27 '18 at 13:30

















symfony.com/doc/current/logging/channels_handlers.html

– ggdx
Nov 27 '18 at 13:30





symfony.com/doc/current/logging/channels_handlers.html

– ggdx
Nov 27 '18 at 13:30












2 Answers
2






active

oldest

votes


















1














The "channel" here is not a generic PHP concept, it's just a term that monolog uses for a category of messages which you want to log.



From the monolog usage documentation:




You can create many Loggers, each defining a channel (e.g.: db, request, router, ..) and each of them combining various handlers, which can be shared or not. The channel is reflected in the logs and allows you to easily see or filter records.




Further down that page, there is another section on using channels:




Channels are a great way to identify to which part of the application a record is related. This is useful in big applications (and is leveraged by MonologBundle in Symfony).



Picture two loggers sharing a handler that writes to a single log file. Channels would allow you to identify the logger that issued every record. You can easily grep through the log files filtering this or that channel.







share|improve this answer































    1














    In simple words, you can define a channel as a separate log file.



    Generally you might need to classify your log files for different services or modules.



    For this purpose, Monolog allows you to create different channels, where each can log separately to different file and allow you to configure your log per channel.



    In the line you are referring to



     $logger = new MonologLogger('channel-name'); 
    $app->container->logger = $logger;


    You are specifying the channel in the constructor of Monologger.



    Anytime you use this $logger object it will be writing to the file you specified when you configured the channel. Below is an example from the Symfony docs for a channel config



    https://symfony.com/doc/current/logging/channels_handlers.html#switching-a-channel-to-a-different-handler



       monolog:
    handlers:
    security:
    # log all messages (since debug is the lowest level)
    level: debug
    type: stream
    path: '%kernel.logs_dir%/security.log'
    channels: [security]


    In which case you would do that in your code to use the channel



     $logger = new MonologLogger('security');


    And then you will be logging to "security.log" with type "stream" errors of level "debug".






    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53500818%2fwhat-is-channel-in-monologger%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      The "channel" here is not a generic PHP concept, it's just a term that monolog uses for a category of messages which you want to log.



      From the monolog usage documentation:




      You can create many Loggers, each defining a channel (e.g.: db, request, router, ..) and each of them combining various handlers, which can be shared or not. The channel is reflected in the logs and allows you to easily see or filter records.




      Further down that page, there is another section on using channels:




      Channels are a great way to identify to which part of the application a record is related. This is useful in big applications (and is leveraged by MonologBundle in Symfony).



      Picture two loggers sharing a handler that writes to a single log file. Channels would allow you to identify the logger that issued every record. You can easily grep through the log files filtering this or that channel.







      share|improve this answer




























        1














        The "channel" here is not a generic PHP concept, it's just a term that monolog uses for a category of messages which you want to log.



        From the monolog usage documentation:




        You can create many Loggers, each defining a channel (e.g.: db, request, router, ..) and each of them combining various handlers, which can be shared or not. The channel is reflected in the logs and allows you to easily see or filter records.




        Further down that page, there is another section on using channels:




        Channels are a great way to identify to which part of the application a record is related. This is useful in big applications (and is leveraged by MonologBundle in Symfony).



        Picture two loggers sharing a handler that writes to a single log file. Channels would allow you to identify the logger that issued every record. You can easily grep through the log files filtering this or that channel.







        share|improve this answer


























          1












          1








          1







          The "channel" here is not a generic PHP concept, it's just a term that monolog uses for a category of messages which you want to log.



          From the monolog usage documentation:




          You can create many Loggers, each defining a channel (e.g.: db, request, router, ..) and each of them combining various handlers, which can be shared or not. The channel is reflected in the logs and allows you to easily see or filter records.




          Further down that page, there is another section on using channels:




          Channels are a great way to identify to which part of the application a record is related. This is useful in big applications (and is leveraged by MonologBundle in Symfony).



          Picture two loggers sharing a handler that writes to a single log file. Channels would allow you to identify the logger that issued every record. You can easily grep through the log files filtering this or that channel.







          share|improve this answer













          The "channel" here is not a generic PHP concept, it's just a term that monolog uses for a category of messages which you want to log.



          From the monolog usage documentation:




          You can create many Loggers, each defining a channel (e.g.: db, request, router, ..) and each of them combining various handlers, which can be shared or not. The channel is reflected in the logs and allows you to easily see or filter records.




          Further down that page, there is another section on using channels:




          Channels are a great way to identify to which part of the application a record is related. This is useful in big applications (and is leveraged by MonologBundle in Symfony).



          Picture two loggers sharing a handler that writes to a single log file. Channels would allow you to identify the logger that issued every record. You can easily grep through the log files filtering this or that channel.








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 27 '18 at 13:35









          IMSoPIMSoP

          47.3k65794




          47.3k65794

























              1














              In simple words, you can define a channel as a separate log file.



              Generally you might need to classify your log files for different services or modules.



              For this purpose, Monolog allows you to create different channels, where each can log separately to different file and allow you to configure your log per channel.



              In the line you are referring to



               $logger = new MonologLogger('channel-name'); 
              $app->container->logger = $logger;


              You are specifying the channel in the constructor of Monologger.



              Anytime you use this $logger object it will be writing to the file you specified when you configured the channel. Below is an example from the Symfony docs for a channel config



              https://symfony.com/doc/current/logging/channels_handlers.html#switching-a-channel-to-a-different-handler



                 monolog:
              handlers:
              security:
              # log all messages (since debug is the lowest level)
              level: debug
              type: stream
              path: '%kernel.logs_dir%/security.log'
              channels: [security]


              In which case you would do that in your code to use the channel



               $logger = new MonologLogger('security');


              And then you will be logging to "security.log" with type "stream" errors of level "debug".






              share|improve this answer






























                1














                In simple words, you can define a channel as a separate log file.



                Generally you might need to classify your log files for different services or modules.



                For this purpose, Monolog allows you to create different channels, where each can log separately to different file and allow you to configure your log per channel.



                In the line you are referring to



                 $logger = new MonologLogger('channel-name'); 
                $app->container->logger = $logger;


                You are specifying the channel in the constructor of Monologger.



                Anytime you use this $logger object it will be writing to the file you specified when you configured the channel. Below is an example from the Symfony docs for a channel config



                https://symfony.com/doc/current/logging/channels_handlers.html#switching-a-channel-to-a-different-handler



                   monolog:
                handlers:
                security:
                # log all messages (since debug is the lowest level)
                level: debug
                type: stream
                path: '%kernel.logs_dir%/security.log'
                channels: [security]


                In which case you would do that in your code to use the channel



                 $logger = new MonologLogger('security');


                And then you will be logging to "security.log" with type "stream" errors of level "debug".






                share|improve this answer




























                  1












                  1








                  1







                  In simple words, you can define a channel as a separate log file.



                  Generally you might need to classify your log files for different services or modules.



                  For this purpose, Monolog allows you to create different channels, where each can log separately to different file and allow you to configure your log per channel.



                  In the line you are referring to



                   $logger = new MonologLogger('channel-name'); 
                  $app->container->logger = $logger;


                  You are specifying the channel in the constructor of Monologger.



                  Anytime you use this $logger object it will be writing to the file you specified when you configured the channel. Below is an example from the Symfony docs for a channel config



                  https://symfony.com/doc/current/logging/channels_handlers.html#switching-a-channel-to-a-different-handler



                     monolog:
                  handlers:
                  security:
                  # log all messages (since debug is the lowest level)
                  level: debug
                  type: stream
                  path: '%kernel.logs_dir%/security.log'
                  channels: [security]


                  In which case you would do that in your code to use the channel



                   $logger = new MonologLogger('security');


                  And then you will be logging to "security.log" with type "stream" errors of level "debug".






                  share|improve this answer















                  In simple words, you can define a channel as a separate log file.



                  Generally you might need to classify your log files for different services or modules.



                  For this purpose, Monolog allows you to create different channels, where each can log separately to different file and allow you to configure your log per channel.



                  In the line you are referring to



                   $logger = new MonologLogger('channel-name'); 
                  $app->container->logger = $logger;


                  You are specifying the channel in the constructor of Monologger.



                  Anytime you use this $logger object it will be writing to the file you specified when you configured the channel. Below is an example from the Symfony docs for a channel config



                  https://symfony.com/doc/current/logging/channels_handlers.html#switching-a-channel-to-a-different-handler



                     monolog:
                  handlers:
                  security:
                  # log all messages (since debug is the lowest level)
                  level: debug
                  type: stream
                  path: '%kernel.logs_dir%/security.log'
                  channels: [security]


                  In which case you would do that in your code to use the channel



                   $logger = new MonologLogger('security');


                  And then you will be logging to "security.log" with type "stream" errors of level "debug".







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 27 '18 at 13:50

























                  answered Nov 27 '18 at 13:38









                  user6437700user6437700

                  6919




                  6919






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53500818%2fwhat-is-channel-in-monologger%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Lallio

                      Unable to find Lightning Node

                      Futebolista