当前位置: 首页>>代码示例>>Python>>正文


Python NTEventLogHandler.setLevel方法代码示例

本文整理汇总了Python中logging.handlers.NTEventLogHandler.setLevel方法的典型用法代码示例。如果您正苦于以下问题:Python NTEventLogHandler.setLevel方法的具体用法?Python NTEventLogHandler.setLevel怎么用?Python NTEventLogHandler.setLevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在logging.handlers.NTEventLogHandler的用法示例。


在下文中一共展示了NTEventLogHandler.setLevel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: initialize_logging

# 需要导入模块: from logging.handlers import NTEventLogHandler [as 别名]
# 或者: from logging.handlers.NTEventLogHandler import setLevel [as 别名]
def initialize_logging(logger_name):
    try:
        logging_config = get_logging_config()

        logging.basicConfig(
            format=get_log_format(logger_name),
            level=logging_config['log_level'] or logging.INFO,
        )

        log_file = logging_config.get('%s_log_file' % logger_name)
        if log_file is not None and not logging_config['disable_file_logging']:
            # make sure the log directory is writeable
            # NOTE: the entire directory needs to be writable so that rotation works
            if os.access(os.path.dirname(log_file), os.R_OK | os.W_OK):
                file_handler = logging.handlers.RotatingFileHandler(log_file, maxBytes=LOGGING_MAX_BYTES, backupCount=1)
                formatter = logging.Formatter(get_log_format(logger_name), get_log_date_format())
                file_handler.setFormatter(formatter)

                root_log = logging.getLogger()
                root_log.addHandler(file_handler)
            else:
                sys.stderr.write("Log file is unwritable: '%s'\n" % log_file)

        # set up syslog
        if logging_config['log_to_syslog']:
            try:
                from logging.handlers import SysLogHandler

                if logging_config['syslog_host'] is not None and logging_config['syslog_port'] is not None:
                    sys_log_addr = (logging_config['syslog_host'], logging_config['syslog_port'])
                else:
                    sys_log_addr = "/dev/log"
                    # Special-case BSDs
                    if Platform.is_darwin():
                        sys_log_addr = "/var/run/syslog"
                    elif Platform.is_freebsd():
                        sys_log_addr = "/var/run/log"

                handler = SysLogHandler(address=sys_log_addr, facility=SysLogHandler.LOG_DAEMON)
                handler.setFormatter(logging.Formatter(get_syslog_format(logger_name), get_log_date_format()))
                root_log = logging.getLogger()
                root_log.addHandler(handler)
            except Exception, e:
                sys.stderr.write("Error setting up syslog: '%s'\n" % str(e))
                traceback.print_exc()

        # Setting up logging in the event viewer for windows
        if get_os() == 'windows' and logging_config['log_to_event_viewer']:
            try:
                from logging.handlers import NTEventLogHandler
                nt_event_handler = NTEventLogHandler(logger_name, get_win32service_file('windows', 'win32service.pyd'), 'Application')
                nt_event_handler.setFormatter(logging.Formatter(get_syslog_format(logger_name), get_log_date_format()))
                nt_event_handler.setLevel(logging.ERROR)
                app_log = logging.getLogger(logger_name)
                app_log.addHandler(nt_event_handler)
            except Exception, e:
                sys.stderr.write("Error setting up Event viewer logging: '%s'\n" % str(e))
                traceback.print_exc()
开发者ID:awasilyev,项目名称:dd-agent,代码行数:60,代码来源:config.py

示例2: __init__

# 需要导入模块: from logging.handlers import NTEventLogHandler [as 别名]
# 或者: from logging.handlers.NTEventLogHandler import setLevel [as 别名]
 def __init__(self, args=None):
     win32serviceutil.ServiceFramework.__init__(self, args)
     self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
     sys.stdout = sys.stderr = open('nul', 'w')
     self._logger = logging.getLogger('MaxUpdater')
     if servicemanager.RunningAsService():
         ev_net = NTEventLogHandler(self._svc_name_, None)
         ev_net.setLevel(logging.ERROR)
         ev_net.setFormatter(logging.Formatter('%(levelname)-8s %(message)s'))
         self._logger.addHandler(ev_net)
     else:
         logging.basicConfig()
     rl = RotatingFileHandler(os.path.join(self._service_path, 'debug.log'), delay=True, maxBytes=150000,
                              backupCount=5)
     rl.setFormatter(logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s'))
     self._logger.addHandler(rl)
     self._cmd_thread = ExecThread()
     self._update_thread = UpdateThread()
开发者ID:dgsantana,项目名称:maxupdater,代码行数:20,代码来源:updater_service.py

示例3: open_ntlogger

# 需要导入模块: from logging.handlers import NTEventLogHandler [as 别名]
# 或者: from logging.handlers.NTEventLogHandler import setLevel [as 别名]
    def open_ntlogger(self):
        from logging.handlers import NTEventLogHandler
        try:
            # setup logger level
            self.logger.setLevel (logging.DEBUG)

            # setup formatter
            fmt = logging.Formatter ("%(asctime)s: %(name)s: %(levelname)s: %(message)s")
            # Create NT Event log handler and set level to INFO
            nh = NTEventLogHandler (self.name)
            nh.setLevel (self.level)
            #add formatter to nh
            nh.setFormatter (fmt)
            #add nh to logger
            self.logger.addHandler (nh)
        except:
            print "Unable to Open NT Eventlog!"
            raise
开发者ID:spdfire,项目名称:teddix,代码行数:20,代码来源:TeddixLogger.py

示例4: add_win_event_log_handler

# 需要导入模块: from logging.handlers import NTEventLogHandler [as 别名]
# 或者: from logging.handlers.NTEventLogHandler import setLevel [as 别名]
def add_win_event_log_handler(logger):
    nh = NTEventLogHandler('GISMOH')
    nh.setLevel(DEBUG)
    nh.setFormatter(get_formatter())

    logger.addHandler(nh)
开发者ID:ImperialCollegeLondon,项目名称:GISMOH_BE,代码行数:8,代码来源:Logging.py

示例5: initialize_logging

# 需要导入模块: from logging.handlers import NTEventLogHandler [as 别名]
# 或者: from logging.handlers.NTEventLogHandler import setLevel [as 别名]
def initialize_logging(logger_name):
    global windows_file_handler_added
    try:
        logging_config = get_logging_config()

        logging.basicConfig(format=get_log_format(logger_name), level=logging_config["log_level"] or logging.INFO)

        # set up file loggers
        if get_os() == "windows" and not windows_file_handler_added:
            logger_name = "ddagent"
            windows_file_handler_added = True

        log_file = logging_config.get("%s_log_file" % logger_name)
        if log_file is not None and not logging_config["disable_file_logging"]:
            # make sure the log directory is writeable
            # NOTE: the entire directory needs to be writable so that rotation works
            if os.access(os.path.dirname(log_file), os.R_OK | os.W_OK):
                file_handler = logging.handlers.RotatingFileHandler(log_file, maxBytes=LOGGING_MAX_BYTES, backupCount=1)
                formatter = logging.Formatter(get_log_format(logger_name), get_log_date_format())
                file_handler.setFormatter(formatter)

                root_log = logging.getLogger()
                root_log.addHandler(file_handler)
            else:
                sys.stderr.write("Log file is unwritable: '%s'\n" % log_file)

        # set up syslog
        if logging_config["log_to_syslog"]:
            try:
                from logging.handlers import SysLogHandler

                if logging_config["syslog_host"] is not None and logging_config["syslog_port"] is not None:
                    sys_log_addr = (logging_config["syslog_host"], logging_config["syslog_port"])
                else:
                    sys_log_addr = "/dev/log"
                    # Special-case macs
                    if sys.platform == "darwin":
                        sys_log_addr = "/var/run/syslog"

                handler = SysLogHandler(address=sys_log_addr, facility=SysLogHandler.LOG_DAEMON)
                handler.setFormatter(logging.Formatter(get_syslog_format(logger_name), get_log_date_format()))
                root_log = logging.getLogger()
                root_log.addHandler(handler)
            except Exception, e:
                sys.stderr.write("Error setting up syslog: '%s'\n" % str(e))
                traceback.print_exc()

        # Setting up logging in the event viewer for windows
        if get_os() == "windows" and logging_config["log_to_event_viewer"]:
            try:
                from logging.handlers import NTEventLogHandler

                nt_event_handler = NTEventLogHandler(
                    logger_name, get_win32service_file("windows", "win32service.pyd"), "Application"
                )
                nt_event_handler.setFormatter(logging.Formatter(get_syslog_format(logger_name)))
                nt_event_handler.setLevel(logging.ERROR)
                app_log = logging.getLogger(logger_name)
                app_log.addHandler(nt_event_handler)
            except Exception, e:
                sys.stderr.write("Error setting up Event viewer logging: '%s'\n" % str(e))
                traceback.print_exc()
开发者ID:kzw,项目名称:dd-agent,代码行数:64,代码来源:config.py


注:本文中的logging.handlers.NTEventLogHandler.setLevel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。