def moulinette(tmp_path_factory): import moulinette import moulinette.core from moulinette.utils.log import configure_logging # Can't call the namespace just 'test' because # that would lead to some "import test" not importing the right stuff namespace = "moulitest" tmp_dir = str(tmp_path_factory.mktemp(namespace)) shutil.copy("./test/actionsmap/moulitest.yml", f"{tmp_dir}/moulitest.yml") shutil.copytree("./test/src", f"{tmp_dir}/lib/{namespace}/") shutil.copytree("./test/locales", f"{tmp_dir}/locales") sys.path.insert(0, f"{tmp_dir}/lib") patch_translate(moulinette) patch_lock(moulinette) configure_logging(logging_configuration(moulinette)) moulinette.m18n.set_locales_dir(f"{tmp_dir}/locales") # Dirty hack to pass this path to Api() and Cli() init later moulinette._actionsmap_path = f"{tmp_dir}/moulitest.yml" return moulinette
def init(logging_config=None, **kwargs): """Package initialization Initialize directories and global variables. It must be called before any of package method is used - even the easy access functions. Keyword arguments: - logging_config -- A dict containing logging configuration to load - **kwargs -- See core.Package At the end, the global variable 'pkg' will contain a Package instance. See core.Package for available methods and variables. """ import sys import __builtin__ from moulinette.core import (Package, Moulinette18n, MoulinetteSignals) from moulinette.utils.log import configure_logging configure_logging(logging_config) # Define and instantiate global objects __builtin__.__dict__['pkg'] = Package(**kwargs) __builtin__.__dict__['m18n'] = Moulinette18n(pkg) __builtin__.__dict__['msignals'] = MoulinetteSignals() __builtin__.__dict__['msettings'] = dict() # Add library directory to python path sys.path.insert(0, pkg.libdir)
def init(logging_config=None, **kwargs): """Package initialization Initialize directories and global variables. It must be called before any of package method is used - even the easy access functions. Keyword arguments: - logging_config -- A dict containing logging configuration to load - **kwargs -- See core.Package At the end, the global variable 'pkg' will contain a Package instance. See core.Package for available methods and variables. """ import sys import __builtin__ from moulinette.core import ( Package, Moulinette18n, MoulinetteSignals ) from moulinette.utils.log import configure_logging configure_logging(logging_config) # Define and instantiate global objects __builtin__.__dict__['pkg'] = Package(**kwargs) __builtin__.__dict__['m18n'] = Moulinette18n(pkg) __builtin__.__dict__['msignals'] = MoulinetteSignals() __builtin__.__dict__['msettings'] = dict() # Add library directory to python path sys.path.insert(0, pkg.libdir)
def init_logging(interface="cli", debug=False, quiet=False, logdir="/var/log/yunohost"): logfile = os.path.join(logdir, "yunohost-%s.log" % interface) if not os.path.isdir(logdir): os.makedirs(logdir, 0o750) # ####################################################################### # # Logging configuration for CLI (or any other interface than api...) # # ####################################################################### # if interface != "api": configure_logging({ 'version': 1, 'main_logger': "yunohost", 'disable_existing_loggers': True, 'formatters': { 'tty-debug': { 'format': '%(relativeCreated)-4d %(fmessage)s' }, 'precise': { 'format': '%(asctime)-15s %(levelname)-8s %(name)s %(funcName)s - %(fmessage)s' }, }, 'filters': { 'action': { '()': 'moulinette.utils.log.ActionFilter', }, }, 'handlers': { 'tty': { 'level': 'DEBUG' if debug else 'INFO', 'class': 'moulinette.interfaces.cli.TTYHandler', 'formatter': 'tty-debug' if debug else '', }, 'file': { 'class': 'logging.FileHandler', 'formatter': 'precise', 'filename': logfile, 'filters': ['action'], }, }, 'loggers': { 'yunohost': { 'level': 'DEBUG', 'handlers': ['file', 'tty'] if not quiet else ['file'], 'propagate': False, }, 'moulinette': { 'level': 'DEBUG', 'handlers': [], 'propagate': True, }, 'moulinette.interface': { 'level': 'DEBUG', 'handlers': ['file', 'tty'] if not quiet else ['file'], 'propagate': False, }, }, 'root': { 'level': 'DEBUG', 'handlers': ['file', 'tty'] if debug else ['file'], }, }) # ####################################################################### # # Logging configuration for API # # ####################################################################### # else: configure_logging({ 'version': 1, 'disable_existing_loggers': True, 'formatters': { 'console': { 'format': '%(relativeCreated)-5d %(levelname)-8s %(name)s %(funcName)s - %(fmessage)s' }, 'precise': { 'format': '%(asctime)-15s %(levelname)-8s %(name)s %(funcName)s - %(fmessage)s' }, }, 'filters': { 'action': { '()': 'moulinette.utils.log.ActionFilter', }, }, 'handlers': { 'api': { 'level': 'DEBUG' if debug else 'INFO', 'class': 'moulinette.interfaces.api.APIQueueHandler', }, 'file': { 'class': 'logging.handlers.WatchedFileHandler', 'formatter': 'precise', 'filename': logfile, 'filters': ['action'], }, 'console': { 'class': 'logging.StreamHandler', 'formatter': 'console', 'stream': 'ext://sys.stdout', 'filters': ['action'], }, }, 'loggers': { 'yunohost': { 'level': 'DEBUG', 'handlers': ['file', 'api'] + (['console'] if debug else []), 'propagate': False, }, 'moulinette': { 'level': 'DEBUG', 'handlers': [], 'propagate': True, }, }, 'root': { 'level': 'DEBUG', 'handlers': ['file'] + (['console'] if debug else []), }, })
def init_logging(interface="cli", debug=False, quiet=False, logdir="/var/log/yunohost"): logfile = os.path.join(logdir, "yunohost-%s.log" % interface) if not os.path.isdir(logdir): os.makedirs(logdir, 0o750) logging_configuration = { 'version': 1, 'disable_existing_loggers': True, 'formatters': { 'console': { 'format': '%(relativeCreated)-5d %(levelname)-8s %(name)s %(funcName)s - %(fmessage)s' }, 'tty-debug': { 'format': '%(relativeCreated)-4d %(fmessage)s' }, 'precise': { 'format': '%(asctime)-15s %(levelname)-8s %(name)s %(funcName)s - %(fmessage)s' }, }, 'filters': { 'action': { '()': 'moulinette.utils.log.ActionFilter', }, }, 'handlers': { 'cli': { 'level': 'DEBUG' if debug else 'INFO', 'class': 'moulinette.interfaces.cli.TTYHandler', 'formatter': 'tty-debug' if debug else '', }, 'api': { 'level': 'DEBUG' if debug else 'INFO', 'class': 'moulinette.interfaces.api.APIQueueHandler', }, 'file': { 'class': 'logging.FileHandler', 'formatter': 'precise', 'filename': logfile, 'filters': ['action'], }, }, 'loggers': { 'yunohost': { 'level': 'DEBUG', 'handlers': ['file', interface] if not quiet else ['file'], 'propagate': False, }, 'moulinette': { 'level': 'DEBUG', 'handlers': ['file', interface] if not quiet else ['file'], 'propagate': False, }, }, 'root': { 'level': 'DEBUG', 'handlers': ['file', interface] if debug else ['file'], }, } # Logging configuration for CLI (or any other interface than api...) # if interface != "api": configure_logging(logging_configuration) # Logging configuration for API # else: # We use a WatchedFileHandler instead of regular FileHandler to possibly support log rotation etc logging_configuration["handlers"]["file"][ "class"] = 'logging.handlers.WatchedFileHandler' # This is for when launching yunohost-api in debug mode, we want to display stuff in the console if debug: logging_configuration["loggers"]["yunohost"]["handlers"].append( "cli") logging_configuration["loggers"]["moulinette"]["handlers"].append( "cli") logging_configuration["root"]["handlers"].append("cli") configure_logging(logging_configuration)
def init_logging(interface="cli", debug=False, quiet=False, logdir="/var/log/yunohost"): logfile = os.path.join(logdir, "yunohost-%s.log" % interface) if not os.path.isdir(logdir): os.makedirs(logdir, 0o750) # ####################################################################### # # Logging configuration for CLI (or any other interface than api...) # # ####################################################################### # if interface != "api": configure_logging( { "version": 1, "main_logger": "yunohost", "disable_existing_loggers": True, "formatters": { "tty-debug": {"format": "%(relativeCreated)-4d %(fmessage)s"}, "precise": { "format": "%(asctime)-15s %(levelname)-8s %(name)s %(funcName)s - %(fmessage)s" }, }, "filters": { "action": { "()": "moulinette.utils.log.ActionFilter", }, }, "handlers": { "tty": { "level": "DEBUG" if debug else "INFO", "class": "moulinette.interfaces.cli.TTYHandler", "formatter": "tty-debug" if debug else "", }, "file": { "class": "logging.FileHandler", "formatter": "precise", "filename": logfile, "filters": ["action"], }, }, "loggers": { "yunohost": { "level": "DEBUG", "handlers": ["file", "tty"] if not quiet else ["file"], "propagate": False, }, "moulinette": { "level": "DEBUG", "handlers": [], "propagate": True, }, "moulinette.interface": { "level": "DEBUG", "handlers": ["file", "tty"] if not quiet else ["file"], "propagate": False, }, }, "root": { "level": "DEBUG", "handlers": ["file", "tty"] if debug else ["file"], }, } ) # ####################################################################### # # Logging configuration for API # # ####################################################################### # else: configure_logging( { "version": 1, "disable_existing_loggers": True, "formatters": { "console": { "format": "%(relativeCreated)-5d %(levelname)-8s %(name)s %(funcName)s - %(fmessage)s" }, "precise": { "format": "%(asctime)-15s %(levelname)-8s %(name)s %(funcName)s - %(fmessage)s" }, }, "filters": { "action": { "()": "moulinette.utils.log.ActionFilter", }, }, "handlers": { "api": { "level": "DEBUG" if debug else "INFO", "class": "moulinette.interfaces.api.APIQueueHandler", }, "file": { "class": "logging.handlers.WatchedFileHandler", "formatter": "precise", "filename": logfile, "filters": ["action"], }, "console": { "class": "logging.StreamHandler", "formatter": "console", "stream": "ext://sys.stdout", "filters": ["action"], }, }, "loggers": { "yunohost": { "level": "DEBUG", "handlers": ["file", "api"] + (["console"] if debug else []), "propagate": False, }, "moulinette": { "level": "DEBUG", "handlers": [], "propagate": True, }, }, "root": { "level": "DEBUG", "handlers": ["file"] + (["console"] if debug else []), }, } )
def init_logging(interface="cli", debug=False, quiet=False, logdir="/var/log/yunohost"): logfile = os.path.join(logdir, "yunohost-%s.log" % interface) if not os.path.isdir(logdir): os.makedirs(logdir, 0o750) logging_configuration = { "version": 1, "disable_existing_loggers": True, "formatters": { "console": { "format": "%(relativeCreated)-5d %(levelname)-8s %(name)s %(funcName)s - %(fmessage)s" }, "tty-debug": {"format": "%(relativeCreated)-4d %(fmessage)s"}, "precise": { "format": "%(asctime)-15s %(levelname)-8s %(name)s %(funcName)s - %(fmessage)s" }, }, "filters": { "action": { "()": "moulinette.utils.log.ActionFilter", }, }, "handlers": { "cli": { "level": "DEBUG" if debug else "INFO", "class": "moulinette.interfaces.cli.TTYHandler", "formatter": "tty-debug" if debug else "", }, "api": { "level": "DEBUG" if debug else "INFO", "class": "moulinette.interfaces.api.APIQueueHandler", }, "file": { "class": "logging.FileHandler", "formatter": "precise", "filename": logfile, "filters": ["action"], }, }, "loggers": { "yunohost": { "level": "DEBUG", "handlers": ["file", interface] if not quiet else ["file"], "propagate": False, }, "moulinette": { "level": "DEBUG", "handlers": ["file", interface] if not quiet else ["file"], "propagate": False, }, }, "root": { "level": "DEBUG", "handlers": ["file", interface] if debug else ["file"], }, } # Logging configuration for CLI (or any other interface than api...) # if interface != "api": configure_logging(logging_configuration) # Logging configuration for API # else: # We use a WatchedFileHandler instead of regular FileHandler to possibly support log rotation etc logging_configuration["handlers"]["file"][ "class" ] = "logging.handlers.WatchedFileHandler" # This is for when launching yunohost-api in debug mode, we want to display stuff in the console if debug: logging_configuration["loggers"]["yunohost"]["handlers"].append("cli") logging_configuration["loggers"]["moulinette"]["handlers"].append("cli") logging_configuration["root"]["handlers"].append("cli") configure_logging(logging_configuration)