-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c10b78
commit 2c328d1
Showing
7 changed files
with
132 additions
and
10 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
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,7 @@ | ||
from dapr.ext.workflow.logger.options import LoggerOptions | ||
from dapr.ext.workflow.logger.logger import Logger | ||
|
||
__all__ = [ | ||
'LoggerOptions', | ||
'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,37 @@ | ||
import logging | ||
from typing import Union | ||
from dapr.ext.workflow.logger.options import LoggerOptions | ||
|
||
|
||
class Logger: | ||
def __init__(self, | ||
name: str, | ||
options: Union[LoggerOptions, None] = None): | ||
# If options is None, then create a new LoggerOptions object | ||
if options is None: | ||
options = LoggerOptions() | ||
log_handler = options.log_handler | ||
log_handler.setLevel(options.log_level) | ||
log_handler.setFormatter(options.log_formatter) | ||
logger = logging.getLogger(name) | ||
logger.handlers.append(log_handler) | ||
self._logger_options = options | ||
self._logger = logger | ||
|
||
def get_options(self) -> LoggerOptions: | ||
return self._logger_options | ||
|
||
def debug(self, msg, *args, **kwargs): | ||
self._logger.debug(msg, *args, **kwargs) | ||
|
||
def info(self, msg, *args, **kwargs): | ||
self._logger.info(msg, *args, **kwargs) | ||
|
||
def warning(self, msg, *args, **kwargs): | ||
self._logger.warning(msg, *args, **kwargs) | ||
|
||
def error(self, msg, *args, **kwargs): | ||
self._logger.error(msg, *args, **kwargs) | ||
|
||
def critical(self, msg, *args, **kwargs): | ||
self._logger.critical(msg, *args, **kwargs) |
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,40 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Copyright 2023 The Dapr Authors | ||
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. | ||
""" | ||
|
||
from typing import Union | ||
import logging | ||
|
||
|
||
class LoggerOptions: | ||
def __init__( | ||
self, | ||
log_level: Union[str, None] = None, | ||
log_handler: Union[logging.Handler, None] = None, | ||
log_formatter: Union[logging.Formatter, None] = None, | ||
): | ||
# Set default log level to INFO if none is provided | ||
if log_level is None: | ||
log_level = logging.INFO | ||
# Add a default log handler if none is provided | ||
if log_handler is None: | ||
log_handler = logging.StreamHandler() | ||
# Set a default log formatter if none is provided | ||
if log_formatter is None: | ||
log_formatter = logging.Formatter( | ||
fmt="%(asctime)s.%(msecs)03d %(name)s %(levelname)s: %(message)s", | ||
datefmt='%Y-%m-%d %H:%M:%S') | ||
self.log_level = log_level | ||
self.log_handler = log_handler | ||
self.log_formatter = log_formatter |
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