本文整理汇总了Python中shinken.log.logger.set_human_format函数的典型用法代码示例。如果您正苦于以下问题:Python set_human_format函数的具体用法?Python set_human_format怎么用?Python set_human_format使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_human_format函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: test_reset_human_timestamp_format
def test_reset_human_timestamp_format(self):
# ensure human timestamp format is set and working
self.test_human_timestamp_format()
# turn of human timestamp format
logger.set_human_format(False)
# test for normal format
self.test_basic_logging_info()
示例3: test_human_timestamp_format
def test_human_timestamp_format(self):
logger.set_level(logger.INFO)
logger.set_human_format(True)
msgs, lines = self._put_log(logger.info, 'Some ] log-message')
self.assertRegexpMatches(msgs[0],
r'^\[[^\]]+] Info :\s+\[Tiroler Schinken\] Some \] log-message\n$')
time.strptime(msgs[0].split(' Info : ', 1)[0], '[%a %b %d %H:%M:%S %Y]')
self.assertRegexpMatches(lines[0],
r'^\[[^\]]+] Info :\s+\[Tiroler Schinken\] Some \] log-message$')
time.strptime(msgs[0].split(' Info : ', 1)[0], '[%a %b %d %H:%M:%S %Y]')
logger.set_human_format(False)
示例4: test_setting_and_unsetting_human_timestamp_format
def test_setting_and_unsetting_human_timestamp_format(self):
# :hack: logging.human_timestamp_log is a global variable
self.assertEqual(logging.human_timestamp_log, False)
logger.set_human_format(True)
self.assertEqual(logging.human_timestamp_log, True)
logger.set_human_format(False)
self.assertEqual(logging.human_timestamp_log, False)
logger.set_human_format(True)
self.assertEqual(logging.human_timestamp_log, True)
logger.set_human_format(False)
self.assertEqual(logging.human_timestamp_log, False)
示例5: setup_new_conf
def setup_new_conf(self):
pk = self.new_conf
conf_raw = pk['conf']
override_conf = pk['override_conf']
modules = pk['modules']
satellites = pk['satellites']
instance_name = pk['instance_name']
push_flavor = pk['push_flavor']
skip_initial_broks = pk['skip_initial_broks']
accept_passive_unknown_check_results = pk['accept_passive_unknown_check_results']
# horay, we got a name, we can set it in our stats objects
statsmgr.register(instance_name, 'scheduler')
t0 = time.time()
conf = cPickle.loads(conf_raw)
logger.debug("Conf received at %d. Unserialized in %d secs" % (t0, time.time() - t0))
self.new_conf = None
# Tag the conf with our data
self.conf = conf
self.conf.push_flavor = push_flavor
self.conf.instance_name = instance_name
self.conf.skip_initial_broks = skip_initial_broks
self.conf.accept_passive_unknown_check_results = accept_passive_unknown_check_results
self.cur_conf = conf
self.override_conf = override_conf
self.modules = modules
self.satellites = satellites
#self.pollers = self.app.pollers
if self.conf.human_timestamp_log:
logger.set_human_format()
# Now We create our pollers
for pol_id in satellites['pollers']:
# Must look if we already have it
already_got = pol_id in self.pollers
p = satellites['pollers'][pol_id]
self.pollers[pol_id] = p
if p['name'] in override_conf['satellitemap']:
p = dict(p) # make a copy
p.update(override_conf['satellitemap'][p['name']])
proto = 'http'
if p['use_ssl']:
proto = 'https'
uri = '%s://%s:%s/' % (proto, p['address'], p['port'])
self.pollers[pol_id]['uri'] = uri
self.pollers[pol_id]['last_connection'] = 0
# First mix conf and override_conf to have our definitive conf
for prop in self.override_conf:
#print "Overriding the property %s with value %s" % (prop, self.override_conf[prop])
val = self.override_conf[prop]
setattr(self.conf, prop, val)
if self.conf.use_timezone != '':
logger.debug("Setting our timezone to %s" % str(self.conf.use_timezone))
os.environ['TZ'] = self.conf.use_timezone
time.tzset()
if len(self.modules) != 0:
logger.debug("I've got %s modules" % str(self.modules))
# TODO: if scheduler had previous modules instanciated it must clean them!
self.modules_manager.set_modules(self.modules)
self.do_load_modules()
# give it an interface
# But first remove previous interface if exists
if self.ichecks is not None:
logger.debug("Deconnecting previous Check Interface")
self.http_daemon.unregister(self.ichecks)
# Now create and connect it
self.ichecks = IChecks(self.sched)
self.http_daemon.register(self.ichecks)
logger.debug("The Scheduler Interface uri is: %s" % self.uri)
# Same for Broks
if self.ibroks is not None:
logger.debug("Deconnecting previous Broks Interface")
self.http_daemon.unregister(self.ibroks)
# Create and connect it
self.ibroks = IBroks(self.sched)
self.http_daemon.register(self.ibroks)
logger.info("Loading configuration.")
self.conf.explode_global_conf()
# we give sched it's conf
self.sched.reset()
self.sched.load_conf(self.conf)
self.sched.load_satellites(self.pollers, self.reactionners)
# We must update our Config dict macro with good value
# from the config parameters
self.sched.conf.fill_resource_macros_names_macros()
#.........这里部分代码省略.........
示例6: setup_new_conf
def setup_new_conf(self):
#self.use_ssl = self.app.use_ssl
(conf, override_conf, modules, satellites) = self.new_conf
self.new_conf = None
# In fact it make the scheduler just DIE as a bad guy.
# Must manage it better or not manage it at all!
#if self.cur_conf and self.cur_conf.magic_hash == conf.magic_hash:
# print("I received a conf with same hash than me, I skip it.")
# return
self.conf = conf
self.cur_conf = conf
self.override_conf = override_conf
self.modules = modules
self.satellites = satellites
#self.pollers = self.app.pollers
if self.conf.human_timestamp_log:
logger.set_human_format()
# Now We create our pollers
for pol_id in satellites['pollers']:
# Must look if we already have it
already_got = pol_id in self.pollers
p = satellites['pollers'][pol_id]
self.pollers[pol_id] = p
uri = pyro.create_uri(p['address'], p['port'], 'Schedulers', self.use_ssl)
self.pollers[pol_id]['uri'] = uri
self.pollers[pol_id]['last_connection'] = 0
#First mix conf and override_conf to have our definitive conf
for prop in self.override_conf:
#print "Overriding the property %s with value %s" % (prop, self.override_conf[prop])
val = self.override_conf[prop]
setattr(self.conf, prop, val)
if self.conf.use_timezone != '':
print "Setting our timezone to", self.conf.use_timezone
os.environ['TZ'] = self.conf.use_timezone
time.tzset()
if len(self.modules) != 0:
print "I've got modules", self.modules
# TODO: if scheduler had previous modules instanciated it must clean them !
self.modules_manager.set_modules(self.modules)
self.do_load_modules()
# And start external ones too
self.modules_manager.start_external_instances()
# give it an interface
# But first remove previous interface if exists
if self.ichecks is not None:
print "Deconnecting previous Check Interface from pyro_daemon"
self.pyro_daemon.unregister(self.ichecks)
#Now create and connect it
self.ichecks = IChecks(self.sched)
self.uri = self.pyro_daemon.register(self.ichecks, "Checks")
print "The Checks Interface uri is:", self.uri
#Same for Broks
if self.ibroks is not None:
print "Deconnecting previous Broks Interface from pyro_daemon"
self.pyro_daemon.unregister(self.ibroks)
#Create and connect it
self.ibroks = IBroks(self.sched)
self.uri2 = self.pyro_daemon.register(self.ibroks, "Broks")
print "The Broks Interface uri is:", self.uri2
print("Loading configuration..")
self.conf.explode_global_conf()
#we give sched it's conf
self.sched.reset()
self.sched.load_conf(self.conf)
self.sched.load_satellites(self.pollers, self.reactionners)
#We must update our Config dict macro with good value
#from the config parameters
self.sched.conf.fill_resource_macros_names_macros()
#print "DBG: got macors", self.sched.conf.macros
#Creating the Macroresolver Class & unique instance
m = MacroResolver()
m.init(self.conf)
#self.conf.dump()
#self.conf.quick_debug()
#Now create the external commander
#it's a applyer : it role is not to dispatch commands,
#but to apply them
e = ExternalCommandManager(self.conf, 'applyer')
#Scheduler need to know about external command to
#activate it if necessery
self.sched.load_external_command(e)
#External command need the sched because he can raise checks
#.........这里部分代码省略.........
示例7: setup_new_conf
def setup_new_conf(self):
pk = self.new_conf
conf_raw = pk["conf"]
override_conf = pk["override_conf"]
modules = pk["modules"]
satellites = pk["satellites"]
instance_name = pk["instance_name"]
push_flavor = pk["push_flavor"]
skip_initial_broks = pk["skip_initial_broks"]
accept_passive_unknown_check_results = pk["accept_passive_unknown_check_results"]
api_key = pk["api_key"]
secret = pk["secret"]
http_proxy = pk["http_proxy"]
statsd_host = pk["statsd_host"]
statsd_port = pk["statsd_port"]
statsd_prefix = pk["statsd_prefix"]
statsd_enabled = pk["statsd_enabled"]
statsd_interval = pk["statsd_interval"]
statsd_types = pk["statsd_types"]
statsd_pattern = pk["statsd_pattern"]
# horay, we got a name, we can set it in our stats objects
statsmgr.register(
self.sched,
instance_name,
"scheduler",
api_key=api_key,
secret=secret,
http_proxy=http_proxy,
statsd_host=statsd_host,
statsd_port=statsd_port,
statsd_prefix=statsd_prefix,
statsd_enabled=statsd_enabled,
statsd_interval=statsd_interval,
statsd_types=statsd_types,
statsd_pattern=statsd_pattern,
)
t0 = time.time()
conf = cPickle.loads(conf_raw)
logger.debug("Conf received at %d. Unserialized in %d secs", t0, time.time() - t0)
self.new_conf = None
# Tag the conf with our data
self.conf = conf
self.conf.push_flavor = push_flavor
self.conf.instance_name = instance_name
self.conf.skip_initial_broks = skip_initial_broks
self.conf.accept_passive_unknown_check_results = accept_passive_unknown_check_results
self.cur_conf = conf
self.override_conf = override_conf
self.modules = modules
self.satellites = satellites
# self.pollers = self.app.pollers
if self.conf.human_timestamp_log:
logger.set_human_format()
# Now We create our pollers
for pol_id in satellites["pollers"]:
# Must look if we already have it
already_got = pol_id in self.pollers
p = satellites["pollers"][pol_id]
self.pollers[pol_id] = p
if p["name"] in override_conf["satellitemap"]:
p = dict(p) # make a copy
p.update(override_conf["satellitemap"][p["name"]])
proto = "http"
if p["use_ssl"]:
proto = "https"
uri = "%s://%s:%s/" % (proto, p["address"], p["port"])
self.pollers[pol_id]["uri"] = uri
self.pollers[pol_id]["last_connection"] = 0
# Now We create our reactionners
for reac_id in satellites["reactionners"]:
# Must look if we already have it
already_got = reac_id in self.reactionners
reac = satellites["reactionners"][reac_id]
self.reactionners[reac_id] = reac
if reac["name"] in override_conf["satellitemap"]:
reac = dict(reac) # make a copy
reac.update(override_conf["satellitemap"][reac["name"]])
proto = "http"
if p["use_ssl"]:
proto = "https"
uri = "%s://%s:%s/" % (proto, reac["address"], reac["port"])
self.reactionners[reac_id]["uri"] = uri
self.reactionners[reac_id]["last_connection"] = 0
# First mix conf and override_conf to have our definitive conf
for prop in self.override_conf:
# print "Overriding the property %s with value %s" % (prop, self.override_conf[prop])
val = self.override_conf[prop]
setattr(self.conf, prop, val)
#.........这里部分代码省略.........