From 772f10a2d4d9b24a4ca70ac70f316abb4e05f8c4 Mon Sep 17 00:00:00 2001 From: nir0s Date: Sun, 25 Mar 2018 17:58:53 +0300 Subject: [PATCH] Improve simple flag handling --- README.md | 4 ++-- wryte.py | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index dcf101d..4a01ed1 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Wryte [![Code Quality](https://landscape.io/github/nir0s/wryte/master/landscape.svg?style=flat)](https://landscape.io/github/nir0s/wryte) [![Is Wheel](https://img.shields.io/pypi/wheel/wryte.svg?style=flat)](https://pypi.python.org/pypi/wryte) -Wryte aims to provide a simple API for logging in Python adhering to logging principles fitting today's systems. +Wryte aims to provide a simple API for logging in Python adhering to logging principles fitting today's systems. Note that the following documentation relates to the code currently in the master branch. If you want to view docs for previous versions, please choose the relevant release in the "releases" tab. @@ -163,7 +163,7 @@ An event is technically distinguished from a log by having a `{ 'type': 'event' ### Wryting a simple log to the console -By default, Wryte will output `TIMESTAMP - LEVEL - LOGGER_NAME - MESSAGE` (and the provided key=value pairs) to the console. Many CLI applications log only the message (e.g. `pip`). You can configure Wryte to do so by either setting the `WRYTE_SIMPLE_CONSOLE` env var or by passing the `simple` flag when instantiating the logger: +By default, Wryte will output `TIMESTAMP - LEVEL - LOGGER_NAME - MESSAGE` (and the provided key=value pairs) to the console. Many CLI applications log only the message (e.g. `pip`). You can configure Wryte to do so by either passing the `simple` flag or by setting the `WRYTE_SIMPLE_CONSOLE` env var to "true" (any other value will explicitly set `false` even if the flag is passed) when instantiating the logger: ```python wryter = Wryte(simple=True) diff --git a/wryte.py b/wryte.py index 9cf33a5..e11b5b6 100644 --- a/wryte.py +++ b/wryte.py @@ -73,7 +73,13 @@ class ConsoleFormatter(logging.Formatter): def __init__(self, pretty=True, color=True, simple=False): self.pretty = pretty self.color = color - self.simple = simple or os.getenv('WRYTE_SIMPLE_CONSOLE') + + _simple = os.getenv('WRYTE_SIMPLE_CONSOLE') + + if _simple is not None: + self.simple = True if _simple == "true" else False + else: + self.simple = simple @staticmethod def _get_level_color(level):