generated from ansys/template
-
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.
Fixed a merge issue. Allowed server version to be set by the user via…
… the new changes, rather than always the latest version. Client used to raise 2 exceptions if Sherlock did not start. One was for sherlock not starting and another was that it was unable to connect to Sherlock. Now it will raise 1 exception. If Sherlock cannot start it will raise that exception. If Sherlock starts but PySherlock cannot connect it will raise that exception.
- Loading branch information
1 parent
f73d5cb
commit 1f52446
Showing
3 changed files
with
87 additions
and
95 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
126 changes: 63 additions & 63 deletions
126
src/ansys/sherlock/core/logging.py → ...ansys/sherlock/core/pysherlock_logging.py
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 |
---|---|---|
@@ -1,63 +1,63 @@ | ||
# © 2023 ANSYS, Inc. All rights reserved | ||
|
||
"""PySherlock logger.""" | ||
from datetime import datetime | ||
import logging | ||
from logging.handlers import TimedRotatingFileHandler | ||
import sys | ||
|
||
LOG_LEVEL = logging.DEBUG | ||
FILE_NAME = "PySherlock.log" | ||
|
||
# Formatting | ||
STDOUT_MSG_FORMAT = logging.Formatter("%(levelname)s - %(module)s - %(funcName)s - %(message)s") | ||
FILE_MSG_FORMAT = STDOUT_MSG_FORMAT | ||
|
||
DEFAULT_STDOUT_HEADER = """ | ||
LEVEL - INSTANCE NAME - MODULE - FUNCTION - MESSAGE | ||
""" | ||
DEFAULT_FILE_HEADER = DEFAULT_STDOUT_HEADER | ||
|
||
NEW_SESSION_HEADER = f""" | ||
=============================================================================== | ||
NEW SESSION - {datetime.now().strftime("%m/%d/%Y, %H:%M:%S")} | ||
===============================================================================""" | ||
|
||
|
||
def _get_console_handler(): | ||
console_handler = logging.StreamHandler(sys.stdout) | ||
console_handler.setFormatter(STDOUT_MSG_FORMAT) | ||
return console_handler | ||
|
||
|
||
def _get_file_handler(): | ||
file_handler = TimedRotatingFileHandler(FILE_NAME, when="midnight") | ||
file_handler.setFormatter(STDOUT_MSG_FORMAT) | ||
file_handler.stream.write(NEW_SESSION_HEADER) | ||
file_handler.stream.write(DEFAULT_FILE_HEADER) | ||
return file_handler | ||
|
||
|
||
def __get_logger(logger_name): | ||
return logging.get_logger(logger_name) | ||
|
||
|
||
class Logger: | ||
"""Provides the PySherlock logger.""" | ||
|
||
def __init__(self, logger_name, level=logging.WARN): | ||
"""Initialize logger.""" | ||
self.logger = logging.getLogger(logger_name) | ||
self.logger.setLevel(LOG_LEVEL) | ||
self.logger.addHandler(_get_console_handler()) | ||
self.logger.addHandler(_get_file_handler()) | ||
self.debug = self.logger.debug | ||
self.info = self.logger.info | ||
self.warning = self.logger.warning | ||
self.error = self.logger.error | ||
self.critical = self.logger.critical | ||
self.log = self.logger.log | ||
|
||
def setLevel(self, level): | ||
"""Set the logging level.""" | ||
self.logger.setLevel(level) | ||
# © 2023 ANSYS, Inc. All rights reserved | ||
|
||
"""PySherlock logger.""" | ||
from datetime import datetime | ||
import logging | ||
from logging.handlers import TimedRotatingFileHandler | ||
import sys | ||
|
||
LOG_LEVEL = logging.DEBUG | ||
FILE_NAME = "PySherlock.log" | ||
|
||
# Formatting | ||
STDOUT_MSG_FORMAT = logging.Formatter("%(levelname)s - %(module)s - %(funcName)s - %(message)s") | ||
FILE_MSG_FORMAT = STDOUT_MSG_FORMAT | ||
|
||
DEFAULT_STDOUT_HEADER = """ | ||
LEVEL - INSTANCE NAME - MODULE - FUNCTION - MESSAGE | ||
""" | ||
DEFAULT_FILE_HEADER = DEFAULT_STDOUT_HEADER | ||
|
||
NEW_SESSION_HEADER = f""" | ||
=============================================================================== | ||
NEW SESSION - {datetime.now().strftime("%m/%d/%Y, %H:%M:%S")} | ||
===============================================================================""" | ||
|
||
|
||
def _get_console_handler(): | ||
console_handler = logging.StreamHandler(sys.stdout) | ||
console_handler.setFormatter(STDOUT_MSG_FORMAT) | ||
return console_handler | ||
|
||
|
||
def _get_file_handler(): | ||
file_handler = TimedRotatingFileHandler(FILE_NAME, when="midnight") | ||
file_handler.setFormatter(STDOUT_MSG_FORMAT) | ||
file_handler.stream.write(NEW_SESSION_HEADER) | ||
file_handler.stream.write(DEFAULT_FILE_HEADER) | ||
return file_handler | ||
|
||
|
||
def __get_logger(logger_name): | ||
return logging.get_logger(logger_name) | ||
|
||
|
||
class Logger: | ||
"""Provides the PySherlock logger.""" | ||
|
||
def __init__(self, logger_name, level=logging.WARN): | ||
"""Initialize logger.""" | ||
self.logger = logging.getLogger(logger_name) | ||
self.logger.setLevel(LOG_LEVEL) | ||
self.logger.addHandler(_get_console_handler()) | ||
self.logger.addHandler(_get_file_handler()) | ||
self.debug = self.logger.debug | ||
self.info = self.logger.info | ||
self.warning = self.logger.warning | ||
self.error = self.logger.error | ||
self.critical = self.logger.critical | ||
self.log = self.logger.log | ||
|
||
def setLevel(self, level): | ||
"""Set the logging level.""" | ||
self.logger.setLevel(level) |