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 /ui | |
parent | e52b37c27c267c882d82cd1e34412817b5a4dbce (diff) | |
download | petitboot-307b4b091e0bc298964e90888bf179431e32c134.zip petitboot-307b4b091e0bc298964e90888bf179431e32c134.tar.gz |
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 'ui')
-rw-r--r-- | ui/ncurses/generic-main.c | 14 | ||||
-rw-r--r-- | ui/twin/main-generic.c | 15 |
2 files changed, 11 insertions, 18 deletions
diff --git a/ui/ncurses/generic-main.c b/ui/ncurses/generic-main.c index cafd23a..9236a80 100644 --- a/ui/ncurses/generic-main.c +++ b/ui/ncurses/generic-main.c @@ -206,6 +206,7 @@ int main(int argc, char *argv[]) int result; int cui_result; struct opts opts; + FILE *log; result = opts_parse(&opts, argc, argv); @@ -224,20 +225,15 @@ int main(int argc, char *argv[]) return EXIT_SUCCESS; } + log = stderr; if (strcmp(opts.log_file, "-")) { - FILE *log = fopen(opts.log_file, "a"); + log = fopen(opts.log_file, "a"); if (!log) log = fopen("/dev/null", "a"); + } - assert(log); - pb_log_set_stream(log); - } else - pb_log_set_stream(stderr); - -#if defined(DEBUG) - pb_log_always_flush(1); -#endif + pb_log_init(log); pb_log("--- petitboot-nc ---\n"); diff --git a/ui/twin/main-generic.c b/ui/twin/main-generic.c index 99520d0..649ad00 100644 --- a/ui/twin/main-generic.c +++ b/ui/twin/main-generic.c @@ -268,6 +268,7 @@ int main(int argc, char *argv[]) int result; int ui_result; struct pbt_client *client; + FILE *log; result = pbt_opts_parse(&opts, argc, argv); @@ -286,17 +287,13 @@ 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); - -#if defined(DEBUG) - pb_log_always_flush(1); -#endif + if (!log) + log = stderr; + } + pb_log_init(log); pb_log("--- petitboot-twin ---\n"); |