diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2013-09-19 12:18:56 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2013-09-19 21:36:32 +0800 |
commit | 307b4b091e0bc298964e90888bf179431e32c134 (patch) | |
tree | 47cc758b0929eb29a216efd945b9ad46f4ffb19a /discover/pb-discover.c | |
parent | e52b37c27c267c882d82cd1e34412817b5a4dbce (diff) | |
download | talos-petitboot-307b4b091e0bc298964e90888bf179431e32c134.tar.gz talos-petitboot-307b4b091e0bc298964e90888bf179431e32c134.zip |
lib/log: Cleanup log API
Rather than exposing log internals (through always_flush and
set_stream), do all logging init through pb_log_init(). If pb_log_init()
hasn't been called, pb_log will drop messages.
Also, add a pb_debug() function, specifically for debugging information.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'discover/pb-discover.c')
-rw-r--r-- | discover/pb-discover.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/discover/pb-discover.c b/discover/pb-discover.c index 6d62e14..c16d690 100644 --- a/discover/pb-discover.c +++ b/discover/pb-discover.c @@ -123,6 +123,7 @@ int main(int argc, char *argv[]) struct opts opts; struct pb_udev *udev; struct user_event *uev; + FILE *log; if (opts_parse(&opts, argc, argv)) { print_usage(); @@ -139,17 +140,17 @@ int main(int argc, char *argv[]) return EXIT_SUCCESS; } + log = stderr; if (strcmp(opts.log_file, "-")) { - FILE *log = fopen(opts.log_file, "a"); - - assert(log); - pb_log_set_stream(log); - } else - pb_log_set_stream(stderr); + log = fopen(opts.log_file, "a"); + if (!log) { + fprintf(stderr, "can't open log file %s, logging to " + "stderr\n", opts.log_file); + log = stderr; + } + } + pb_log_init(log); -#if defined(DEBUG) - pb_log_always_flush(1); -#endif pb_log("--- pb-discover ---\n"); /* we look for closed sockets when we write, so ignore SIGPIPE */ |