entry to string function #448
Labels
enhancement
new features or improvements
good first issue
something that would be simple for a newcomer to stumpless to work on
help wanted
external contributations encouraged
It is often useful to be able to obtain a string representation of a given value either for user interface hints, troubleshooting, or operations like value comparison. Such a function is currently implemented for some stumpless data types (like the version, param, and element structs) but not for others, including the entry struct.
Note that this function is not intended for use in the formatting of a log message as this output may be subtly different, for example when escape codes are needed. Rather, it is meant to give an as-is representation of the entry itself (all fields and elements).
Check out the Contributing Guidelines and the development guide for the basics on working with stumpless and submitting changes.
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 are also free to take a different approach if you feel it is better - this is merely meant as a starting point.
First, read this specific section of the development guide devoted to adding new functions. It provides an outline of the work you will need to do beyond the implementation and testing of the function.
Next, add a declaration for your function in the
include/stumpless/entry.h
header file. Name the functionstumpless_entry_to_string
and document its behavior in the same doxygen format as the others in the same header. Make sure to cover the following points:stumpless_element_to_string
function to get the output for each element. For example:time="2003-10-11T22:14:15.003Z", prival="165", hostname="example.com", app_name="test-suite", procid="6", msgid="yellow", element-1=[param="val"], message="test message"
const
pointerNow you are ready to add the matching implementation for the function in
src/entry.c
. Use the code for existing functions in this file as examples. You will also need to usestumpless_element_to_string
to get the string representation of any elements in the entry. Be sure that there is no memory leak in your result, and try to avoid expensive operations likesprintf
- you should be able to do this withmemcpy
calls and assignments, and perhapsstrlen
calls. You may consider refactoring some common portions ofstumpless_element_to_string
into separate private functions that can be used in both places for efficiency, but don't worry if you don't want to go this far - it can be turned into a follow-on first issue for others to tackle.Finally, be sure to add tests for the new function. These should go in
test/function/entry.cpp
and should achieve full coverage, including for memory allocation failure and NULL argument cases. Again, there are already similar test cases for other functions in this file that you can look at to get a general idea of how the tests should be structured.The text was updated successfully, but these errors were encountered: