-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from valentingol/logging
✨ Improve cliconfig logging
- Loading branch information
Showing
5 changed files
with
63 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright (c) 2023 Valentin Goldite. All Rights Reserved. | ||
"""Logging functions for cliconfig.""" | ||
import logging | ||
import sys | ||
from logging import Logger | ||
|
||
|
||
def create_logger() -> Logger: | ||
"""Create cliconfig logger.""" | ||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.INFO) | ||
handler = logging.StreamHandler(sys.stdout) | ||
formatter = logging.Formatter("%(levelname)s - %(message)s") | ||
handler.setFormatter(formatter) | ||
logger.addHandler(handler) | ||
return logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright (c) 2023 Valentin Goldite. All Rights Reserved. | ||
"""Tests for dict routines.""" | ||
import pytest | ||
import pytest_check as check | ||
|
||
from cliconfig._logger import create_logger | ||
|
||
|
||
def test_create_logger( | ||
caplog: pytest.CaptureFixture, | ||
capsys: pytest.CaptureFixture, | ||
) -> None: | ||
"""Test create_logger.""" | ||
logger = create_logger() | ||
logger.info("This is an info message.") | ||
check.is_true("INFO cliconfig._logger:test_logger.py:" in caplog.text) | ||
check.is_true(" This is an info message." in caplog.text) | ||
check.is_true("INFO - This is an info message." in capsys.readouterr().out) | ||
logger.warning("This is a warning message.") | ||
check.is_true("WARNING cliconfig._logger:test_logger.py:" in caplog.text) | ||
check.is_true(" This is a warning message." in caplog.text) | ||
check.is_true("WARNING - This is a warning message." in capsys.readouterr().out) |