goatshriek / stumpless

a C logging library built for performance and features
https://goatshriek.github.io/stumpless
Apache License 2.0
447 stars 337 forks source link

expand facility from string #358

Closed goatshriek closed 1 year ago

goatshriek commented 1 year ago

The Stumpless Rust crate and CLI tool creates targets and entries to do whatever logging needed. In order to provide CLI support, many of these tasks need to use the strings provided in the command to set up stumpless structures. One of these is the prival used for the severity and facility values of the logged entry. To support this, the existing stumpless_get_facility_enum function needs to be enhanced to support the same strings that standard logging tools do.

Currently the facility enum from string function only supports strings that exactly match the name of the symbol for a facility level, such as "STUMPLESS_FACILITY_AUTH". It needs to be updated to support the following strings, as well as not being case sensitive.

auth
authpriv
cron
daemon
ftp
kern
lpr
mail
news
syslog
user
uucp
local0
local1
local2
local3
local4
local5
local6
local7
security

General Approach

There are a few details left out of the following approach, for you to fill in as you encounter them. If you find you need help, please ask here or on the project gitter and someone can help you get past the stumbling block.

First, review the existing implementation of stumpless_get_facility_enum in src/facility.c. Once you understand how the current implementation works, start adding the new functionality. Note that the list of new strings to accept mostly matches the end of the current symbol names without the STUMPLESS_FACILITY_ prefix - you can likely use this fact to simplify your implementation.

Add tests for your new functionality in the existing test module test/function/facility.cpp, as separate test cases from the existing ones for this function. Be sure that you test for upper and lower case versions of the strings (both should be accepted), invalid strings, empty strings, and NULL strings at a minimum.

EDIT: this issue was originally duplicative of #237 and has been updated to specify the next phase of intended functionality.

jagw-mobica commented 1 year ago

Hi, I want to do this task, but I'm not sure if I understand it correctly. There is already created function stumpless_get_facility_enum( const char *facility_string ). What is difference between this expected to do stumpless_facility_from_string and stumpless_get_facility_enum( const char *facility_string )? Can you provide an usage example for it?

goatshriek commented 1 year ago

You're absolutely correct, I apologize for that. I had forgotten this was already done and missed the function when I did a quick check before making the issue.

I've updated this one to refer to the next thing that needs to be done with this function - please give the revised description a look and see if it's still something that interests you.

jagw-mobica commented 1 year ago

I think description is clear, but now I can see 2 things from the documentation logger :

  1. What about "kern cannot be generated from userspace process, automatically converted to user" - I can see it as an exception. Do we have to return 'user' facility for string 'kern'?
  2. What about "security deprecated synonym for auth". How to treat the string "security"? Additionally I can see in the project stumpless_logger :

auth or security security/authorization messages\n\

Please assign me to this task, I want to do it.

goatshriek commented 1 year ago

For kern you do not need to do anything special; you should return STUMPLESS_FACILITY_KERN. This special behavior will be up to the CLI tool to handle, but the library should allow any facility as it doesn't know what is using it.

security can be treated as identical to auth for this function, returning STUMPLESS_FACILITY_AUTH.