This repository has been archived by the owner on May 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
botlog.py
61 lines (52 loc) · 1.95 KB
/
botlog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# botlog.py
#
# Copyright © 2018 Antergos
#
# Antergos Bot is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Antergos Bot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# The following additional terms are in effect as per Section 7 of the license:
#
# The preservation of all legal notices and author attributions in
# the material or in the Appropriate Legal Notices displayed
# by works containing it is required.
#
# You should have received a copy of the GNU General Public License
# along with Antergos Bot; if not, see <http://www.gnu.org/licenses/>.
""" Configure logs for Antergos Bot """
import logging
def setup_logging():
""" Configure our logger """
logger = logging.getLogger()
logger.handlers = []
#log_level = logging.DEBUG
log_level = logging.INFO
logger.setLevel(log_level)
# Log format
formatter = logging.Formatter(
fmt="%(asctime)s [%(levelname)s] %(filename)s(%(lineno)d) %(funcName)s(): %(message)s",
datefmt="%Y-%m-%d %H:%M:%S")
# File logger
try:
file_handler = logging.FileHandler('/tmp/antergos-bot.log', mode='w')
file_handler.setLevel(log_level)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
except PermissionError as permission_error:
print("Can't open /tmp/antergos-bot.log : ", permission_error)
# Stdout logger
# Show log messages to stdout
stream_handler = logging.StreamHandler()
stream_handler.setLevel(log_level)
stream_handler.setFormatter(formatter)
logger.addHandler(stream_handler)