Docs / Guides / Logging & Config

Platform 14–15 · Study guide

Logging & Config

Configure nested settings and write structured logs — including production config caching.

What you will learn
  • How Config.load / load_auto work
  • How to cache config for faster boots
  • How to write to log channels

1. Configuration setup

from tpy.config import Config

# Always parse tpy.toml + env
cfg = Config.load(".")

# Prefer JSON cache when TPY_CONFIG_CACHE=1 and cache is fresh
cfg = Config.load_auto(".")

print(cfg.get("app.name"))
print(cfg.get("database.driver"))
print(cfg.get("server.port", 8000))
cfg.set("cache.driver", "redis")  # runtime only
$ tpy config show
$ tpy config show app.name
$ tpy config cache
$ tpy config status
$ tpy config clear
$ set TPY_CONFIG_CACHE=1   # Windows

2. How config caching works

  1. tpy config cache writes storage/framework/config.cache.json.
  2. Cache is fresh only if newer than tpy.toml and .env.
  3. With TPY_CONFIG_CACHE=1, load_auto() reads the cache when fresh; otherwise it reloads live sources.

3. Logging setup

from tpy.logging import get_logger, LogManager

log = get_logger("app")
log.info("booted", version="0.1.9")

manager = LogManager()
manager.configure(level="INFO", log_dir="storage/logs", app_name="myapp")
manager.channel("stack").error("something failed")