# -*- coding: utf-8 -*-
# @Time    : 2024/5/16
# @Author  : 魏志亮

import datetime
import logging
import sys
from os import path, sep, makedirs

from utils.conf.read_conf import read_conf, yaml_conf

logger = logging.getLogger("energy_online_data")
logger.setLevel(logging.INFO)
stout_handle = logging.StreamHandler(sys.stdout)
stout_handle.setFormatter(
    logging.Formatter("%(asctime)s: %(message)s"))
stout_handle.setLevel(logging.INFO)
logger.addHandler(stout_handle)

config_path = path.abspath(__file__).split("utils")[0] + 'conf' + sep + 'config.yaml'
config = yaml_conf(config_path)
log_path_dir = read_conf(config, 'log_path_dir', "/data/logs")

log_path = log_path_dir + sep + r'energy_online_data'
file_path = path.join(log_path)

if not path.exists(file_path):
    makedirs(file_path, exist_ok=True)
file_name = str(file_path + sep + str(datetime.date.today()) + '.log')

file_handler = logging.FileHandler(file_name, encoding='utf-8')
file_handler.setFormatter(
    logging.Formatter("%(asctime)s: %(message)s"))
file_handler.setLevel(logging.INFO)
logger.addHandler(file_handler)

# def logger.info(*args):
#     logger.info("  ".join([str(a) for a in args]))
