Examples#

The runnable demo script in the repository lives at examples/usage.py.

Console And File Output#

import tuning

tuning.basicConfig(
    filename="app.log",
    console=True,
    level="INFO",
    show_time=True,
    datefmt=tuning.ISO_FORMAT,
)

logger = tuning.getLogger(__name__)
logger.info("application started")

Rotating File Logs#

import tuning

tuning.basicConfig(
    filename="app.log",
    level="INFO",
    max_bytes="10 MB",
    backup_count=5,
)

logger = tuning.getLogger(__name__)
logger.info("rotating file output")

Boxed Console Records#

import tuning

tuning.basicConfig(level="INFO", boxes=True, show_icon=True)

logger = tuning.getLogger(__name__)
logger.success("boxed output")

Styled Prompt#

import tuning

logger = tuning.getLogger(__name__)
name = logger.prompt("Your name?")
logger.info("hello %s", name)

App Banner#

Create a banners.txt file in your project:

### compact
TUNING

Print a named banner, or omit name to select a random banner that fits the terminal width:

import tuning

tuning.banner(name="compact")

Customize the Rich panel style, background, box, padding, or remove the border:

import tuning

tuning.banner(
    name="compact",
    border_style="bright_cyan",
    text_style="bold bright_magenta",
    background_style="on black",
    padding=(0, 2),
    box="HEAVY",
)

tuning.banner(name="compact", border=False, padding=(1, 4))

YAML Configuration#

Export a full starter config:

import tuning

tuning.export("tuning.yml")

Use a small override file:

handlers:
  console:
    level: DEBUG
    show_time: true
    show_path: true
    show_icon: true

root:
  level: DEBUG

Load YAML configuration:

import tuning

tuning.basicConfigFromYaml("tuning.yml", force=True)

logger = tuning.getLogger(__name__)
logger.info("configured from YAML")