Skip to content

Commit 1e1a0e4

Browse files
committed
Rename colorlog.logging to colorlog.wrappers
1 parent 729c0bd commit 1e1a0e4

4 files changed

Lines changed: 75 additions & 47 deletions

File tree

colorlog/__init__.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,32 @@
33
import sys
44
import warnings
55

6-
from logging import (
7-
CRITICAL,
8-
FATAL,
9-
ERROR,
10-
WARNING,
11-
WARN,
12-
INFO,
13-
DEBUG,
14-
NOTSET,
15-
)
16-
176
from colorlog.formatter import (
18-
default_log_colors,
197
ColoredFormatter,
208
LevelFormatter,
219
TTYColoredFormatter,
10+
default_log_colors,
2211
)
23-
24-
from colorlog.logging import (
12+
from colorlog.wrappers import (
13+
CRITICAL,
14+
DEBUG,
15+
ERROR,
16+
FATAL,
17+
INFO,
18+
NOTSET,
19+
StreamHandler,
20+
WARN,
21+
WARNING,
2522
basicConfig,
26-
root,
27-
getLogger,
28-
log,
23+
critical,
2924
debug,
30-
info,
31-
warning,
3225
error,
3326
exception,
34-
critical,
35-
StreamHandler,
27+
getLogger,
28+
info,
29+
log,
30+
root,
31+
warning,
3632
)
3733

3834
__all__ = (

colorlog/tests/test_logging.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

colorlog/tests/test_wrappers.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""Test the colorlog.wrappers module."""
2+
3+
import logging
4+
5+
import colorlog
6+
7+
8+
def test_logging_module(test_logger):
9+
test_logger(logging)
10+
11+
12+
def test_colorlog_module(test_logger):
13+
test_logger(colorlog)
14+
15+
16+
def test_colorlog_basicConfig(test_logger):
17+
colorlog.basicConfig()
18+
test_logger(colorlog.getLogger())
19+
20+
21+
def test_reexports():
22+
assert colorlog.root is logging.root
23+
assert colorlog.getLogger is logging.getLogger
24+
assert colorlog.StreamHandler is logging.StreamHandler
25+
26+
assert colorlog.CRITICAL is logging.CRITICAL
27+
assert colorlog.FATAL is logging.FATAL
28+
assert colorlog.ERROR is logging.ERROR
29+
assert colorlog.WARNING is logging.WARNING
30+
assert colorlog.WARN is logging.WARN
31+
assert colorlog.INFO is logging.INFO
32+
assert colorlog.DEBUG is logging.DEBUG
33+
assert colorlog.NOTSET is logging.NOTSET
34+
35+
36+
def test_wrappers():
37+
assert colorlog.debug is not logging.debug
38+
assert colorlog.info is not logging.info
39+
assert colorlog.warning is not logging.warning
40+
assert colorlog.error is not logging.error
41+
assert colorlog.critical is not logging.critical
42+
assert colorlog.log is not logging.log
43+
assert colorlog.exception is not logging.exception
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,29 @@
33
import functools
44
import logging
55
import typing
6+
from logging import (
7+
CRITICAL,
8+
DEBUG,
9+
ERROR,
10+
FATAL,
11+
INFO,
12+
NOTSET,
13+
StreamHandler,
14+
WARN,
15+
WARNING,
16+
getLogger,
17+
root,
18+
)
619

720
import colorlog.formatter
821

9-
BASIC_FORMAT = "%(log_color)s%(levelname)s%(reset)s:%(name)s:%(message)s"
10-
1122

1223
def basicConfig(
1324
style: str = "%",
1425
log_colors: typing.Optional[colorlog.formatter.LogColors] = None,
1526
reset: bool = True,
1627
secondary_log_colors: typing.Optional[colorlog.formatter.SecondaryLogColors] = None,
17-
format: str = BASIC_FORMAT,
28+
format: str = "%(log_color)s%(levelname)s%(reset)s:%(name)s:%(message)s",
1829
datefmt: typing.Optional[str] = None,
1930
**kwargs
2031
) -> None:
@@ -39,7 +50,7 @@ def basicConfig(
3950

4051

4152
def ensure_configured(func):
42-
"""Modify a function to call ``basicConfig`` first if no handlers exist."""
53+
"""Modify a function to call our basicConfig() first if no handlers exist."""
4354

4455
@functools.wraps(func)
4556
def wrapper(*args, **kwargs):
@@ -50,14 +61,10 @@ def wrapper(*args, **kwargs):
5061
return wrapper
5162

5263

53-
root = logging.root
54-
getLogger = logging.getLogger
5564
debug = ensure_configured(logging.debug)
5665
info = ensure_configured(logging.info)
5766
warning = ensure_configured(logging.warning)
5867
error = ensure_configured(logging.error)
5968
critical = ensure_configured(logging.critical)
6069
log = ensure_configured(logging.log)
6170
exception = ensure_configured(logging.exception)
62-
63-
StreamHandler = logging.StreamHandler

0 commit comments

Comments
 (0)