本文整理汇总了Python中shinken.log.logger.setLevel函数的典型用法代码示例。如果您正苦于以下问题:Python setLevel函数的具体用法?Python setLevel怎么用?Python setLevel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setLevel函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_human_timestamp_format
def test_human_timestamp_format(self):
"test output using the human timestamp format"
shinken_logger.setLevel(INFO)
self._collector = Collector()
sys.stdout = StringIO()
shinken_logger.handlers[0].stream = sys.stdout
shinken_logger.load_obj(self._collector)
shinken_logger.set_human_format(True)
if isinstance(shinken_logger.handlers[0], ColorStreamHandler):
loglist = self.generic_tst(shinken_logger.info, 'Some log-message',
[1, 1],
[r'^\[.+?\] INFO: \[Shinken\] Some log-message$',
r'^\x1b\[35m\[.+?\] INFO: \[Shinken\] Some log-message\x1b\[0m$'])
else:
loglist = self.generic_tst(shinken_logger.info, 'Some log-message',
[1, 1],
[r'^\[.+?\] INFO: \[Shinken\] Some log-message$',
r'^\[.+?\] INFO: \[Shinken\] Some log-message$'])
times = loglist[1][0].split(' INFO: ', 1)[0]
_, time2 = times.rsplit('[', 1)
time.strptime(time2.rsplit(']')[0], '%a %b %d %H:%M:%S %Y')
logger.set_human_format(False)
示例2: main
def main(self):
try:
self.load_config_file()
# Setting log level
logger.setLevel(self.log_level)
# Force the debug level if the daemon is said to start with such level
if self.debug:
logger.setLevel('DEBUG')
self.look_for_early_exit()
self.do_daemon_init_and_start()
self.load_modules_manager()
self.http_daemon.register(self.interface)
self.http_daemon.register(self.istats)
#self.inject = Injector(self.sched)
#self.http_daemon.register(self.inject)
self.http_daemon.unregister(self.interface)
self.uri = self.http_daemon.uri
logger.info("[scheduler] General interface is at: %s", self.uri)
self.do_mainloop()
except Exception, exp:
self.print_unrecoverable(traceback.format_exc())
raise
示例3: main
def main(self):
try:
self.load_config_file()
# Setting log level
logger.setLevel(self.log_level)
# Force the debug level if the daemon is said to start with such level
if self.debug:
logger.setLevel('DEBUG')
# Look if we are enabled or not. If ok, start the daemon mode
self.look_for_early_exit()
self.load_parent_config()
for line in self.get_header():
logger.info(line)
logger.info("[Receiver] Using working directory: %s", os.path.abspath(self.workdir))
self.do_daemon_init_and_start()
self.load_modules_manager()
self.uri2 = self.http_daemon.register(self.interface)
logger.debug("The Arbiter uri it at %s", self.uri2)
self.uri3 = self.http_daemon.register(self.istats)
# Register ibroks
if self.ibroks is not None:
logger.debug("Deconnecting previous Broks Interface")
self.http_daemon.unregister(self.ibroks)
# Create and connect it
self.http_daemon.register(self.ibroks)
# We wait for initial conf
self.wait_for_initial_conf()
if not self.new_conf:
return
self.setup_new_conf()
self.modules_manager.set_modules(self.modules)
self.do_load_modules()
# and start external modules too
self.modules_manager.start_external_instances()
# Do the modules part, we have our modules in self.modules
# REF: doc/receiver-modules.png (1)
# Now the main loop
self.do_mainloop()
except Exception, exp:
self.print_unrecoverable(traceback.format_exc())
raise
示例4: test_basic_logging_log
def test_basic_logging_log(self):
sys.stdout = StringIO()
self._collector = Collector()
sh = StreamHandler(sys.stdout)
sh.setFormatter(defaultFormatter)
shinken_logger.handlers = []
shinken_logger.addHandler(sh)
shinken_logger.load_obj(self._collector)
shinken_logger.setLevel(DEBUG)
self.generic_tst(lambda x: naglog_result('info', x), 'Some log-message',
[1, 1], [r'^\[\d+\] Some log-message\n$', r'^\[\d+\] Some log-message$'])
示例5: test_basic_logging_info_colored
def test_basic_logging_info_colored(self):
shinken_logger.setLevel(INFO)
self._collector = Collector()
sys.stdout = StringIO()
shinken_logger.handlers[0].stream = sys.stdout
shinken_logger.load_obj(self._collector)
if isinstance(shinken_logger.handlers[0], ColorStreamHandler):
self.generic_tst(shinken_logger.info, 'Some log-message',
[1, 1],
[r'^\[.+?\] INFO: \[Shinken\] Some log-message$',
r'^\x1b\[95m\[.+?\] INFO: \[Shinken\] Some log-message\x1b\[0m$'])
else:
self.generic_tst(shinken_logger.info, 'Some log-message',
[1, 1],
[r'^\[.+?\] INFO:\s+Some log-message$',
r'^\[.+?\] INFO:\s+Some log-message$'])
示例6: main
def main(self):
try:
self.load_config_file()
# Setting log level
logger.setLevel(self.log_level)
# Force the debug level if the daemon is said to start with such level
if self.debug:
logger.setLevel('DEBUG')
for line in self.get_header():
logger.info(line)
logger.info("[Broker] Using working directory: %s", os.path.abspath(self.workdir))
# Look if we are enabled or not. If ok, start the daemon mode
self.look_for_early_exit()
self.do_daemon_init_and_start()
self.load_modules_manager()
self.uri2 = self.http_daemon.register(self.interface)
logger.debug("The Arbiter uri it at %s", self.uri2)
self.uri3 = self.http_daemon.register(self.istats)
# We wait for initial conf
self.wait_for_initial_conf()
if not self.new_conf:
return
self.setup_new_conf()
# Do the modules part, we have our modules in self.modules
# REF: doc/broker-modules.png (1)
self.hook_point('load_retention')
# Now the main loop
self.do_mainloop()
except Exception, exp:
self.print_unrecoverable(traceback.format_exc())
raise
示例7: add
from shinken.daemons.receiverdaemon import Receiver
from logging import ERROR
# Modules are by default on the ../modules
myself = os.path.abspath(__file__)
global modules_dir
modules_dir = os.environ.get('SHINKEN_MODULES_DIR', "modules")
class __DUMMY:
def add(self, obj):
pass
logger.load_obj(__DUMMY())
logger.setLevel(ERROR)
#############################################################################
def guess_sys_stdout_encoding():
''' Return the best guessed encoding to be used for printing on sys.stdout. '''
return (
getattr(sys.stdout, 'encoding', None)
or getattr(__stdout__, 'encoding', None)
or locale.getpreferredencoding()
or sys.getdefaultencoding()
or 'ascii'
)
示例8: main
def main(custom_args=None):
parser = optparse.OptionParser(
'',
version="%prog " + VERSION,
add_help_option=False)
parser.add_option('--proxy', dest="proxy",
help="""Proxy URI. Like http://user:[email protected]:3128""")
parser.add_option('-A', '--api-key',
dest="api_key", help=("Your API key for uploading the package to the "
"Shinken.io website. If you don't have one, "
"please go to your account page"))
parser.add_option('-l', '--list', action='store_true',
dest="do_list", help=("List available commands"))
parser.add_option('--init', action='store_true',
dest="do_init", help=("Initialize/refill your shinken.ini file "
"(default to %s)" % DEFAULT_CFG))
parser.add_option('-D', action='store_true',
dest="do_debug", help=("Enable the debug mode"))
parser.add_option('-c', '--config', dest="iniconfig", default=DEFAULT_CFG,
help=("Path to your shinken.ini file. Default: %s" % DEFAULT_CFG))
parser.add_option('-v', action='store_true',
dest="do_verbose", help=("Be more verbose"))
parser.add_option('-h', '--help', action='store_true',
dest="do_help", help=("Print help"))
# First parsing, for purely internal parameters, but disable
# errors, because we only want to see the -D -v things
old_error = parser.error
parser.error = lambda x: 1
opts, args = parser.parse_args(custom_args)
# reenable the errors for later use
parser.error = old_error
do_help = opts.do_help
if do_help and len(args) == 0:
parser.print_help()
sys.exit(0)
if opts.do_verbose:
logger.setLevel('INFO')
if opts.do_debug:
logger.setLevel('DEBUG')
cfg = None
if not os.path.exists(opts.iniconfig):
logger.debug('Missing configuration file!')
else:
cfg = ConfigParser.ConfigParser()
cfg.read(opts.iniconfig)
for section in cfg.sections():
if section not in CONFIG:
CONFIG[section] = {}
for (key, value) in cfg.items(section):
CONFIG[section][key] = value
# Now replace if given in command line
if opts.api_key:
CONFIG['shinken.io']['api_key'] = opts.api_key
logger.debug("Using given api-key in command line")
if opts.proxy:
CONFIG['shinken.io']['proxy'] = opts.proxy
logger.debug("Using given proxy in command line")
CLI = CLICommander(CONFIG, cfg, opts)
# We should look on the sys.argv if we find a valid keywords to
# call in one loop or not.
def hack_sys_argv():
command_values = []
internal_values = []
# print "RARGS", parser.rargs
founded = False
for arg in sys.argv:
if arg in CLI.keywords:
founded = True
# Did we found it?
if founded:
command_values.append(arg)
else: # ok still not, it's for the shinekn command so
internal_values.append(arg)
sys.argv = internal_values
return command_values
# We will remove specific commands from the sys.argv list and keep
# them for parsing them after
command_args = hack_sys_argv()
# Global command parsing, with the error enabled this time
opts, args = parser.parse_args(custom_args)
if opts.do_help:
if len(command_args) == 0:
logger.error("Cannot find any help for you")
sys.exit(1)
a = command_args.pop(0)
if a not in CLI.keywords:
logger.error("Cannot find any help for %s" % a)
#.........这里部分代码省略.........
示例9: sig_handler
# or parent directory to support running without installation.
# Submodules will then be loaded from there, too.
import imp
imp.load_module('shinken',
*imp.find_module('shinken',
[os.path.realpath("."),
os.path.realpath(".."),
os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])),
"..")]))
from shinken.bin import VERSION
from shinken.log import logger, cprint, nagFormatter
from shinken.objects.config import Config
logger.setLevel('WARNING')
logger.handlers[0].setFormatter(nagFormatter)
# Handle some signals
def sig_handler(signalnum, handle):
""" Handle some signals """
sys.exit(0)
signal.signal(signal.SIGTERM, sig_handler)
signal.signal(signal.SIGINT, sig_handler)
CONFIG = {}
class Dummy():