Skip to content
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

Fix logger config #313

Merged
merged 9 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ All notable changes to the Zowe Client Python SDK will be documented in this fil

- Fixed a bug on `create` in `Datasets` where the target dataset gets created with a different block size when `like` is specified [#295] (https://github.com/zowe/zowe-client-python-sdk/issues/295)

- Fixed a bug on `logger` that it would affect all Python application loggers.

## `1.0.0-dev17`

### Enhancements
Expand Down
12 changes: 5 additions & 7 deletions src/core/zowe/core_for_zowe_sdk/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ class Log:

os.makedirs(dirname, exist_ok=True)

logging.basicConfig(
filename=os.path.join(dirname, "python_sdk_logs.log"),
level=logging.INFO,
format="[%(asctime)s] [%(levelname)s] [%(name)s] - %(message)s",
datefmt="%m/%d/%Y %I:%M:%S %p",
)

loggers = set()

@staticmethod
Expand All @@ -40,6 +33,11 @@ def registerLogger(name: str):
A Logger object named after the file where it is created
"""
logger = logging.getLogger(name)
file_handler = logging.FileHandler(os.path.join(Log.dirname, "python_sdk_logs.log"))
file_handler.setLevel(logging.INFO)
formatter = logging.Formatter("[%(asctime)s] [%(levelname)s] [%(name)s] - %(message)s", "%m/%d/%Y %I:%M:%S %p")
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
Log.loggers.add(logger)
return logger

Expand Down
1 change: 1 addition & 0 deletions tests/unit/core/test_profile_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def setUp(self):
self.original_nested_file_path = os.path.join(FIXTURES_PATH, "nested.zowe.config.json")
self.original_nested_user_file_path = os.path.join(FIXTURES_PATH, "nested.zowe.config.user.json")
self.original_schema_file_path = os.path.join(FIXTURES_PATH, "zowe.schema.json")
self.fs.create_dir(os.path.join(os.path.expanduser("~"), ".zowe/logs"))

loader = importlib.util.find_spec("jsonschema")
module_path = loader.origin
Expand Down
Loading