# # # add_dir "tests/diagnostics_with--timestamps" # # add_file "tests/diagnostics_with--timestamps/__driver__.lua" # content [fd96b62501b167118430cbeb3cc674f86b3641ef] # # patch "NEWS" # from [4f6c24f988b3f1857437d1ee5847ae02afc05875] # to [f46fdfaf95ae550e91b37383b72296038a042e3a] # # patch "options_list.hh" # from [bfe72482f6c82ec90a15fdc3d3b540ac241b05d9] # to [0af1ca614362af5db0ebda15049eaf69eebad2eb] # # patch "ui.cc" # from [c1706a9c8cc139e1489b06515156c1171c0b071d] # to [6a29e5352e7fd49b248150574cba975dec563e35] # # patch "ui.hh" # from [5c9d5db3978343c279096c8aee2b51f8408feb4d] # to [867ad5d3cbd82e1f27e3c02317439723426e6c10] # ============================================================ --- tests/diagnostics_with--timestamps/__driver__.lua fd96b62501b167118430cbeb3cc674f86b3641ef +++ tests/diagnostics_with--timestamps/__driver__.lua fd96b62501b167118430cbeb3cc674f86b3641ef @@ -0,0 +1,12 @@ + +mtn_setup() + +-- since we run with LANG=C, we check for dates like Mon Nov 23 12:34:04 2009 +local prefix_pattern = "%[%a+ %a+ %d%d %d%d:%d%d:%d%d %d%d%d%d%] " + +check(mtn("crash", "N", "--timestamps"), 1, false, true) +check(string.find(readfile("stderr"), prefix_pattern .. "mtn: misuse: There is no spoon.") ~= nil) + +check(mtn("crash", "E", "--timestamps"), 1, false, true) +check(string.find(readfile("stderr"), prefix_pattern .. "mtn: error: There is no spoon.") ~= nil) + ============================================================ --- NEWS 4f6c24f988b3f1857437d1ee5847ae02afc05875 +++ NEWS f46fdfaf95ae550e91b37383b72296038a042e3a @@ -34,6 +34,12 @@ the same, but executes only a single command and does not stdio-encode the output. + - The global option '--timestamps' has been added which prefixes + the current local timestamp before diagnostic messages such as + warnings, progress messages, errors and tickers. For example, + this option can be used to log the date and time when clients + connect to a monotone server. + Bugs fixed - A regression from 0.45's key migration prevented the proper ============================================================ --- options_list.hh bfe72482f6c82ec90a15fdc3d3b540ac241b05d9 +++ options_list.hh 0af1ca614362af5db0ebda15049eaf69eebad2eb @@ -637,6 +637,15 @@ gettext_noop("suppress warning, verbose, } #endif +GOPT(timestamps, "timestamps", bool, false, +gettext_noop("show timestamps in front of errors, warnings and progress messages")) +#ifdef option_bodies +{ + timestamps = true; + ui.enable_timestamps(); +} +#endif + OPT(recursive, "recursive,R", bool, false, gettext_noop("also operate on the contents of any listed directories")) #ifdef option_bodies ============================================================ --- ui.cc c1706a9c8cc139e1489b06515156c1171c0b071d +++ ui.cc 6a29e5352e7fd49b248150574cba975dec563e35 @@ -446,6 +446,8 @@ void user_interface::initialize() set_tick_write_count(); else set_tick_write_dot(); + + timestamps_enabled = false; } void user_interface::deinitialize() @@ -637,10 +639,21 @@ user_interface::output_prefix() string user_interface::output_prefix() { + std::string prefix; + if (timestamps_enabled) { + // FIXME: with no app pointer around we have no access to + // app.lua.get_date_format_spec() here, so we use the same format + // which f.e. also Apache uses for its log output + prefix = "[" + date_t::now().as_formatted_localtime("%a %b %d %H:%M:%S %Y") + "] "; + } if (prog_name.empty()) { - return "?: "; + prefix += "?: "; } - return prog_name + ": "; + else + { + prefix += prog_name + ": "; + } + return prefix; } static inline string @@ -888,6 +901,12 @@ user_interface::inform_usage(usage const commands::explain_usage(u.which, opts.show_hidden_commands, usage_stream); } +void +user_interface::enable_timestamps() +{ + timestamps_enabled = true; +} + // Local Variables: // mode: C++ // fill-column: 76 ============================================================ --- ui.hh 5c9d5db3978343c279096c8aee2b51f8408feb4d +++ ui.hh 867ad5d3cbd82e1f27e3c02317439723426e6c10 @@ -68,6 +68,7 @@ public: void set_tick_write_nothing(); void ensure_clean_line(); void redirect_log_to(system_path const & filename); + void enable_timestamps(); std::string output_prefix(); @@ -77,6 +78,7 @@ private: struct impl; impl * imp; + bool timestamps_enabled; friend struct ticker; friend struct tick_write_count;