-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add base logger to enable debug logging
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import logging | ||
|
||
|
||
class BaseLogger: | ||
|
||
def __init__(self, log_level=logging.CRITICAL): | ||
self._logger = logging.getLogger("google") | ||
self._logger.setLevel(log_level) | ||
console_handler = logging.StreamHandler() | ||
console_handler.setLevel(log_level) | ||
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") | ||
console_handler.setFormatter(formatter) | ||
self._logger.addHandler(console_handler) | ||
|
||
def get_logger(self): | ||
return self._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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import logging | ||
import pytest | ||
|
||
from google.api_core.client_logging import BaseLogger | ||
|
||
|
||
def test_base_logger(caplog): | ||
|
||
logger = BaseLogger().get_logger() | ||
|
||
with caplog.at_level(logging.INFO, logger="google"): | ||
logger.info("This is a test message.") | ||
|
||
assert "This is a test message." in caplog.text | ||
assert caplog.records[0].name == "google" | ||
assert caplog.records[0].levelname == "INFO" | ||
assert caplog.records[0].message == "This is a test message." |