How to use the appdirs.user_log_dir function in appdirs

To help you get started, we’ve selected a few appdirs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vietjtnguyen / gimp-image-labeling-toolbox / gimp / label-toolbox.py View on Github external
# Attempt to add default Python 2.7 install to allow GIMP's Python to find
# dependencies
if os.name == 'nt':
  sys.path.append(r'C:\Python27\Lib\site-packages')

# Try to import `appdirs` and set up the logging infrastructure. There *really*
# should be no reason `appdirs` does not import properly because the file is
# right there! However, just in case I'm going to assume Viet screwed up so
# we're on his computer and so we'll set up the output streams to his home
# directory.
try:
  import appdirs
  # Get a platform specific logging directory for application name
  # `gimp-label-toolbox`.
  log_file = appdirs.user_log_dir('gimp-label-toolbox')
  # The function specifies the log file as just `log`. We want two different
  # log files (one to act as `stderr` and one to act as `stdout`) so we'll grab
  # the path and specify our own file names.
  log_dir = os.path.split(log_file)[0]
except ImportError:
  log_dir = '/home/vnguyen'
if not os.path.exists(log_dir):
  os.makedirs(log_dir)
err_log_file = os.path.join(log_dir, 'err.log')
out_log_file = os.path.join(log_dir, 'out.log')
log_log_file = os.path.join(log_dir, 'log.log')
# Now we'll redirect our `stderr` and `stdout` to these files and initialize
# our logging infrastructure with a very verbose prefix.
sys.stderr = open(err_log_file, 'w', buffering=0)
sys.stdout = open(out_log_file, 'w', buffering=0)
logging.basicConfig(filename=log_log_file,
github snowman2 / pangaea / pangaea / log.py View on Github external
.. _pangaea Documentation HOWTO:
   https://github.com/snowman2/pangaea
"""
# default modules
import logging
import os
# external modules
import appdirs
# local modules
from .meta import version

LOGGER = logging.getLogger('pangaea')
LOGGER.addHandler(logging.NullHandler())
LOGGER.propagate = False

DEFAULT_LOG_DIR = appdirs.user_log_dir('pangaea', 'logs')
DEFAULT_LOG_FILE = os.path.join(DEFAULT_LOG_DIR, 'pangaea.log')


def log_to_console(status=True, level=None):
    """Log events to  the console.

    Args:
        status (bool, Optional, Default=True)
            whether logging to console should be turned on(True) or off(False)
        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
      """

    if status:
github projecthamster / hamster-cli / hamster_cli / hamster_cli.py View on Github external
def user_log_dir(self):
        """Return ``user_log_dir``."""
        directory = appdirs.user_log_dir(self.appname, self.appauthor,
                            version=self.version)
        if self.create:
            self._ensure_directory_exists(directory)
        return directory
github CounterpartyXCP / counterblock / counterblock / lib / config.py View on Github external
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
github Digital-Sapphire / PyUpdater / pyupdater / __init__.py View on Github external
fmt = logging.Formatter("[%(levelname)s] %(message)s")
sh = logging.StreamHandler()
sh.setLevel(logging.INFO)
sh.setFormatter(fmt)
log.addHandler(sh)

# Log to pyu.log if available
local_debug_file_path = os.path.join(os.getcwd(), "pyu.log")
if os.path.exists(local_debug_file_path):  # pragma: no cover
    fh = logging.FileHandler(local_debug_file_path)
    fh.setLevel(logging.DEBUG)
    fh.setFormatter(logging_formatter)
    log.addHandler(fh)

# Default log directory
LOG_DIR = user_log_dir(settings.APP_NAME, settings.APP_AUTHOR)
if not os.path.exists(LOG_DIR):  # pragma: no cover
    os.makedirs(LOG_DIR)

log_file = os.path.join(LOG_DIR, settings.LOG_FILENAME_DEBUG)
rfh = RotatingFileHandler(log_file, maxBytes=1048576, backupCount=2)
rfh.setLevel(logging.DEBUG)
rfh.setFormatter(logging_formatter)
log.addHandler(rfh)

# noinspection PyPep8
from ._version import get_versions

__version__ = get_versions()["version"]
del get_versions
log.debug("Version - %s", __version__)
github nschloe / pipdate / pipdate / main.py View on Github external
from distutils.version import LooseVersion

import appdirs

try:
    import configparser
except ImportError:
    import ConfigParser as configparser


_config_dir = appdirs.user_config_dir("pipdate")
if not os.path.exists(_config_dir):
    os.makedirs(_config_dir)
_config_file = os.path.join(_config_dir, "config.ini")

_log_dir = appdirs.user_log_dir("pipdate", u"Nico Schlömer")
if not os.path.exists(_log_dir):
    os.makedirs(_log_dir)
_log_file = os.path.join(_log_dir, "times.log")


def _get_seconds_between_checks():
    if not os.path.exists(_config_file):
        # add default config
        parser = configparser.ConfigParser()
        parser.set("DEFAULT", "SecondsBetweenChecks", str(24 * 60 * 60))
        with open(_config_file, "w") as handle:
            parser.write(handle)

    # read config
    config = configparser.ConfigParser()
    config.read(_config_file)
github zatosource / zato / code / zato-exeagent / src / zato / exeagent / main.py View on Github external
def main():

    # Always attempt to store the PID file first
    store_pidfile(os.path.abspath('.'))

    # Capture warnings to log files
    logging.captureWarnings(True)

    config = Config()

    print(user_config_dir(app_name, app_author))
    print(user_log_dir(app_name, app_author))

    return

    repo_location = os.path.join('.', 'config', 'repo')

    # Logging configuration
    with open(os.path.join(repo_location, 'logging.conf')) as f:
        dictConfig(yaml.load(f))

    # Read config in and make paths absolute
    config.main = get_config(repo_location, 'exeagent.conf')

    if config.main.crypto.use_tls:
        config.main.crypto.ca_certs_location = absjoin(repo_location, config.main.crypto.ca_certs_location)
        config.main.crypto.priv_key_location = absjoin(repo_location, config.main.crypto.priv_key_location)
        config.main.crypto.cert_location = absjoin(repo_location, config.main.crypto.cert_location)
github abulka / pynsource / src / common / logger.py View on Github external
def get_log_file_path(file_name):
    """
    Returns path of log file.
    Creates the directory if needed.

    Args:
        file_name: e.g. debug.log

    Returns: full path e.g. ~/library/logs/pynsource/debug.log

    """
    # log.debug(f'user_log_dir() is {user_log_dir()}')
    if sys.platform == 'win32':
        dir = os.path.normpath(
            os.path.join(user_log_dir(), os.path.join('..', '..', 'Roaming', APP_NAME)))
    else:
        dir = user_log_dir(APP_NAME).lower()
    os.makedirs(dir, exist_ok=True)
    path = os.path.join(dir, file_name)
    return path
github abulka / pynsource / src / common / logger.py View on Github external
"""
    Returns path of log file.
    Creates the directory if needed.

    Args:
        file_name: e.g. debug.log

    Returns: full path e.g. ~/library/logs/pynsource/debug.log

    """
    # log.debug(f'user_log_dir() is {user_log_dir()}')
    if sys.platform == 'win32':
        dir = os.path.normpath(
            os.path.join(user_log_dir(), os.path.join('..', '..', 'Roaming', APP_NAME)))
    else:
        dir = user_log_dir(APP_NAME).lower()
    os.makedirs(dir, exist_ok=True)
    path = os.path.join(dir, file_name)
    return path

appdirs

A small Python module for determining appropriate platform-specific dirs, e.g. a "user data dir".

MIT
Latest version published 4 years ago

Package Health Score

77 / 100
Full package analysis

Similar packages