Menu

#37 Custom syslog Facility Support

Release 1.2
closed
nobody
None
1
2017-02-28
2017-02-24
Anonymous
No

Some system logging products (especially commercial ones), only supports separation of incoming syslog packets by facility code. In the current version, all syslog logging done as 'user'. I am attaching a patch, which does following:

If configuration has 'logging.syslog.facility' string value, it uses given value while calling 'openlog' function.
For security reasons, attached patch only allows 'user', 'local0', .... 'local7' facilities to be specified in the configuration.

Artyom,
I don't know how you feel about adding new functionality to already completed features, but in my opinion, this feature should be included with completely backward-compatible way (which is true for given patch).

Regards.

1 Attachments

Discussion

  • Anonymous

    Anonymous - 2017-02-27
    1. I hereby transfer to "Artyom Beilis" all of my right, title and interest in and to the following patch ("underlying work"), including without limitation the copyright in that underlying work.
    2. I confirm that I own the rights necessary to enter into this Transfer of Rights agreement. I also confirm that I am the author of the underlying work and that it does not defame any person, nor does it violate the right of privacyor any other right of any person.
    3. Without limiting the foregoing, the rights transferred include the right to create derivative works based, in whole or in part, on the underlying work, and the right to edit, delete from, arrange, combine, revise or adapt in any manner whatsoever the underlying work, and to use it in any manner which "Artyom Beilis", in your sole discretion, deem appropriate. I waive my moral rights. This transfer and waiver is irrevocable.
    4. I release and discharge "Artyom Beilis" from any and all claims, demands or causes of actions that I haveor may in the future have for libel, defamation, invasion of privacyor right of publicity, infringement of copyright or trademark, or violatio of any other right arising out of or relating to any use of the rights granted under this Agreement.
    Index: src/service.cpp
    ===================================================================
    --- src/service.cpp (revision 2413)
    +++ src/service.cpp (working copy)
    @@ -261,8 +261,10 @@
                throw cppcms_error("Syslog is not availible on Windows");
            #else
            std::string id = settings.get("logging.syslog.id","");
    +       std::string facility = settings.get("logging.syslog.facility","user");
            std::vector<std::string> vops = settings.get("logging.syslog.options",std::vector<std::string>());
            std::string sfacility = settings.get("logging.syslog.options","");
    +       int facility_code = 0;
            int ops = 0;
            for(unsigned i=0;i<vops.size();i++) {
                std::string const &op=vops[i];
    @@ -275,10 +277,33 @@
                #endif
                else if(op=="LOG_PID") ops|=LOG_PID;
            }
    +       if(!facility.empty()) {
    +           if(facility == "user") {
    +               facility_code = LOG_USER;
    +           } else if(facility == "local0") {
    +               facility_code = LOG_LOCAL0;
    +           } else if(facility == "local1") {
    +               facility_code = LOG_LOCAL1;
    +           } else if(facility == "local2") {
    +               facility_code = LOG_LOCAL2;
    +           } else if(facility == "local3") {
    +               facility_code = LOG_LOCAL3;
    +           } else if(facility == "local4") {
    +               facility_code = LOG_LOCAL4;
    +           } else if(facility == "local5") {
    +               facility_code = LOG_LOCAL5;
    +           } else if(facility == "local6") {
    +               facility_code = LOG_LOCAL6;
    +           } else if(facility == "local7") {
    +               facility_code = LOG_LOCAL7;
    +           } else {
    +               throw cppcms_error("Unsupported syslog facility: " + facility);
    +           }
    +       }
            if(id.empty())
    -           ::openlog(0,ops,0);
    +           ::openlog(0,ops,facility_code);
            else
    -           ::openlog(id.c_str(),ops,0);
    +           ::openlog(id.c_str(),ops,facility_code);
            logger::instance().add_sink(booster::shared_ptr<sink>(new sinks::syslog()));
            #endif
        }
    

    Regards,
    Nazım Can Bedir.

     
  • Artyom Beilis

    Artyom Beilis - 2017-02-28
    • status: open --> closed
     
  • Artyom Beilis

    Artyom Beilis - 2017-02-28

    Thanks for the patch,

    Implemented in trunk changeset #2417

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.