mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Rename LOGGER_BACKEND to LOG_BACKEND
This commit is contained in:
parent
a40fd1bb6c
commit
ffa927fa36
@ -30,15 +30,15 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
LOGGER_BACKEND current_backend = -1;
|
||||
LOG_BACKEND current_backend = -1;
|
||||
|
||||
bool open_log(LOGGER_BACKEND backend)
|
||||
bool open_log(LOG_BACKEND backend)
|
||||
{
|
||||
if (current_backend != -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (backend == LOGGER_BACKEND_SYSLOG) {
|
||||
if (backend == LOG_BACKEND_SYSLOG) {
|
||||
openlog(DAEMON_NAME, LOG_NOWAIT | LOG_PID, LOG_DAEMON);
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ bool close_log()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (current_backend == LOGGER_BACKEND_SYSLOG) {
|
||||
if (current_backend == LOG_BACKEND_SYSLOG) {
|
||||
closelog();
|
||||
}
|
||||
|
||||
@ -101,10 +101,10 @@ bool write_log(LOG_LEVEL level, const char *format, ...)
|
||||
va_start(args, format);
|
||||
|
||||
switch (current_backend) {
|
||||
case LOGGER_BACKEND_SYSLOG:
|
||||
case LOG_BACKEND_SYSLOG:
|
||||
log_syslog(level, format, args);
|
||||
break;
|
||||
case LOGGER_BACKEND_STDOUT:
|
||||
case LOG_BACKEND_STDOUT:
|
||||
log_stdout(level, format, args);
|
||||
break;
|
||||
}
|
||||
|
@ -26,10 +26,10 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef enum LOGGER_BACKEND {
|
||||
LOGGER_BACKEND_SYSLOG,
|
||||
LOGGER_BACKEND_STDOUT
|
||||
} LOGGER_BACKEND;
|
||||
typedef enum LOG_BACKEND {
|
||||
LOG_BACKEND_SYSLOG,
|
||||
LOG_BACKEND_STDOUT
|
||||
} LOG_BACKEND;
|
||||
|
||||
typedef enum LOG_LEVEL {
|
||||
LOG_LEVEL_INFO,
|
||||
@ -42,7 +42,7 @@ typedef enum LOG_LEVEL {
|
||||
* @param backend Specifies which backend to use.
|
||||
* @return true on success, flase if log is already opened.
|
||||
*/
|
||||
bool open_log(LOGGER_BACKEND backend);
|
||||
bool open_log(LOG_BACKEND backend);
|
||||
|
||||
/**
|
||||
* Releases all used resources by the logger.
|
||||
|
@ -544,7 +544,7 @@ bool print_help()
|
||||
// Handels command line arguments, setting cfg_file_path and log_backend.
|
||||
// Terminates the application if incorrect arguments are specified.
|
||||
|
||||
void handle_command_line_arguments(int argc, char *argv[], char **cfg_file_path, LOGGER_BACKEND *log_backend)
|
||||
void handle_command_line_arguments(int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend)
|
||||
{
|
||||
if (argc < 2) {
|
||||
write_log(LOG_LEVEL_ERROR, "Error: No arguments provided.\n\n");
|
||||
@ -581,10 +581,10 @@ void handle_command_line_arguments(int argc, char *argv[], char **cfg_file_path,
|
||||
|
||||
case 'l':
|
||||
if (strcmp(optarg, "syslog") == 0) {
|
||||
*log_backend = LOGGER_BACKEND_SYSLOG;
|
||||
*log_backend = LOG_BACKEND_SYSLOG;
|
||||
log_backend_set = true;
|
||||
} else if (strcmp(optarg, "stdout") == 0) {
|
||||
*log_backend = LOGGER_BACKEND_STDOUT;
|
||||
*log_backend = LOG_BACKEND_STDOUT;
|
||||
log_backend_set = true;
|
||||
} else {
|
||||
write_log(LOG_LEVEL_ERROR, "Error: Invalid BACKEND value for --log-backend option passed: %s\n\n", optarg);
|
||||
@ -610,7 +610,7 @@ void handle_command_line_arguments(int argc, char *argv[], char **cfg_file_path,
|
||||
}
|
||||
|
||||
if (!log_backend_set) {
|
||||
*log_backend = LOGGER_BACKEND_SYSLOG;
|
||||
*log_backend = LOG_BACKEND_SYSLOG;
|
||||
}
|
||||
|
||||
if (!cfg_file_path_set) {
|
||||
@ -623,10 +623,10 @@ void handle_command_line_arguments(int argc, char *argv[], char **cfg_file_path,
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *cfg_file_path;
|
||||
LOGGER_BACKEND log_backend;
|
||||
LOG_BACKEND log_backend;
|
||||
|
||||
// choose backend for printing command line argument parsing output based on whether the daemon is being run from a terminal
|
||||
log_backend = isatty(STDOUT_FILENO) ? LOGGER_BACKEND_STDOUT : LOGGER_BACKEND_SYSLOG;
|
||||
log_backend = isatty(STDOUT_FILENO) ? LOG_BACKEND_STDOUT : LOG_BACKEND_SYSLOG;
|
||||
|
||||
open_log(log_backend);
|
||||
handle_command_line_arguments(argc, argv, &cfg_file_path, &log_backend);
|
||||
@ -798,7 +798,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// Go quiet
|
||||
if (log_backend != LOGGER_BACKEND_STDOUT) {
|
||||
if (log_backend != LOG_BACKEND_STDOUT) {
|
||||
close(STDOUT_FILENO);
|
||||
close(STDIN_FILENO);
|
||||
close(STDERR_FILENO);
|
||||
|
Loading…
x
Reference in New Issue
Block a user