Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions daemon/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ void log_init(void) {
snprintfz(filename, FILENAME_MAX, "%s/access.log", netdata_configured_log_dir);
stdaccess_filename = config_get(CONFIG_SECTION_GLOBAL, "access log", filename);

char deffacility[8];
snprintfz(deffacility,7,"%s","daemon");
facility_log = config_get(CONFIG_SECTION_GLOBAL, "facility log", deffacility);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not make facility_log int and put the call to log_facility_id here as well? Then you only call that function once.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see any problem to use an integer, but it will be necessary to export log_facility_id. I did not use integer initially, because yesterday when we talked about the libnetdata/log/log.c you said me "Since we only have one config setting for the facility, there's no reason to go through the initialization and call log_facility_id again. Just use a static int,", after read this I supposed that we had to keep this function static, so I decided to use a pointer to get the configuration and carry it to the log.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me spell it out.

  • Function open_log_file is called at least three times, for access.log, error.log, debug.log and it's also called we reopen the log files (I don't remember exactly where, you can check the usages of this function).
  • Since we unconditionally initialize syslog each time filename="syslog", we are also making three calls to log_facility_id.
  • However, there's a single input and a single output to that function, as we only have a single config parameter to control the facility. So there's no point in calling it again, with the exact same input.

There are a few ways to prevent this:

  • Put a static int ihavealreadydonethis either in open_log_file or in log_facility_id. The first time we enter it's set e.g. to -1, the second to something else. We check its value and based on that, we don't go through the checks again. There are many variations of this solution.
  • Don't call log_facility_id from open_log_file at all. Do instead:
facility_log = log_facility_id(config_get(CONFIG_SECTION_GLOBAL, "facility log",  deffacility));

and do syslog_init(facility_log) in open_log_file. Of course then facility_log needs to be an int.

The older comments were a bit vague, so I get why you didn't understand them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I could understand the previous request. I found another solution and I decided use it. Inside the function syslog_init we already have an "static int i", so the function openlog is called only one time, so I returned the syslog_init for the previous format and I put the call of the function log_facility_id inside the openlog.


error_log_throttle_period = config_get_number(CONFIG_SECTION_GLOBAL, "errors flood protection period", error_log_throttle_period);
error_log_errors_per_period = (unsigned long)config_get_number(CONFIG_SECTION_GLOBAL, "errors to trigger flood protection", (long long int)error_log_errors_per_period);
error_log_errors_per_period_backup = error_log_errors_per_period;
Expand Down
Loading