本文整理汇总了Python中appdirs.user_log_dir方法的典型用法代码示例。如果您正苦于以下问题:Python appdirs.user_log_dir方法的具体用法?Python appdirs.user_log_dir怎么用?Python appdirs.user_log_dir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类appdirs
的用法示例。
在下文中一共展示了appdirs.user_log_dir方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_log_dir [as 别名]
def main():
"Main entry point"
log_dir = os.getenv('LOG_DIR', appdirs.user_log_dir(APP_NAME, APP_AUTHOR))
distutils.dir_util.mkpath(log_dir)
logfile_path = os.path.join(log_dir, 'application.log')
handler = RotatingFileHandler(logfile_path, maxBytes=10000000, backupCount=5)
formatter = logging.Formatter("[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s")
handler.setFormatter(formatter)
handler.setLevel(app.config.get('LOG_LEVEL', logging.WARNING))
app.logger.addHandler(handler)
manager.run()
示例2: get_dirs
# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_log_dir [as 别名]
def get_dirs():
import appdirs
data_dir = appdirs.user_data_dir(appauthor=XCP_NAME, appname=APP_NAME, roaming=True)
config_dir = appdirs.user_config_dir(appauthor=XCP_NAME, appname=APP_NAME, roaming=True)
log_dir = appdirs.user_log_dir(appauthor=XCP_NAME, appname=APP_NAME)
return data_dir, config_dir, log_dir
示例3: log_to_file
# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_log_dir [as 别名]
def log_to_file(status=True, filename=None, level=None):
"""Log events to a file.
Parameters
----------
status: bool, optional, default=True
Whether logging to console should be turned on(True) or off(False)
filename: string, optional, default=None
path of file to log to
level: string, optional, default=None
Level of logging; whichever level is chosen all higher levels
will be logged. See: https://docs.python.org/2/library/logging.html#levels
"""
set_log_level(level)
if filename is None:
filename = os.path.join(appdirs.user_log_dir("geocube", "logs"), "geocube.log")
if status:
try:
os.makedirs(os.path.dirname(filename))
except OSError:
pass
file_handler = logging.FileHandler(filename)
formatter = logging.Formatter(_LOGGER_FORMAT_STR)
file_handler.setFormatter(formatter)
_LOGGER.addHandler(file_handler)
else:
_remove_log_handler(logging.FileHandler)
示例4: get_log_dir
# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_log_dir [as 别名]
def get_log_dir(module_name: Optional[str]) -> str: # pragma: no cover
log_dir = appdirs.user_log_dir("activitywatch")
return os.path.join(log_dir, module_name) if module_name else log_dir
示例5: configure_statehost
# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_log_dir [as 别名]
def configure_statehost(self):
self.logger.debug("configure_statehost")
hostdir = None
# user asked for statehost
if self.statehost :
hostdir = self.hostname
if self.hostform == 'short' : hostdir = self.hostname.split('.')[0]
# finalize user_log_dir
if hostdir and not hostdir in self.user_log_dir :
self.user_log_dir = self.user_log_dir[:-4] + os.sep + hostdir + '/log'
# create user_log_dir
self.logger.debug("sr_config user_log_dir %s " % self.user_log_dir )
try:
os.makedirs(self.user_log_dir, 0o775,True)
except Exception as ex:
self.logger.warning( "making %s: %s" % ( self.user_log_dir, ex ) )
# finalize user_cache_dir
if hostdir and not hostdir in self.user_cache_dir :
self.user_cache_dir = appdirs.user_cache_dir (self.appname,self.appauthor)
self.user_cache_dir += os.sep + hostdir
self.user_cache_dir += os.sep + self.program_name.replace('sr_','')
self.user_cache_dir += os.sep + "%s" % self.config_name
# create user_cache_dir
if not self.program_name in [ 'sr', 'sr_config' ]:
self.logger.debug("sr_config user_cache_dir %s " % self.user_cache_dir )
try:
os.makedirs(self.user_cache_dir, 0o775,True)
except Exception as ex:
self.logger.warning( "making %s: %s" % ( self.user_cache_dir, ex ) )