goatshriek/stumpless

prival from string

goatshriek opened this issue · 1 comments

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, a new function is needed named stumpless_prival_from_string which parses a string and attempts to extract a prival from it.

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.

You may want to check the status of #358 and #359, as they may be useful to you in your implementation if they have completed. If not, you can proceed with your own implementation without waiting on them.

First, read this section of the development documentation on adding new functions. Once you understand how this process works, start defining the new function.

Your new function will be named stumpless_prival_from_string, should take a single string parameter, and should return an int of the extracted prival. In the event of an error (such as a NULL or invalid string), return -1. Declare it in a new header include/stumpless/priority.h and corresponding source file src/priority.c. Don't forget to add these to the relevant lists in CMakeLists.txt (look for src/facility.c and src/facility.h for references on where this should be).

Next, review the existing Rust implementation of this functionality. This change will move this functionality into the base stumpless library, allowing other language bindings such as C++ to also provide it.

The Rust implementation use a regular expressions to extract the facility and severity, but the C library should avoid adding a regular expression dependency for performance reasons. Parse the provided string up to the first period character, ensure that there is not another period character before the end of the string, and then compare the two pieces of the string to the known facility and severity strings to generate the prival. You may find STUMPLESS_FOREACH_FACILITY and STUMPLESS_FOREACH_SEVERITY useful for this.

Add tests for your new function in a new test module test/function/priority.cpp. Use test/function/facility.cpp as both an example and a search point to see how to add the tests to CmakeLists.txt. 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.

Could you assign me to this task?
I have almost finished the patch.