class ToposPlayground::Command::Logs
- ToposPlayground::Command::Logs
- ToposPlayground::Command
- Reference
- Object
Defined in:
topos-playground/command/log.crConstant Summary
-
UUID_REGEXP =
/([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})/
Class Method Summary
- .levenshtein_options
- .list_options(parser, config)
- .log_to_file?(config)
- .options(parser, config)
- .prune_options(parser, config)
- .view_options(parser, config)
Instance Method Summary
-
#calculate_gaps_and_standard_deviation(logs)
Given a sorted array of logs, calculate the standard deviation of the gaps in time between each of the logs.
-
#do_list
Execute the logic of the
list
command. -
#do_prune
Using the sorting heuristic for
#do_list
to sort files, allow pruning of log files by age, size, or range. -
#do_prune_days(sorted_logs, selector)
Delete log files older than the specified number of days.
-
#do_prune_range(sorted_logs, selector)
Delete log files within the specified range.
-
#do_prune_size(sorted_logs, selector)
Delete log files smaller than the specified size.
-
#do_view
Using the sorting heuristic for
#do_list
to sort files, allow viewing of an individual log file, selected by index, or by date/time -- the first file before or after a given date/time. -
#do_view_after(sorted_logs, selector)
Find the log file specified by the selector, which is a date/time, and display it.
-
#do_view_before(sorted_logs, selector)
Find the log file specified by the selector, which is a date/time, and display it.
-
#do_view_index(sorted_logs, selector)
Find the log file specified by the selector, which is an index into the sorted list of log files, most recent first, and display it.
-
#generate_base_list : Array(Tuple(String, String, Time))
Perform the first pass at creating a list of log files.
-
#handle_erroneously_old_logs(logs) : Array(Tuple(String, String, Time))
If there are any log files with a filename that reflects a timestamp later than the current time, then it must be a randomly generated UUID from the official Node.js version of the topos-playground; pull the timestamp from the last modification time.
-
#handle_erroneously_young_logs(logs, gaps, standard_deviation)
With a modest statistical probability of being wrong, this should be able to identify those logs which have accidentally created valid UUID timestamps that are too early in time to have been generated by this version of the playground.
-
#multi_line_header(logs)
Build the multi-line header.
-
#parse_to_size(selector)
Parse a size selector, which can be a number, or a number followed by a unit, into a byte count.
-
#print_header(logs)
print the header for the sorted list of logs
-
#print_logs(logs)
Print the sorted list of logs.
-
#run
Act on the log subcommand (
list
,view
, orprune
). -
#show_deletion_count(count)
Output the number of deleted files.
-
#show_log_file(log)
Display the given log file.
-
#single_line_header(logs)
Build the single-line header.
Instance methods inherited from class ToposPlayground::Command
config : Config
config,
config=(config : Config)
config=,
run
run,
run_process(command, chdir = ".", env : Process::Env = nil, shell : Bool = true)run_process(command, chdir = ".", background : Bool = false, env : Process::Env = nil) run_process
Constructor methods inherited from class ToposPlayground::Command
new(config : Config)
new
Class methods inherited from class ToposPlayground::Command
config : Config
config,
config=(config : Config)
config=,
levenshtein_options
levenshtein_options,
log_to_file?(config)
log_to_file?,
options(parser, config)
options,
run_process(command, chdir = ".", background : Bool = false, env : Process::Env = nil)run_process(command, chdir = ".", env : Process::Env = nil, shell : Bool = true) run_process
Class Method Detail
Instance Method Detail
Given a sorted array of logs, calculate the standard deviation of the gaps in time between each of the logs.
Execute the logic of the list
command. Logs are sorted by the timestamp embedded
into the UUID in the filename. If the UUID doesn't encode a valid timestamp, then
the file modification time is used. If it does encode a valid timestamp, but the
timestamp is for a time later than now, the file modification time is used. Likewise,
if there is a gap between the timestamp of one log file and the next that is greater
than twice the standard deviation of the gaps between all of the log file, the timestamp
will be taken from the file modification time.
This heuristic lets the log files generated by this version of the playground, which are part of the UUID in the filename, to take precedence when sorting the files, but it allows the playground binary to also function in a reasonable and predictable way with log files generated by the official Node.js version.
Using the sorting heuristic for #do_list
to sort files, allow pruning of log files
by age, size, or range. The age is calculated in the same way as with the #do_list
method. Ranges are indexed with 1 being the most recent file.
Delete log files older than the specified number of days.
Delete log files within the specified range. Ranges are indexed with 1 being the most recent file. Alternatively, delete specific log files, by index, either alone, or in a comma separated list.
Delete log files smaller than the specified size. This is useful for getting rid of log files that are empty, or that contain only a few lines of output.
Using the sorting heuristic for #do_list
to sort files, allow viewing of an individual
log file, selected by index, or by date/time -- the first file before or after a given
date/time.
Find the log file specified by the selector, which is a date/time, and display it. This will show the first log file with a timestamp later than the selector.
Find the log file specified by the selector, which is a date/time, and display it. This will show the first log file with a timestamp earlier than the selector.
Find the log file specified by the selector, which is an index into the sorted list of log files, most recent first, and display it. If the selector is emtpy, show the most recent log file.
Perform the first pass at creating a list of log files.
If there are any log files with a filename that reflects a timestamp later than the current time, then it must be a randomly generated UUID from the official Node.js version of the topos-playground; pull the timestamp from the last modification time.
With a modest statistical probability of being wrong, this should be able to identify those logs which have accidentally created valid UUID timestamps that are too early in time to have been generated by this version of the playground. If the gap between them is greater than three times the standard deviation, it will use the file modification time instead of the timestamp.
Parse a size selector, which can be a number, or a number followed by a unit,
into a byte count. For example, 128b
or 10k or
1mor
4g`.
print the header for the sorted list of logs
There are two formats for the header, depending on whether the logs will be printed in single line format or multi-line format.
Print the sorted list of logs.
This is comprised of a header, and then a line for each log file. If the single-line format is too wide for the terminal, the multi-line format will be used. Regarding, though, line wrapping is still applied, so that everything stays relatively formatted, even on small terminal windows.