Setting up logging
Setting up logging, update README.md
This commit is contained in:
parent
f939fe5b3d
commit
75c18b9bb3
10
README.md
10
README.md
@ -1,2 +1,8 @@
|
||||
# foBot
|
||||
A simple bot for discord
|
||||
# FoBot #
|
||||
|
||||
FoBot is a simple discord bot created by non professional to practice programming skill. It is written in [Python](http://python.org "Python") and use the rewrited version of the lib [discord.py](https://github.com/Rapptz/discord.py/tree/rewrite "Discord.py-rewrite"). For the moment there isn't an official support server and the bot is not fully functional.
|
||||
|
||||
## Configuration ##
|
||||
|
||||
### For user who want an sms on error ###
|
||||
You need to be a [free](https://free.fr "free") client. In the file `config_sms.py` you have to put your user id and your password.
|
9
SMSHandler.py
Normal file
9
SMSHandler.py
Normal file
@ -0,0 +1,9 @@
|
||||
import logging
|
||||
import urllib
|
||||
|
||||
import config_sms
|
||||
|
||||
class SMSHandler(logging.Handler):
|
||||
def emit(self, record):
|
||||
msg = urllib.parse.quote(self.format(record).encode('utf8'))
|
||||
urllib.request.urlopen("https://smsapi.free-mobile.fr/sendmsg?user=" + config_sms.user + "&pass=" + config_sms.password + "&msg=" + msg)
|
2
config_sms.py
Normal file
2
config_sms.py
Normal file
@ -0,0 +1,2 @@
|
||||
user = ""
|
||||
password = ""
|
30
main.py
Normal file
30
main.py
Normal file
@ -0,0 +1,30 @@
|
||||
import json
|
||||
import logging
|
||||
import logging.config
|
||||
import os
|
||||
|
||||
def setup_logging(default_path='log_config.json', default_level=logging.INFO, env_key='LOG_CFG', sms=True):
|
||||
"""Setup logging configuration
|
||||
"""
|
||||
path = default_path
|
||||
value = os.getenv(env_key, None)
|
||||
if value:
|
||||
path = value
|
||||
if os.path.exists(path):
|
||||
with open(path, 'rt') as f:
|
||||
config = json.load(f)
|
||||
logging.config.dictConfig(config)
|
||||
else:
|
||||
logging.basicConfig(level=default_level)
|
||||
|
||||
|
||||
setup_logging()
|
||||
|
||||
log_discord = logging.getLogger('discord')
|
||||
log_foBot = logging.getLogger('foBot')
|
||||
|
||||
debug = log_foBot.debug
|
||||
info = log_foBot.info
|
||||
warning = log_foBot.warning
|
||||
error = log_foBot.error
|
||||
critical = log_foBot.critical
|
Loading…
Reference in New Issue
Block a user