Home | Trees | Indices | Help |
|
---|
|
1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 # 4 # Copyright © 2010 Red Hat, Inc. 5 # 6 # This software is licensed to you under the GNU General Public License, 7 # version 2 (GPLv2). There is NO WARRANTY for this software, express or 8 # implied, including the implied warranties of MERCHANTABILITY or FITNESS 9 # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 10 # along with this software; if not, see 11 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 12 # 13 # Red Hat trademarks are not licensed under GPLv2. No permission is 14 # granted to use or replicate Red Hat trademarks that are incorporated 15 # in this software or its documentation. 16 17 import logging 18 import logging.handlers 19 import os 20 import os.path 21 22 from pulp.server import config 23 24 # logging configuration ------------------------------------------------------- 2527 """ 28 Check the write permissions on log files and their parent directory. Raise 29 a runtime error if the write permissions are lacking. 30 """ 31 if os.path.exists(file_path) and not os.access(file_path, os.W_OK): 32 raise RuntimeError('Cannot write to log file: %s' % file_path) 33 dir_path = os.path.dirname(file_path) 34 if not os.access(dir_path, os.W_OK): 35 raise RuntimeError('Cannot write to log directory: %s' % dir_path) 36 return 'Yeah!'37 3840 """ 41 Pull the log file configurations from the global config and/or default 42 config and initialize the top-level logging for both pulp and grinder. 43 """ 44 level_name = config.config.get('logs', 'level').upper() 45 level = getattr(logging, level_name, logging.INFO) 46 max_size = config.config.getint('logs', 'max_size') 47 backups = config.config.getint('logs', 'backups') 48 fmt = '%(asctime)s [%(levelname)s][%(threadName)s] %(funcName)s() @ %(filename)s:%(lineno)d - %(message)s' 49 formatter = logging.Formatter(fmt) 50 51 pulp_file = config.config.get('logs', 'pulp_file') 52 check_log_file(pulp_file) 53 pulp_logger = logging.getLogger('pulp') 54 pulp_logger.setLevel(level) 55 pulp_handler = logging.handlers.RotatingFileHandler(pulp_file, 56 maxBytes=max_size, 57 backupCount=backups) 58 pulp_handler.setFormatter(formatter) 59 pulp_logger.addHandler(pulp_handler) 60 61 grinder_file = config.config.get('logs', 'grinder_file') 62 check_log_file(grinder_file) 63 grinder_logger = logging.getLogger('grinder') 64 grinder_logger.setLevel(level) 65 grinder_handler = logging.handlers.RotatingFileHandler(grinder_file, 66 maxBytes=max_size, 67 backupCount=backups) 68 grinder_handler.setFormatter(formatter) 69 grinder_logger.addHandler(grinder_handler)70 7173 """ 74 Pull the audit logging configuration from the global config and/or default 75 config and initialize pulp's audit logging. 76 """ 77 file = config.config.get('auditing', 'events_file') 78 check_log_file(file) 79 lifetime = config.config.getint('auditing', 'lifetime') 80 backups = config.config.getint('auditing', 'backups') 81 82 # NOTE, this cannot be a descendant of the pulp log as it will inherit 83 # pulp's rotating log and handler and log to both files. Yes, I've tried 84 # removing the handler to no avail... 85 logger = logging.getLogger('auditing') 86 logger.setLevel(logging.INFO) 87 handler = logging.handlers.TimedRotatingFileHandler(file, 88 when='D', 89 interval=lifetime, 90 backupCount=backups) 91 logger.addHandler(handler)92 93 # pulp logging api ------------------------------------------------------------ 94 95 started = False 9698 """ 99 Convenience function to start pulp's different logging mechanisms. 100 """ 101 assert config.config is not None 102 global started 103 if not started: 104 configure_pulp_grinder_logging() 105 configure_audit_logging() 106 started = True107 108110 """ 111 Convenience function to stop pulp's different logging mechanisms. 112 """ 113 global started 114 if started: 115 logging.shutdown() 116 started = False117 118120 """ 121 Convenience function to restart pulp's different logging mechanisms. 122 """ 123 stop_logging() 124 start_logging()125
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue Sep 7 12:30:37 2010 | http://epydoc.sourceforge.net |