Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

entry to string function #448

Open
goatshriek opened this issue Sep 26, 2024 · 4 comments
Open

entry to string function #448

goatshriek opened this issue Sep 26, 2024 · 4 comments
Assignees
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

Comments

@goatshriek
Copy link
Owner

goatshriek commented Sep 26, 2024

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 function stumpless_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:

  • the general format of the output. This should be each field name (procid, app_name, msgid, etc.), an equals sign, and the value in double quotes, all separated by commas. For the elements, use the 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"
  • the supplied argument should be a const pointer
  • explicitly state that the result must be freed when it is no longer needed

Now 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 use stumpless_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 like sprintf - you should be able to do this with memcpy calls and assignments, and perhaps strlen calls. You may consider refactoring some common portions of stumpless_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.

@goatshriek goatshriek added enhancement new features or improvements help wanted external contributations encouraged good first issue something that would be simple for a newcomer to stumpless to work on hacktoberfest labels Sep 26, 2024
@Master9090rgb
Copy link

Master9090rgb commented Sep 27, 2024

Hello Sir, I am new to the field of Open Source Contribution,I am willing to work on this issue if you can guide me a little on how to contribute to this.
My Tech Stack is C++,Python,Django
Thank you

@goatshriek
Copy link
Owner Author

goatshriek commented Sep 27, 2024

Welcome! Have a look through the contributing guidelines and development guides linked in the issue, which are intended to be an accessible entry point for newcomers. Specifically, this section lays out the most basic steps.

If you aren't super familiar with C and this is your first contribution, I do recommend one of the other good first issues that are smaller changes. This one will deal heavily with dynamic memory and strings, which can be tough to deal with coming from Python or even C++ in many cases. #445 may be a good fit, as it will only require a bugfix to existing C code, and the test suites are written in C++ which will be more familiar to you.

@Master9090rgb
Copy link

Thank You for the reply i will look through all the resources provided and will try to do my best

@KlowdfurrRad
Copy link

I would like to work on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

3 participants