Skip to content

Commit c991e5b

Browse files
feat: Using an environment variable to configure logging to a file
1 parent ac21a1d commit c991e5b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

main.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,19 @@
1111
from atlassian.adf import AtlassianDocumentFormatBuilder
1212
from utils.utils import Utils
1313

14-
logging.basicConfig()
15-
logger = logging.getLogger(__name__)
14+
# Setting up the logging level from the environment variable `LOGLEVEL`.
15+
if 'LOG_FILENAME' in environ.keys():
16+
logging.basicConfig(
17+
filename=environ['LOG_FILENAME'],
18+
filemode='a',
19+
format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
20+
datefmt='%H:%M:%S'
21+
)
22+
logger = logging.getLogger(__name__)
23+
else:
24+
logging.basicConfig()
25+
logger = logging.getLogger(__name__)
26+
1627
logger.setLevel(environ['LOG_LEVEL'] if 'LOG_LEVEL' in environ.keys() else 'INFO')
1728

1829
def main():

0 commit comments

Comments
 (0)