Last active
April 26, 2022 09:19
-
-
Save Olgoetz/6188e39a03b21be9c670caed683ff0c6 to your computer and use it in GitHub Desktop.
AWS Lambda python logger that also works locally
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
import logging | |
import os | |
LOG_LEVEL = os.getenv('LOG_LEVEL', 'INFO').lower() | |
log_level_map = { | |
"info": logging.INFO, | |
"debug": logging.DEBUG, | |
"warning": logging.WARNING, | |
"error": logging.ERROR, | |
"critical": logging.CRITICAL | |
} | |
class Logger: | |
def __init__(self): | |
self._logger = logging.getLogger() | |
if self._logger.hasHandlers(): | |
self._logger.setLevel(level=log_level_map[LOG_LEVEL]) | |
else: | |
logging.basicConfig(level=log_level_map[LOG_LEVEL]) | |
@property | |
def getlogger(self): | |
return self._logger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment