Add log level config option
* Log levels can now be set via the command line and the configuration file. * ServerConfig.load() function takes a file-like object now, rather than a string Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -1,20 +1,40 @@
|
||||
import argparse
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from .config import ServerConfig
|
||||
from .bot import Bot
|
||||
|
||||
parser = argparse.ArgumentParser(description="Run an IRC bot")
|
||||
parser.add_argument(
|
||||
"-c", "--config", type=argparse.FileType("r"), default="config.toml"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--loglevel",
|
||||
type=str,
|
||||
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
|
||||
required=False,
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
config = ServerConfig()
|
||||
config.load(args.config)
|
||||
|
||||
# Set log level now
|
||||
loglevel = logging.INFO
|
||||
if args.loglevel:
|
||||
loglevel = getattr(logging, args.loglevel)
|
||||
elif config.loglevel:
|
||||
loglevel = getattr(logging, config.loglevel)
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
level=loglevel,
|
||||
format="%(asctime)s - %(name)-12s - %(levelname)-8s - %(message)s",
|
||||
)
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
log.debug("Loading config")
|
||||
config = ServerConfig()
|
||||
config.load("config.toml")
|
||||
log.info("Loaded config file %s", args.config)
|
||||
log.debug("Using configuration: %s", config)
|
||||
|
||||
bot = Bot(config)
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user