Skip to content

Commit

Permalink
Improve simple flag handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nir0s committed Mar 25, 2018
1 parent d0a3372 commit 772f10a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion wryte.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 772f10a

Please sign in to comment.