diff options
| author | Dennis Camera <skonfig@dtnr.ch> | 2022-08-14 22:39:24 +0200 |
|---|---|---|
| committer | Dennis Camera <skonfig@dtnr.ch> | 2022-08-14 23:47:33 +0200 |
| commit | 289a2e94910d3b30256799f6c261dc01b194f254 (patch) | |
| tree | c634e450838a35a84a7d10cca2e0a40b7ac30638 /src/skonfig.c | |
| parent | a08bb6903495fb562fc3f2b881ee69eb36ac01cf (diff) | |
| download | skonfig-c-289a2e94910d3b30256799f6c261dc01b194f254.tar.gz skonfig-c-289a2e94910d3b30256799f6c261dc01b194f254.zip | |
Implement logging module
Diffstat (limited to 'src/skonfig.c')
| -rw-r--r-- | src/skonfig.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/skonfig.c b/src/skonfig.c index 1b97adf..eea5fb1 100644 --- a/src/skonfig.c +++ b/src/skonfig.c @@ -1,6 +1,7 @@ #include "../config.h" #include "config.h" +#include "log.h" #include "util/array.h" #include "util/fs.h" #include "util/string.h" @@ -167,19 +168,23 @@ void sk_init_config(struct sk_config *config, const char *config_file) { if (config_file) { /* Parse config file (as given by option) */ +#if DEBUG printf("processing config file (opt): %s\n", config_file); +#endif fh = fopen(config_file, "r"); if (fh) { sk_config_parse_file(config, fh); fclose(fh); } else { - fprintf(stderr, "invalid config file: %s\n", config_file); - exit(1); + sk_error("invalid config file: %s", config_file); + exit(EXIT_FAILURE); } } else if ((config_file = sk_config_find())) { /* found a config file in default location */ +#if DEBUG printf("processing config file (found): %s\n", config_file); +#endif fh = fopen(config_file, "r"); sk_config_parse_file(config, fh); @@ -220,7 +225,7 @@ int main(int argc, char *argv[]) { /* check if conf_root exists */ if (!is_dir(options.conf_root)) { - fprintf(stderr, "Cannot find configuration directory.\n"); + sk_error("cannot find configuration directory."); perror(options.conf_root); /* is_dir sets errno */ /* TODO: Add link to Getting Started guide */ return EXIT_FAILURE; @@ -238,12 +243,29 @@ int main(int argc, char *argv[]) { if (config->global.verbosity_level > SK_LOG_MAX) config->global.verbosity_level = SK_LOG_MAX; + sk_log_level_set(config->global.verbosity_level); + switch (config->global.coloured_output) { + case SK_COLOUR_NEVER: + sk_log_font_set(SK_LOG_MONOCHROME); + break; + case SK_COLOUR_ALWAYS: + sk_log_font_set(SK_LOG_COLOURED); + break; + case SK_COLOUR_AUTO: + if (isatty(fileno(stdout))) { + sk_log_font_set(SK_LOG_COLOURED); + } else { + sk_log_font_set(SK_LOG_MONOCHROME); + } + break; + } + #if DEBUG sk_config_print(config, stdout); /* DEBUG */ #endif - printf("conf dir: %s\n", options.conf_root); - printf("target host: %s\n", options.target_host); + sk_debug("conf dir: %s", options.conf_root); + sk_debug("target host: %s", options.target_host); sk_config_free(config); |
