I am trying to generate a log file to a specific folder and path in greengrass v2. however the log file is created at the current directory.
The current directory at which the logger file is generated is
/sim/things/t1_gateway_iotgateway_1234/greengrass/packages/artifacts-unarchived/com.data.iot.RulesEngineCore/2.3.1-pp.38/package
Could you please help me where am I missing?
The following is my program.
import logging
from datetime import datetime
import os, sys
from logging.handlers import RotatingFileHandler
def getStandardStdOutHandler():
formatter = logging.Formatter(
fmt="[%(asctime)s][%(levelname)-7s][%(name)s] %(message)s (%(threadName)s[% (thread)d]:%(module)s:%(funcName)s:%(lineno)d)"
)
filename = datetime.now().strftime("rule_engine_%Y_%m_%d_%H_%M.log")
path = "/sim/things/t1_gateway_iotgateway_1234/greengrass/logs/"
_handler = RotatingFileHandler(path + filename, maxBytes=1000000, backupCount=5)
_handler.setLevel(logging.DEBUG)
_handler.setFormatter(formatter)
return _handler
def getLogger(name: str):
logger = logging.getLogger(name)
logger.addHandler(getStandardStdOutHandler())
return logger
from Problem in generating logger file to a specific path
No comments:
Post a Comment