mirror of
https://github.com/kuitoi/kuitoi-Server.git
synced 2025-08-17 16:25:36 +00:00
Add logging
This commit is contained in:
parent
c386d2f5f0
commit
5e994cf735
14
src/main.py
14
src/main.py
@ -2,13 +2,17 @@ import argparse
|
||||
|
||||
import __version__
|
||||
import config_provider
|
||||
import utils
|
||||
|
||||
parser = argparse.ArgumentParser(description='KuiToi-Server - BeamingDrive server compatible with BeamMP clients!')
|
||||
parser.add_argument('-v', '--version', action="store_true", help='Print version and exit.', default=False)
|
||||
parser.add_argument('--config', help='Patch to config file.', nargs='?', default=None, type=str)
|
||||
log = utils.get_logger("main")
|
||||
|
||||
|
||||
def main():
|
||||
global log
|
||||
log.info("Hello from KuiToi-Server!")
|
||||
args = parser.parse_args()
|
||||
if args.version:
|
||||
print(f"KuiToi-Server:\n\tVersion: {__version__.__version__}\n\tBuild: {__version__.__build__}")
|
||||
@ -17,9 +21,17 @@ def main():
|
||||
config_patch = "kuitoi.yml"
|
||||
if args.config:
|
||||
config_patch = args.config
|
||||
log.info(f"Use {config_patch} for config.")
|
||||
|
||||
cp = config_provider.ConfigProvider(config_patch)
|
||||
config = cp.open_config()
|
||||
print(config)
|
||||
if config.Server['debug'] is True:
|
||||
utils.set_debug_status()
|
||||
log.info("Getting new loggen with DEBUG level!")
|
||||
log = utils.get_logger("main")
|
||||
log.level = 10
|
||||
log.debug("Debug enabled!")
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
25
src/utils.py
Normal file
25
src/utils.py
Normal file
@ -0,0 +1,25 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
log_format = "[%(asctime)s | %(name)s | %(levelname)-5s] %(message)s"
|
||||
log_file = "server.log"
|
||||
log_level = logging.INFO
|
||||
# Инициализируем логирование
|
||||
logging.basicConfig(level=log_level, format=log_format)
|
||||
# Настройка логирование в файл.
|
||||
if os.path.exists(log_file):
|
||||
os.remove(log_file)
|
||||
fh = logging.FileHandler(log_file)
|
||||
fh.setLevel(log_level)
|
||||
fh.setFormatter(logging.Formatter(log_format))
|
||||
|
||||
|
||||
def get_logger(name):
|
||||
log = logging.getLogger(name=name)
|
||||
log.addHandler(fh)
|
||||
return log
|
||||
|
||||
|
||||
def set_debug_status():
|
||||
global log_level
|
||||
log_level = logging.DEBUG
|
Loading…
x
Reference in New Issue
Block a user