Boost Log severity levels versus syslog severity levels












0














I'm trying to modify my application to use the Boost Log library instead of logging into syslog. Boost Log severity levels are defined in boost/log/trivial.hpp, where the most serious level has maximal numeric number (5):



enum severity_level
{
trace,
debug,
info,
warning,
error,
fatal
};


However, the syslog defines more severity levels, which are actually standardized by the RFC5424 - and most serious level has minimal numeric number (0).



Is it any way to define my own MySeverityLevels enumeration type (probably close to the RFC5424) and use various Boost Log loggers (severity_logger, for instance) with this new type, including the filtering by severity level?










share|improve this question






















  • not really clear what is the problem. Can you invent a mapping from boost severity levels to syslog severity levels? Yes, why not?
    – user463035818
    Nov 19 '18 at 17:17










  • @user463035818 - yes, I can - but it wouldn't be an answer for this question
    – HEKTO
    Nov 19 '18 at 17:28
















0














I'm trying to modify my application to use the Boost Log library instead of logging into syslog. Boost Log severity levels are defined in boost/log/trivial.hpp, where the most serious level has maximal numeric number (5):



enum severity_level
{
trace,
debug,
info,
warning,
error,
fatal
};


However, the syslog defines more severity levels, which are actually standardized by the RFC5424 - and most serious level has minimal numeric number (0).



Is it any way to define my own MySeverityLevels enumeration type (probably close to the RFC5424) and use various Boost Log loggers (severity_logger, for instance) with this new type, including the filtering by severity level?










share|improve this question






















  • not really clear what is the problem. Can you invent a mapping from boost severity levels to syslog severity levels? Yes, why not?
    – user463035818
    Nov 19 '18 at 17:17










  • @user463035818 - yes, I can - but it wouldn't be an answer for this question
    – HEKTO
    Nov 19 '18 at 17:28














0












0








0







I'm trying to modify my application to use the Boost Log library instead of logging into syslog. Boost Log severity levels are defined in boost/log/trivial.hpp, where the most serious level has maximal numeric number (5):



enum severity_level
{
trace,
debug,
info,
warning,
error,
fatal
};


However, the syslog defines more severity levels, which are actually standardized by the RFC5424 - and most serious level has minimal numeric number (0).



Is it any way to define my own MySeverityLevels enumeration type (probably close to the RFC5424) and use various Boost Log loggers (severity_logger, for instance) with this new type, including the filtering by severity level?










share|improve this question













I'm trying to modify my application to use the Boost Log library instead of logging into syslog. Boost Log severity levels are defined in boost/log/trivial.hpp, where the most serious level has maximal numeric number (5):



enum severity_level
{
trace,
debug,
info,
warning,
error,
fatal
};


However, the syslog defines more severity levels, which are actually standardized by the RFC5424 - and most serious level has minimal numeric number (0).



Is it any way to define my own MySeverityLevels enumeration type (probably close to the RFC5424) and use various Boost Log loggers (severity_logger, for instance) with this new type, including the filtering by severity level?







c++ boost boost-log






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 17:10









HEKTO

1,91311530




1,91311530












  • not really clear what is the problem. Can you invent a mapping from boost severity levels to syslog severity levels? Yes, why not?
    – user463035818
    Nov 19 '18 at 17:17










  • @user463035818 - yes, I can - but it wouldn't be an answer for this question
    – HEKTO
    Nov 19 '18 at 17:28


















  • not really clear what is the problem. Can you invent a mapping from boost severity levels to syslog severity levels? Yes, why not?
    – user463035818
    Nov 19 '18 at 17:17










  • @user463035818 - yes, I can - but it wouldn't be an answer for this question
    – HEKTO
    Nov 19 '18 at 17:28
















not really clear what is the problem. Can you invent a mapping from boost severity levels to syslog severity levels? Yes, why not?
– user463035818
Nov 19 '18 at 17:17




not really clear what is the problem. Can you invent a mapping from boost severity levels to syslog severity levels? Yes, why not?
– user463035818
Nov 19 '18 at 17:17












@user463035818 - yes, I can - but it wouldn't be an answer for this question
– HEKTO
Nov 19 '18 at 17:28




@user463035818 - yes, I can - but it wouldn't be an answer for this question
– HEKTO
Nov 19 '18 at 17:28












2 Answers
2






active

oldest

votes


















1














<boost_root>/libs/log/example/native_syslog contains example of custom log levels, i.e. create an enumeration for your severity levels:



//! Define application-specific severity levels
enum severity_levels
{
/* your own level */
normal = 2,
warning = 1,
error = 0
};


and register it in your sink



    // Create a syslog sink
shared_ptr< sinks::synchronous_sink< sinks::syslog_backend > > sink(
new sinks::synchronous_sink< sinks::syslog_backend >(
keywords::use_impl = sinks::syslog::native,
keywords::facility = sinks::syslog::local7));
........................
// We'll have to map our custom levels to the syslog levels
sinks::syslog::custom_severity_mapping< severity_levels > mapping("Severity");
mapping[normal] = sinks::syslog::info;
mapping[warning] = sinks::syslog::warning;
mapping[error] = sinks::syslog::critical;

sink->locked_backend()->set_severity_mapper(mapping);

// Add the sink to the core
logging::core::get()->add_sink(sink);





share|improve this answer































    0














    I'm answering my own question. The code below implements what I wanted:



    #include <boost/log/common.hpp>
    #include <boost/log/utility/setup/file.hpp>

    namespace logging = boost::log;
    namespace src = boost::log::sources;
    namespace keywords = boost::log::keywords;

    enum class MySeverityLevel
    {
    panic,
    alert,
    critical,
    error,
    warning,
    notice,
    info,
    debug
    };

    BOOST_LOG_ATTRIBUTE_KEYWORD(Severity, "Severity", MySeverityLevel)

    int main()
    {
    // ------ define sink
    logging::add_file_log
    (
    keywords::file_name = "test.log",
    keywords::filter = (Severity <= MySeverityLevel::error)
    );
    // ------ define logger
    src::severity_logger<MySeverityLevel> lg;
    // ------ output logging messages
    BOOST_LOG_SEV(lg, MySeverityLevel::panic) << "This is panic";
    BOOST_LOG_SEV(lg, MySeverityLevel::debug) << "This is debug";
    }


    It was no need to use any mappings.






    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%2f53379583%2fboost-log-severity-levels-versus-syslog-severity-levels%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














      <boost_root>/libs/log/example/native_syslog contains example of custom log levels, i.e. create an enumeration for your severity levels:



      //! Define application-specific severity levels
      enum severity_levels
      {
      /* your own level */
      normal = 2,
      warning = 1,
      error = 0
      };


      and register it in your sink



          // Create a syslog sink
      shared_ptr< sinks::synchronous_sink< sinks::syslog_backend > > sink(
      new sinks::synchronous_sink< sinks::syslog_backend >(
      keywords::use_impl = sinks::syslog::native,
      keywords::facility = sinks::syslog::local7));
      ........................
      // We'll have to map our custom levels to the syslog levels
      sinks::syslog::custom_severity_mapping< severity_levels > mapping("Severity");
      mapping[normal] = sinks::syslog::info;
      mapping[warning] = sinks::syslog::warning;
      mapping[error] = sinks::syslog::critical;

      sink->locked_backend()->set_severity_mapper(mapping);

      // Add the sink to the core
      logging::core::get()->add_sink(sink);





      share|improve this answer




























        1














        <boost_root>/libs/log/example/native_syslog contains example of custom log levels, i.e. create an enumeration for your severity levels:



        //! Define application-specific severity levels
        enum severity_levels
        {
        /* your own level */
        normal = 2,
        warning = 1,
        error = 0
        };


        and register it in your sink



            // Create a syslog sink
        shared_ptr< sinks::synchronous_sink< sinks::syslog_backend > > sink(
        new sinks::synchronous_sink< sinks::syslog_backend >(
        keywords::use_impl = sinks::syslog::native,
        keywords::facility = sinks::syslog::local7));
        ........................
        // We'll have to map our custom levels to the syslog levels
        sinks::syslog::custom_severity_mapping< severity_levels > mapping("Severity");
        mapping[normal] = sinks::syslog::info;
        mapping[warning] = sinks::syslog::warning;
        mapping[error] = sinks::syslog::critical;

        sink->locked_backend()->set_severity_mapper(mapping);

        // Add the sink to the core
        logging::core::get()->add_sink(sink);





        share|improve this answer


























          1












          1








          1






          <boost_root>/libs/log/example/native_syslog contains example of custom log levels, i.e. create an enumeration for your severity levels:



          //! Define application-specific severity levels
          enum severity_levels
          {
          /* your own level */
          normal = 2,
          warning = 1,
          error = 0
          };


          and register it in your sink



              // Create a syslog sink
          shared_ptr< sinks::synchronous_sink< sinks::syslog_backend > > sink(
          new sinks::synchronous_sink< sinks::syslog_backend >(
          keywords::use_impl = sinks::syslog::native,
          keywords::facility = sinks::syslog::local7));
          ........................
          // We'll have to map our custom levels to the syslog levels
          sinks::syslog::custom_severity_mapping< severity_levels > mapping("Severity");
          mapping[normal] = sinks::syslog::info;
          mapping[warning] = sinks::syslog::warning;
          mapping[error] = sinks::syslog::critical;

          sink->locked_backend()->set_severity_mapper(mapping);

          // Add the sink to the core
          logging::core::get()->add_sink(sink);





          share|improve this answer














          <boost_root>/libs/log/example/native_syslog contains example of custom log levels, i.e. create an enumeration for your severity levels:



          //! Define application-specific severity levels
          enum severity_levels
          {
          /* your own level */
          normal = 2,
          warning = 1,
          error = 0
          };


          and register it in your sink



              // Create a syslog sink
          shared_ptr< sinks::synchronous_sink< sinks::syslog_backend > > sink(
          new sinks::synchronous_sink< sinks::syslog_backend >(
          keywords::use_impl = sinks::syslog::native,
          keywords::facility = sinks::syslog::local7));
          ........................
          // We'll have to map our custom levels to the syslog levels
          sinks::syslog::custom_severity_mapping< severity_levels > mapping("Severity");
          mapping[normal] = sinks::syslog::info;
          mapping[warning] = sinks::syslog::warning;
          mapping[error] = sinks::syslog::critical;

          sink->locked_backend()->set_severity_mapper(mapping);

          // Add the sink to the core
          logging::core::get()->add_sink(sink);






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 19 '18 at 18:08

























          answered Nov 19 '18 at 17:41









          Victor Gubin

          1,293111




          1,293111

























              0














              I'm answering my own question. The code below implements what I wanted:



              #include <boost/log/common.hpp>
              #include <boost/log/utility/setup/file.hpp>

              namespace logging = boost::log;
              namespace src = boost::log::sources;
              namespace keywords = boost::log::keywords;

              enum class MySeverityLevel
              {
              panic,
              alert,
              critical,
              error,
              warning,
              notice,
              info,
              debug
              };

              BOOST_LOG_ATTRIBUTE_KEYWORD(Severity, "Severity", MySeverityLevel)

              int main()
              {
              // ------ define sink
              logging::add_file_log
              (
              keywords::file_name = "test.log",
              keywords::filter = (Severity <= MySeverityLevel::error)
              );
              // ------ define logger
              src::severity_logger<MySeverityLevel> lg;
              // ------ output logging messages
              BOOST_LOG_SEV(lg, MySeverityLevel::panic) << "This is panic";
              BOOST_LOG_SEV(lg, MySeverityLevel::debug) << "This is debug";
              }


              It was no need to use any mappings.






              share|improve this answer


























                0














                I'm answering my own question. The code below implements what I wanted:



                #include <boost/log/common.hpp>
                #include <boost/log/utility/setup/file.hpp>

                namespace logging = boost::log;
                namespace src = boost::log::sources;
                namespace keywords = boost::log::keywords;

                enum class MySeverityLevel
                {
                panic,
                alert,
                critical,
                error,
                warning,
                notice,
                info,
                debug
                };

                BOOST_LOG_ATTRIBUTE_KEYWORD(Severity, "Severity", MySeverityLevel)

                int main()
                {
                // ------ define sink
                logging::add_file_log
                (
                keywords::file_name = "test.log",
                keywords::filter = (Severity <= MySeverityLevel::error)
                );
                // ------ define logger
                src::severity_logger<MySeverityLevel> lg;
                // ------ output logging messages
                BOOST_LOG_SEV(lg, MySeverityLevel::panic) << "This is panic";
                BOOST_LOG_SEV(lg, MySeverityLevel::debug) << "This is debug";
                }


                It was no need to use any mappings.






                share|improve this answer
























                  0












                  0








                  0






                  I'm answering my own question. The code below implements what I wanted:



                  #include <boost/log/common.hpp>
                  #include <boost/log/utility/setup/file.hpp>

                  namespace logging = boost::log;
                  namespace src = boost::log::sources;
                  namespace keywords = boost::log::keywords;

                  enum class MySeverityLevel
                  {
                  panic,
                  alert,
                  critical,
                  error,
                  warning,
                  notice,
                  info,
                  debug
                  };

                  BOOST_LOG_ATTRIBUTE_KEYWORD(Severity, "Severity", MySeverityLevel)

                  int main()
                  {
                  // ------ define sink
                  logging::add_file_log
                  (
                  keywords::file_name = "test.log",
                  keywords::filter = (Severity <= MySeverityLevel::error)
                  );
                  // ------ define logger
                  src::severity_logger<MySeverityLevel> lg;
                  // ------ output logging messages
                  BOOST_LOG_SEV(lg, MySeverityLevel::panic) << "This is panic";
                  BOOST_LOG_SEV(lg, MySeverityLevel::debug) << "This is debug";
                  }


                  It was no need to use any mappings.






                  share|improve this answer












                  I'm answering my own question. The code below implements what I wanted:



                  #include <boost/log/common.hpp>
                  #include <boost/log/utility/setup/file.hpp>

                  namespace logging = boost::log;
                  namespace src = boost::log::sources;
                  namespace keywords = boost::log::keywords;

                  enum class MySeverityLevel
                  {
                  panic,
                  alert,
                  critical,
                  error,
                  warning,
                  notice,
                  info,
                  debug
                  };

                  BOOST_LOG_ATTRIBUTE_KEYWORD(Severity, "Severity", MySeverityLevel)

                  int main()
                  {
                  // ------ define sink
                  logging::add_file_log
                  (
                  keywords::file_name = "test.log",
                  keywords::filter = (Severity <= MySeverityLevel::error)
                  );
                  // ------ define logger
                  src::severity_logger<MySeverityLevel> lg;
                  // ------ output logging messages
                  BOOST_LOG_SEV(lg, MySeverityLevel::panic) << "This is panic";
                  BOOST_LOG_SEV(lg, MySeverityLevel::debug) << "This is debug";
                  }


                  It was no need to use any mappings.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 20 '18 at 19:26









                  HEKTO

                  1,91311530




                  1,91311530






























                      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.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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%2f53379583%2fboost-log-severity-levels-versus-syslog-severity-levels%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

                      android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                      SQL update select statement

                      'app-layout' is not a known element: how to share Component with different Modules