Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto
CHANGELOG.md merge=union
16 changes: 16 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[settings]

not_skip = __init__.py

multi_line_output = 3

known_standard_library = dataclasses,typing_extensions
known_third_party = click,log
known_first_party = log

combine_as_imports = true
force_grid_wrap = false
include_trailing_comma = true

lines_after_imports = 2
line_length = 88
4 changes: 3 additions & 1 deletion .pylint.ini
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ disable=
too-many-arguments,
too-many-branches,
unpacking-non-sequence,
global-statement,
wildcard-import,
unused-wildcard-import,
singleton-comparison,

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.5 (unreleased)

- Fixed `init()` to handle invalid `verbosity` levels and default to **DEBUG**.

# 1.4.1 (2020-03-22)

- Fixed new loggers to inherit the root logging level when their parent has none set.
Expand Down
80 changes: 80 additions & 0 deletions bin/update
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import importlib
import tempfile
import shutil
import subprocess
import sys

CWD = os.getcwd()
TMP = tempfile.gettempdir()
CONFIG = {
"full_name": "Jace Browning",
"email": "jacebrowning@gmail.com",
"github_username": "jacebrowning",
"github_repo": "minilog",
"default_branch": "develop",
"project_name": "minilog",
"package_name": "log",
"project_short_description": "Minimalistic wrapper for Python logging.",
"python_major_version": 3,
"python_minor_version": 6,
}


def install(package='cookiecutter'):
try:
importlib.import_module(package)
except ImportError:
print("Installing cookiecutter")
subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])


def run():
print("Generating project")

from cookiecutter.main import cookiecutter

os.chdir(TMP)
cookiecutter(
'https://github.com/jacebrowning/template-python.git',
no_input=True,
overwrite_if_exists=True,
extra_context=CONFIG,
)


def copy():
for filename in [
'.appveyor.yml',
'.coveragerc',
'.gitattributes',
'.gitignore',
'.isort.cfg',
'.mypy.ini',
'.pydocstyle.ini',
'.pylint.ini',
'.scrutinizer.yml',
'.travis.yml',
'.verchew.ini',
'CONTRIBUTING.md',
'Makefile',
os.path.join('bin', 'checksum'),
os.path.join('bin', 'open'),
os.path.join('bin', 'update'),
os.path.join('bin', 'verchew'),
'pytest.ini',
'scent.py',
]:
src = os.path.join(TMP, CONFIG['project_name'], filename)
dst = os.path.join(CWD, filename)
print("Updating " + filename)
shutil.copy(src, dst)


if __name__ == '__main__':
install()
run()
copy()
9 changes: 8 additions & 1 deletion docs/extras.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ To work with frameworks that provide a `verbosity` level in their CLI frameworks
log.init(format=…, verbosity=verbosity)
```

| Verbosity | Level |
|-----------|-------------|
| `0` | **ERROR** |
| `1` | **WARNING** |
| `2` | **INFO** |
| `3` | **DEBUG** |

### Silencing Loggers

To hide logging for specific named loggers:
Expand All @@ -51,5 +58,5 @@ log.init(…)
In addition to the standard [`LogRecord`](https://docs.python.org/3/library/logging.html#logrecord-attributes) attributes, the following additional patterns are available:

| Logging Format | Description |
| -------------- | ------------------------------------------------------------------------------------------------------------- |
|----------------|---------------------------------------------------------------------------------------------------------------|
| `%(relpath)s` | Full pathname of the source file where the logging call was issued relative to the current working directory. |
4 changes: 4 additions & 0 deletions docs/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
This package intends to be a drop-in replacement for `logging.Logger` objects. It supports the standard logging API:

```python
import log

log.debug(message, *args)
log.info(message, *args)
log.warning(message, *args)
Expand All @@ -17,6 +19,8 @@ log.log(level, message, *args)
As well as convenience methods:

```python
import log

log.warn(message, *args) # warning

log.d(message, *args) # debug
Expand Down
1 change: 1 addition & 0 deletions log/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .helpers import *
from .logger import *


WARN = WARNING

d = debug
Expand Down
6 changes: 5 additions & 1 deletion log/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from . import filters, state


__all__ = ['reset', 'init', 'silence']

VERBOSITY_TO_LEVEL = {
Expand Down Expand Up @@ -38,7 +39,10 @@ def init(*, debug=False, verbosity=None, **kwargs):
if debug:
state.default_level = logging.DEBUG
elif verbosity is not None:
state.default_level = VERBOSITY_TO_LEVEL[verbosity]
try:
state.default_level = VERBOSITY_TO_LEVEL[verbosity]
except KeyError:
state.default_level = logging.DEBUG

kwargs['level'] = kwargs.get('level', state.default_level)
kwargs['format'] = kwargs.get('format', state.default_format)
Expand Down
1 change: 1 addition & 0 deletions log/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from . import utils


__all__ = ['log', 'debug', 'info', 'warning', 'error', 'critical', 'exception']


Expand Down
1 change: 1 addition & 0 deletions log/state.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging


default_level = logging.INFO
default_format = "%(levelname)s: %(name)s: %(message)s"

Expand Down
5 changes: 5 additions & 0 deletions log/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def with_verbosity_3(config, expect):
helpers.init(format='%(message)s', verbosity=3)
expect(config.mock_calls) == [call(format='%(message)s', level=10)]

@patch('logging.basicConfig')
def with_verbosity_above_3(config, expect):
helpers.init(format='%(message)s', verbosity=4)
expect(config.mock_calls) == [call(format='%(message)s', level=10)]

@patch('logging.basicConfig')
def with_verbosity_0_and_debug(config, expect):
helpers.init(format='%(message)s', verbosity=0, debug=True)
Expand Down
52 changes: 27 additions & 25 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]

name = "minilog"
version = "1.4.1"
version = "1.5"
description = "Minimalistic wrapper for Python logging."

license = "MIT"
Expand Down Expand Up @@ -46,11 +46,11 @@ isort = "=4.3.21"
# Linters
pylint = "^2.0"
pydocstyle = "*"
mypy = "*"
mypy = "~0.761"

# Testing
pytest = "^5.3"
pytest-describe = "*"
pytest = "^5.4"
pytest-describe = { git = "https://github.com/jacebrowning/pytest-describe", branch = "pytest-5.4-support" }
pytest-expecter = "*"
pytest-repeat = "*"
pytest-random = "*"
Expand Down
2 changes: 1 addition & 1 deletion scent.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Options:
@select_runnable('run_targets')
@file_validator
def python_files(filename):
return filename.endswith('.py')
return filename.endswith('.py') and '.py.' not in filename


@select_runnable('run_targets')
Expand Down
1 change: 1 addition & 0 deletions tests/other.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging


log = logging.getLogger('3rd-party')


Expand Down