Skip to main content

Logging to stderr and file for click applications.

Project description

click_loguru initializes click CLI-based programs for logging to stderr and (optionally) a log file via the loguru logger.

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.

Instantiation

click_loguru objects are instantiated from the ClickLoguru class as:

click_loguru = ClickLoguru(name,
                           version,
                           retention=4,
                           stderr_format_func=None,
                           log_dir_parent="./logs",
                           file_log_level="DEBUG",
                           stderr_log_level="INFO",
  )

where:

  • name is the name of your application

  • version is the version string of your application

  • retention is the log file retention policy. If set to a non-zero value, the log files will be given by logs/NAME[-SUBCOMMAND]_n.log where `NAME is the name of your application, SUBCOMMAND is the group subcommand (if you are using click groups), and n is an integer number. The value of retention specifies the number of log files to be kept.

  • stderr_format_func is the format function to be used for messages to stderr, as defined by loguru. Default is very short, with INFO-level messages having no level name printed.

  • log_dir_parent sets the location of the log file directory. This value may be overridden per-command.

  • file_log_level sets the level of logging to the log file.

  • stderr_log_level sets the level of logging to stderr. This value may be overridden by the --quiet or --verbose options.

Methods

The ClickLoguru class defines the following methods:

  • logging_options is a decorator to be used for your application’s CLI function. This decorator defines the global options that allows control of quiet, verbose, and log file booleans.

  • stash_subcommand is a decorator to be used for the CLI method for applications which define subcommands.

  • init_logger is a decorator which must be used for each subcommand. It allows override of the default log_dir_parent established at instantiation, as well as turning off file logging for that command by setting log file to False.

  • log_elapsed_time is a decorator which causes the elapsed time for the (sub)command to be emitted at the DEBUG level.

  • get_global_options is 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 booleans verbose, quiet, and log file, the string subcommand showing the subcommand that was invoked, and log file_handler_id if your code wishes to manipulate the handler directly.

See the simple test CLI application for usage examples.

Prerequisites

Python 3.6 or greater is required. This package is tested under Linux using Python 3.8. This package has no dependencies beyond``click`` and loguru themselves.

Project Status

Latest Release

Python package

Activity

GitHub repository

Downloads

Download stats

Download Rate

Download stats

License

License terms

Travis Build

Travis CI

Coverage

Codecov.io test coverage

Code Grade

Codacy.io grade

Dependencies

dependabot dependencies

Issues

Issues reported

Code Style

Black is the uncompromising Python code formatter

Pre-commit

pre-commit

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

click_loguru-1.0.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

click_loguru-1.0.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file click_loguru-1.0.0.tar.gz.

File metadata

  • Download URL: click_loguru-1.0.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.9 CPython/3.8.3 Linux/5.7.6-gentoo-x86_64

File hashes

Hashes for click_loguru-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d2ed4c6602052fae3f29e8fb866bbfde3af45726bfa7ac1ad46d5e1914361ba5
MD5 31ac2857b0e9ac7c892664b369e8ecd6
BLAKE2b-256 e56538d30f3c58d65af2bd7c3e871f4cf2706d499ee419c81e06bb4557ed9491

See more details on using hashes here.

File details

Details for the file click_loguru-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: click_loguru-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.9 CPython/3.8.3 Linux/5.7.6-gentoo-x86_64

File hashes

Hashes for click_loguru-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6af3d28232092141af5313ee035bfb37688b605c37be58cc2518726df4be17a9
MD5 3db2cbbddd0033b5007c05f43b8d0e23
BLAKE2b-256 5ce7ccc2f1a88caa92bf5ec1a51d6f05c0c7fd83fb40bd96ae6868b10b23826d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page