-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: use own logger, not global logger #10
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
01987a6
Don't let our logging calls mess with the root logger
kroeschl e1adaf3
Correct indentation error
kroeschl d5f59ef
const as UPPERCASE, logger for wanrings, documentation
jkowalleck 44d8ab9
Merge remote-tracking branch 'origin/main' into logging-no-global
jkowalleck d565418
suppress mypy for py3.7
jkowalleck 0da6a35
fix tests
jkowalleck 9ee1f3a
style
jkowalleck 2443d31
Merge remote-tracking branch 'origin/main' into logging-no-global
jkowalleck 96893f4
style
jkowalleck 1fdc9a6
log compatibility
jkowalleck e3c8c5f
fix compat
jkowalleck 190c775
refactor logger declaration in protected, make still public API
jkowalleck 117e94c
reformat docs
jkowalleck 1b39831
fix tests
jkowalleck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ See also: | |
getting-started | ||
customising-structure | ||
formatters | ||
logging | ||
support | ||
changelog | ||
|
||
|
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,39 @@ | ||
Logging | ||
==================================================== | ||
|
||
This library utilizes an own instance of `Logger`_, which you may access and add handlers to. | ||
|
||
.. _logger: https://docs.python.org/3/library/logging.html#logger-objects | ||
|
||
|
||
.. code-block:: python | ||
:caption: Example: send all logs messages to the console | ||
|
||
import sys | ||
import logging | ||
import serializable | ||
|
||
my_log_handler = logging.StreamHandler(sys.stderr) | ||
my_log_handler.setLevel(logging.DEBUG) | ||
my_log_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) | ||
serializable.LOGGER.addHandler(my_log_handler) | ||
|
||
|
||
@serializable.serializable_class | ||
class Chapter: | ||
|
||
def __init__(self, *, number: int, title: str) -> None: | ||
self._number = number | ||
self._title = title | ||
|
||
@property | ||
def number(self) -> int: | ||
return self._number | ||
|
||
@property | ||
def title(self) -> str: | ||
return self._title | ||
|
||
|
||
moby_dick_c1 = Chapter(number=1, title='Loomings') | ||
print(moby_dick_c1.as_json()) |
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,27 @@ | ||
# encoding: utf-8 | ||
|
||
# This file is part of py-serializable | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright (c) Paul Horton. All Rights Reserved. | ||
|
||
import logging | ||
from sys import version_info | ||
|
||
_LOGGER = logging.getLogger(f'{__name__}.LOGGER') | ||
_LOGGER.setLevel(logging.DEBUG) | ||
|
||
# logger.warning() got additional kwarg since py38 | ||
_warning_kwargs = {'stacklevel': 2} if version_info >= (3, 8) else {} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌
bring back
logger
and mark it as deprecated.even though
logger
was not used for any logging in the past, it still was public API.but all UPPERCASE is preferred to point downstream users to the fact, that is a readonly/constant value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or leave as is and consider it a breaking change -- which is okay for a planned v1.0.0