Compare commits
No commits in common. "a9fa313605fb3ae22b1ecaef9fc4d21608f81b8d" and "caa9e3264a916c9adc22b79b67ca06f1449e68dc" have entirely different histories.
a9fa313605
...
caa9e3264a
106
daemon.py
106
daemon.py
@ -18,58 +18,6 @@ log_file = 'output.log'
|
|||||||
cfg_file = 'config.ini'
|
cfg_file = 'config.ini'
|
||||||
|
|
||||||
|
|
||||||
def get_console_handler():
|
|
||||||
console_handler = logging.StreamHandler(sys.stdout)
|
|
||||||
console_handler.setFormatter(log_format)
|
|
||||||
return console_handler
|
|
||||||
|
|
||||||
|
|
||||||
def get_file_handler():
|
|
||||||
file_handler = TimedRotatingFileHandler(log_file, when='midnight')
|
|
||||||
file_handler.setFormatter(log_format)
|
|
||||||
return file_handler
|
|
||||||
|
|
||||||
|
|
||||||
class CustomFormatter(logging.Formatter):
|
|
||||||
|
|
||||||
grey = "\x1b[38;20m"
|
|
||||||
yellow = "\x1b[33;20m"
|
|
||||||
red = "\x1b[31;20m"
|
|
||||||
bold_red = "\x1b[31;1m"
|
|
||||||
reset = "\x1b[0m"
|
|
||||||
format = "%(asctime)s %(levelname)s - %(message)s"
|
|
||||||
|
|
||||||
FORMATS = {
|
|
||||||
logging.DEBUG: grey + format + reset,
|
|
||||||
logging.INFO: grey + format + reset,
|
|
||||||
logging.WARNING: yellow + format + reset,
|
|
||||||
logging.ERROR: red + format + reset,
|
|
||||||
logging.CRITICAL: bold_red + format + reset
|
|
||||||
}
|
|
||||||
|
|
||||||
def format(self, record):
|
|
||||||
log_fmt = self.FORMATS.get(record.levelno)
|
|
||||||
formatter = logging.Formatter(log_fmt)
|
|
||||||
return formatter.format(record)
|
|
||||||
|
|
||||||
|
|
||||||
def get_logger(logger_name):
|
|
||||||
"""
|
|
||||||
Инициализация лога
|
|
||||||
"""
|
|
||||||
logger = logging.getLogger(logger_name)
|
|
||||||
logger.setLevel(logging.DEBUG)
|
|
||||||
|
|
||||||
# Console logging
|
|
||||||
console = get_console_handler()
|
|
||||||
console.setFormatter(CustomFormatter())
|
|
||||||
logger.addHandler(console)
|
|
||||||
|
|
||||||
logger.addHandler(get_file_handler())
|
|
||||||
logger.propagate = False
|
|
||||||
return logger
|
|
||||||
|
|
||||||
|
|
||||||
def set_config():
|
def set_config():
|
||||||
"""
|
"""
|
||||||
Эта функция либо читает существующий конфиг, либо создает новый.
|
Эта функция либо читает существующий конфиг, либо создает новый.
|
||||||
@ -176,7 +124,7 @@ def check_stream():
|
|||||||
os.path.exists(os.path.join(streamer_path, "pid"))):
|
os.path.exists(os.path.join(streamer_path, "pid"))):
|
||||||
log.info("{} стримит".format(streamer))
|
log.info("{} стримит".format(streamer))
|
||||||
start_recording(streamer)
|
start_recording(streamer)
|
||||||
os.mknod(os.path.join(streamer_path, "pid"))
|
open(os.path.join(streamer_path, "pid"), 'w').close
|
||||||
else:
|
else:
|
||||||
log.info(
|
log.info(
|
||||||
"Идет запись {}".format(streamer)
|
"Идет запись {}".format(streamer)
|
||||||
@ -210,6 +158,58 @@ def remove_old_streams():
|
|||||||
log.error(e)
|
log.error(e)
|
||||||
|
|
||||||
|
|
||||||
|
def get_console_handler():
|
||||||
|
console_handler = logging.StreamHandler(sys.stdout)
|
||||||
|
console_handler.setFormatter(log_format)
|
||||||
|
return console_handler
|
||||||
|
|
||||||
|
|
||||||
|
def get_file_handler():
|
||||||
|
file_handler = TimedRotatingFileHandler(log_file, when='midnight')
|
||||||
|
file_handler.setFormatter(log_format)
|
||||||
|
return file_handler
|
||||||
|
|
||||||
|
|
||||||
|
class CustomFormatter(logging.Formatter):
|
||||||
|
|
||||||
|
grey = "\x1b[38;20m"
|
||||||
|
yellow = "\x1b[33;20m"
|
||||||
|
red = "\x1b[31;20m"
|
||||||
|
bold_red = "\x1b[31;1m"
|
||||||
|
reset = "\x1b[0m"
|
||||||
|
format = "%(asctime)s %(levelname)s - %(message)s"
|
||||||
|
|
||||||
|
FORMATS = {
|
||||||
|
logging.DEBUG: grey + format + reset,
|
||||||
|
logging.INFO: grey + format + reset,
|
||||||
|
logging.WARNING: yellow + format + reset,
|
||||||
|
logging.ERROR: red + format + reset,
|
||||||
|
logging.CRITICAL: bold_red + format + reset
|
||||||
|
}
|
||||||
|
|
||||||
|
def format(self, record):
|
||||||
|
log_fmt = self.FORMATS.get(record.levelno)
|
||||||
|
formatter = logging.Formatter(log_fmt)
|
||||||
|
return formatter.format(record)
|
||||||
|
|
||||||
|
|
||||||
|
def get_logger(logger_name):
|
||||||
|
"""
|
||||||
|
Инициализация лога
|
||||||
|
"""
|
||||||
|
logger = logging.getLogger(logger_name)
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
# Console logging
|
||||||
|
console = get_console_handler()
|
||||||
|
console.setFormatter(CustomFormatter())
|
||||||
|
logger.addHandler(console)
|
||||||
|
|
||||||
|
logger.addHandler(get_file_handler())
|
||||||
|
logger.propagate = False
|
||||||
|
return logger
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Проверить, установлены ли нужные утилиты
|
# Проверить, установлены ли нужные утилиты
|
||||||
if not check_installed_tools():
|
if not check_installed_tools():
|
||||||
|
Loading…
Reference in New Issue
Block a user