Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Support configurable syslog facilities #5792
In the link #5717 there was a request for the system admin to select the facility that he wanna have in syslog. In this commit I am creating two functions and I am also changing two to solve the described issue.
The function log_facility_id is the unique that is really necessary to fix the problem. When I created it I used all the facilities that are listed in the operate system headers, including the facility that is not available(mark) and it was commented due this or it is considered deprecated(security). This situation happens, because I am considering possible mistakes in the configure file. When someone chooses a facility that is not available, I am starting the syslog with the default that was present in the log.c previously.
The function log_facility_name was created to keep the same pattern that I found inside the file web/server/web_server.c . This function is not necessary to fix the problem, but it helps with possible future features.
The function syslog_init now has an argument, the argument is an integer that represents the facility that will be set.
Finally I had to append few lines of code inside the function open_log_file. I am considering that the config file will have a configuration variable "facility log" for the user to set the facility that is wished. I called three functions in the same line, instead to create variables to store the results, because the return of the called function is direct the input for the new function, so I am considering that there is not any necessity to extract results from the registers to put in memory addresses.
I am changing the file libnetdata/log/log.c
Nice and clean.
Hint: You could use a hash function to avoid all those strcmps and instead compare integers first. It's not a big deal in this case because we only open a few log files. When you use a static int, you'll only go through the comparisons once, so hashing is not needed here. But search for
Initially I compiled with the traditional steps(./configure && make && make install ), so I could not identify the problem that happens when we use script. After to use the script, I had the same problem and I could fix using the following steps:
I changed the libnet/log/log.c adding the variable facility_log and I put an extern reference to it inside the file libnet/log/log.h . After this I moved few lines of code that were inside the function open_log_file to the daemon/main.c, so I am reading the option "facility log" there now.
I accepted all the suggestions given and I wrote the body of the function log_facility_id using hashes. I agree 100% that we could consider this "not a big deal", but when we remove the strcmp we avoid some call instructions and no less important, I could learn more about the source code. I decided to use simple_hash instead simple_uhash, because I arrived in the conclusion it is the correct case here, please can you confirm this?
Finally, to save some byte codes, I commented the function(log_facility_name) that is not been used anywhere.