Changeset 4511ac3


Ignore:
Timestamp:
Aug 5, 2017, 11:21:53 PM (7 years ago)
Author:
Jason Gross <jasongross9@gmail.com>
Branches:
master
Children:
253f37f
Parents:
565a43c
git-author:
Jason Gross <jgross@mit.edu> (08/05/17 22:06:52)
git-committer:
Jason Gross <jasongross9@gmail.com> (08/05/17 23:21:53)
Message:
Better UI for :flush-logs and flush-logs-interval

We now only print the message about how many logs there are to flush
when -q is not passed to :flush-logs.  The timer from
flush-logs-interval passes -q, so the user won't see "There are no logs
to flush." ever few minutes.
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    r77beb3c r4511ac3  
    490490  OWLCMD_ARGS("flush-logs", owl_command_flushlogs, OWL_CTX_ANY,
    491491              "flush the queue of messages waiting to be logged",
    492               "flush-logs [-f | --force]",
     492              "flush-logs [-f | --force] [-q | --quiet]",
    493493              "If BarnOwl failed to log a file, this command tells\n"
    494494              "BarnOwl to try logging the messages that have since\n"
     
    501501              "any messages on the queue which cannot successfully be\n"
    502502              "logged are dropped, and BarnOwl will resume logging\n"
    503               "normally."),
     503              "normally.\n"
     504              "\n"
     505              "Unless --quiet is passed, a message is printed about\n"
     506              "how many logs there are to flush."),
    504507
    505508  OWLCMD_ARGS("load-subs", owl_command_loadsubs, OWL_CTX_ANY,
     
    14541457char *owl_command_flushlogs(int argc, const char *const *argv, const char *buff)
    14551458{
    1456   if (argc == 1) {
    1457     owl_log_flush_logs(false);
    1458   } else if (argc == 2) {
    1459     if (!strcmp(argv[1], "-f") || !strcmp(argv[1], "--force")) {
    1460       owl_log_flush_logs(true);
     1459  bool force = false;
     1460  bool quiet = false;
     1461  int i;
     1462
     1463  for (i = 1; i < argc; i++) {
     1464    if (!strcmp(argv[i], "-f") || !strcmp(argv[i], "--force")) {
     1465      force = true;
     1466    } else if (!strcmp(argv[i], "-q") || !strcmp(argv[i], "--quiet")) {
     1467      quiet = true;
    14611468    } else {
    1462       owl_function_makemsg("Invalid flag to flush-logs: %s", argv[1]);
     1469      owl_function_makemsg("Invalid flag to flush-logs: %s", argv[i]);
    14631470    }
    1464   } else {
    1465     owl_function_makemsg("Wrong number of arguments for flush-logs.");
    1466   }
     1471  }
     1472  owl_log_flush_logs(force, quiet);
    14671473  return NULL;
    14681474}
  • logging.c

    r565a43c r4511ac3  
    77} owl_log_entry;
    88
     9typedef struct _owl_log_options { /* noproto */
     10  bool drop_failed_logs;
     11  bool display_initial_log_count;
     12} owl_log_options;
    913
    1014static GMainContext *log_context;
     
    302306{
    303307  owl_log_entry *entry;
    304   bool drop_failed_logs = *(bool *)data;
     308  owl_log_options *opts = (owl_log_options *)data;
    305309  int ret;
    306310  int logged_message_count = 0;
    307311  bool all_succeeded = true;
    308312
    309   if (g_queue_is_empty(deferred_entry_queue)) {
    310     owl_log_makemsg("There are no logs to flush.");
    311   } else {
    312     owl_log_makemsg("Attempting to flush %u logs...",
    313                      g_queue_get_length(deferred_entry_queue));
     313  if (opts->display_initial_log_count) {
     314    if (g_queue_is_empty(deferred_entry_queue)) {
     315      owl_log_makemsg("There are no logs to flush.");
     316    } else {
     317      owl_log_makemsg("Attempting to flush %u logs...",
     318                      g_queue_get_length(deferred_entry_queue));
     319    }
    314320  }
    315321
     
    318324    logged_message_count++;
    319325    entry = (owl_log_entry*)g_queue_pop_head(deferred_entry_queue);
    320     if (!drop_failed_logs) {
     326    if (!opts->drop_failed_logs) {
    321327      /* Attempt to write the log entry.  If it fails, re-queue the entry at
    322328       * the head of the queue. */
     
    334340  }
    335341  if (logged_message_count > 0) {
    336     /* first clear the "attempting to flush" message from the status bar */
    337     owl_log_makemsg("");
     342    if (opts->display_initial_log_count) {
     343      /* first clear the "attempting to flush" message from the status bar */
     344      owl_log_makemsg("");
     345    }
    338346    if (!defer_logs) {
    339347      if (all_succeeded) {
     
    351359}
    352360
    353 void owl_log_flush_logs(bool drop_failed_logs)
    354 {
    355   bool *data = g_new(bool, 1);
    356   *data = drop_failed_logs;
     361void owl_log_flush_logs(bool drop_failed_logs, bool quiet)
     362{
     363  owl_log_options *data = g_new(owl_log_options, 1);
     364  data->drop_failed_logs = drop_failed_logs;
     365  data->display_initial_log_count = !quiet;
    357366
    358367  owl_select_post_task(owl_log_write_deferred_entries,
     
    641650  /* flush the deferred logs queue, trying to write the
    642651   * entries to the disk one last time.  Drop any failed
    643    * entries */
    644   bool bool_true = true;
    645   owl_log_write_deferred_entries(&bool_true);
     652   * entries, and be quiet about it. */
     653  owl_log_options opts;
     654  opts.drop_failed_logs = true;
     655  opts.display_initial_log_count = false;
     656  owl_log_write_deferred_entries(&opts);
    646657#if GLIB_CHECK_VERSION(2, 32, 0)
    647658  g_queue_free_full(deferred_entry_queue, owl_log_entry_free);
  • perl/lib/BarnOwl/DeferredLogging.pm

    r9d6e37c r4511ac3  
    5050                            name     => 'flush-logs interval timer',
    5151                            interval => 60 * $flush_logs_interval,
    52                             cb       => sub { BarnOwl::command("flush-logs"); }
     52                            cb       => sub { BarnOwl::command("flush-logs", "-q"); }
    5353                        });
    5454                }
Note: See TracChangeset for help on using the changeset viewer.