class ToposPlayground::Command::Logs

Defined in:

topos-playground/command/log.cr

Constant Summary

UUID_REGEXP = /([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})/

Class Method Summary

Instance Method Summary

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

def self.levenshtein_options #

[View source]
def self.list_options(parser, config) #

[View source]
def self.log_to_file?(config) #

[View source]
def self.options(parser, config) #

[View source]
def self.prune_options(parser, config) #

[View source]
def self.view_options(parser, config) #

[View source]

Instance Method Detail

def 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.


[View source]
def do_list #

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.


[View source]
def do_prune #

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.


[View source]
def do_prune_days(sorted_logs, selector) #

Delete log files older than the specified number of days.


[View source]
def do_prune_range(sorted_logs, selector) #

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.


[View source]
def do_prune_size(sorted_logs, selector) #

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.


[View source]
def 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.


[View source]
def do_view_after(sorted_logs, 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 later than the selector.


[View source]
def do_view_before(sorted_logs, 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.


[View source]
def 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. If the selector is emtpy, show the most recent log file.


[View source]
def generate_base_list : Array(Tuple(String, String, Time)) #

Perform the first pass at creating a list of log files.


[View source]
def 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.


[View source]
def 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. If the gap between them is greater than three times the standard deviation, it will use the file modification time instead of the timestamp.


[View source]
def multi_line_header(logs) #

Build the multi-line header.

 #                                             Log File Path
                  File Date                File Size

[View source]
def parse_to_size(selector) #

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 or1mor4g`.


[View source]
def print_header(logs) #

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.


[View source]
def print_logs(logs) #

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.


[View source]
def run #

Act on the log subcommand (list, view, or prune).


[View source]
def show_deletion_count(count) #

Output the number of deleted files.


[View source]
def show_log_file(log) #

Display the given log file.


[View source]
def single_line_header(logs) #

Build the single-line header.

#                                             Log File Path                                                             File Date                File Size

[View source]