Python appdirs.user_log_dir() Examples

The following are 5 code examples of appdirs.user_log_dir(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module appdirs , or try the search function .
Example #1
Source File: manage.py    From putio-automator with MIT License 6 votes vote down vote up
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() 
Example #2
Source File: config.py    From counterblock with MIT License 5 votes vote down vote up
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 
Example #3
Source File: logger.py    From geocube with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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) 
Example #4
Source File: dirs.py    From aw-core with Mozilla Public License 2.0 5 votes vote down vote up
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 
Example #5
Source File: sr_config.py    From sarracenia with GNU General Public License v2.0 5 votes vote down vote up
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 ) )