{"id":9372,"library":"twiggy","title":"Twiggy","description":"Twiggy is a Pythonic logging library that emphasizes structured logging and a fluid, method-chaining API. It aims to be more \"Pythonic\" than the standard library's `logging` module. The current version is 0.5.1, released on May 12, 2021. The library has a slow release cadence and is marked by its maintainers as \"not rock solid (yet)\", suggesting it is in a maintenance status rather than active, rapid development.","status":"maintenance","version":"0.5.1","language":"en","source_language":"en","source_url":"https://github.com/wearpants/twiggy/","tags":["logging","logger","structured-logging"],"install":[{"cmd":"pip install Twiggy","lang":"bash","label":"Install latest stable version"}],"dependencies":[],"imports":[{"note":"Commonly imported alongside 'log' for initial configuration.","wrong":"import twiggy.quick_setup","symbol":"quick_setup","correct":"from twiggy import quick_setup"},{"note":"The primary logger instance. Often used after calling quick_setup().","wrong":"import twiggy.log","symbol":"log","correct":"from twiggy import log"},{"note":"Output classes reside in the `twiggy.outputs` submodule.","wrong":"from twiggy import FileOutput","symbol":"FileOutput","correct":"from twiggy.outputs import FileOutput"}],"quickstart":{"code":"from twiggy import quick_setup, log\n\n# Configure a basic console output\nquick_setup()\n\n# Log a message with structured fields\nlog.name('my_app').fields(user_id=123).info(\"User {user_id} logged in from {ip}\", ip=\"192.168.1.100\")\n\n# Log a warning message\nlog.warning(\"Something unusual happened, but it's not critical.\")\n\n# Using the NOTICE level (added in 0.5.0)\nlog.notice(\"Heads up: An important event occurred.\")","lang":"python","description":"This quickstart demonstrates how to initialize Twiggy with default settings (console output) using `quick_setup()` and then log messages with bound names, structured fields, and different severity levels using the global `log` object. Twiggy supports `str.format()` style string formatting."},"warnings":[{"fix":"Evaluate suitability for your project's reliability requirements. Consider more mature logging solutions for high-stakes systems.","message":"The official documentation states, 'Twiggy works great, but is not rock solid (yet); do not use for nuclear power plants, spaceships or mortgage derivatives trading.' This suggests caution for mission-critical applications.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the 0.5.0 changelog and API documentation to identify and update usage of any deprecated features. Review the `logging_compat` module if transitioning from standard library logging.","message":"Version 0.4.1's changelog mentions \"deprecate features, pending a rewrite in 0.5\". Users upgrading from versions prior to 0.5.0 that relied on these deprecated features may experience breakage.","severity":"breaking","affected_versions":"0.4.1 -> 0.5.x"},{"fix":"Always ensure `from twiggy import quick_setup, log` and `quick_setup()` are at the start of your application, or use `twiggy.setup()` for more granular control.","message":"Twiggy's `log` object needs to be imported (`from twiggy import log`) and often `quick_setup()` needs to be called to configure basic output before logging messages. Forgetting these steps leads to errors or no output.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Add `from twiggy import quick_setup, log` at the top of your file, and ensure `quick_setup()` is called once early in your application's lifecycle.","cause":"The global 'log' object or 'quick_setup' function was used without being imported, or the `quick_setup()` function was not called to initialize the logging system.","error":"NameError: name 'log' is not defined"},{"fix":"Use a logging level method on the `log` object, e.g., `log.info(\"Your message here\")`, `log.debug(\"Another message\")`, etc.","cause":"Attempting to call the `log` object directly like a function (`log(\"message\")`) instead of calling one of its level-specific methods (e.g., `log.info()`, `log.warning()`).","error":"TypeError: 'Message' object is not callable"},{"fix":"Twiggy primarily uses `str.format()` style. Ensure your format string (`\"hello {who}\"`) matches the arguments (`who='world'`) and avoid mixing with C-style `%` formatting.","cause":"Mixing up string formatting styles (e.g., using old-style `%` formatting with `str.format()` placeholders, or vice-versa).","error":"SyntaxError: invalid syntax (related to string formatting in log messages)"}]}