Package: click-loguru
click_loguruinitializesclickCLI-based
programs for logging via thelogurulogger.
It can optionally log to a log file with a logfile-retention policy and with command-line
arguments captured.  It can also optionally log run time, CPU use, and peak memory use of
user CLI functions.Log file names will include the name of your program and (if your application uses
subcommands via@click.group()), the name of the subcommand. Log files are
(optionally) numbered, with a retention policy specified.  Log files can be
enabled or disabled per-subcommand and written to a subdirectory that your
application specifies.Global CLI options control verbose/quiet levels and log file creation.
The values of these global options are accessible, along with the path to the
log file, from your application.Instantiationclick_loguruobjects are instantiated from theClickLoguruclass as:click_loguru = ClickLoguru(name,
                           version,
                           retention=4,
                           stderr_format_func=None,
                           log_dir_parent="./logs",
                           file_log_level="DEBUG",
                           stderr_log_level="INFO",
                           timer_log_level="debug",
  )where:nameis the name of your applicationversionis the version string of your applicationretentionis the log file retention policy.  If set to a non-zero value, the
log files will be given bylogs/NAME[-SUBCOMMAND]_n.logwhere`NAMEis the name
of your application,SUBCOMMANDis the group subcommand (if you are using
click groups), andnis an integer number.  The value ofretentionspecifies
the number of log files to be kept.stderr_format_funcis the format function to be used for messages to stderr, as
defined byloguru.  Default is very short, withINFO-level messages having
no level name printed.log_dir_parentsets the location of the log file directory.  This value may be
overridden per-command.file_log_levelsets the level of logging to the log file.stderr_log_levelsets the level of logging to stderr.  This value may be overridden
by the--quietor--verboseoptions.timer_log_levelis the level at whichelapsed_timeresults will be logged.MethodsTheClickLoguruclass defines the following methods:logging_optionsis a decorator to be used for your application’s CLI function.  This
decorator defines the global options that allows control ofquiet,verbose,
andlog filebooleans.stash_subcommandis a  decorator to be used for the CLI method for applications
which define subcommands.init_loggeris  a decorator which must be used for each subcommand.   It allows
override of the defaultlog_dir_parentestablished at instantiation,
as well as turning off file logging for that command by settinglog filetoFalse.log_elapsed_timeis a decorator which causes the elapsed wall-clock time and
CPU time in seconds for the (sub)command
to be emitted at the level specified by thelevel=argument (debugby default).get_global_optionsis a method that returns the context object associated with the
global options. The context object is printable.  The attributes of the context object are the booleansverbose,quiet, andlog file, the stringsubcommandshowing the subcommand that was invoked,
andlog file_handler_idif your code wishes to manipulate the handler directly.user_global_options_callbackis a method to be used as
a callback when your code declares a global option.  Values
of these global options will be stored in a user global
options context dictionary.get_user_global_optionsis a method to retrieve a
dictionary of values of user global options.elapsed_timeris a method that accepts a single argument,phase.
The next invocation of this method will produce a log entry attimer_log_levelshowing the elapsed wall clock and CPU time.  IfphaseisNone,
the next invocation will not produce a message.log_peak_memory_useis a method that results in the peak memory usage for
the function and children of the function to be emitted at a level specified
by thelevel=keyword (debugis default).  This functionality
is somewhat expensive in that it requires an additional thread, so the global
option--profile_memmust be enabled.See thesimple test CLI applicationfor usage examples.PrerequisitesPython 3.6 or greater is required.
This package is tested under Linux, MacOS, and Windows using Python 3.9.