本文整理汇总了Python中systemd.journal.Reader方法的典型用法代码示例。如果您正苦于以下问题:Python journal.Reader方法的具体用法?Python journal.Reader怎么用?Python journal.Reader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类systemd.journal
的用法示例。
在下文中一共展示了journal.Reader方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_boots
# 需要导入模块: from systemd import journal [as 别名]
# 或者: from systemd.journal import Reader [as 别名]
def find_boots(message_id):
"""Find all boots with this message id.
Returns the entries of all found boots.
"""
j = journal.Reader()
j.add_match(MESSAGE_ID=message_id.hex, # identify the message
_UID=0) # prevent spoofing of logs
oldboot = None
for entry in j:
boot = entry['_BOOT_ID']
if boot == oldboot:
continue
oldboot = boot
yield entry
示例2: get_resume_cursor
# 需要导入模块: from systemd import journal [as 别名]
# 或者: from systemd.journal import Reader [as 别名]
def get_resume_cursor(self):
"""Find the sender cursor location where a new JournalReader instance should resume reading from"""
if not self.senders:
self.log.info("Reader has no senders, using reader's resume location")
return self.cursor
for sender_name, sender in self.senders.items():
state = sender.get_state()
cursor = state["sent"]["cursor"]
if cursor is None:
self.log.info("Sender %r needs a full catchup from beginning, resuming from journal start", sender_name)
return None
# TODO: pick oldest sent cursor
self.log.info("Resuming reader from sender's ('%s') position", sender_name)
return cursor
return None
示例3: __init__
# 需要导入模块: from systemd import journal [as 别名]
# 或者: from systemd.journal import Reader [as 别名]
def __init__(self, unit):
self.reader = journal.Reader()
self.reader.add_match(_SYSTEMD_UNIT=unit)
示例4: get_journal_records
# 需要导入模块: from systemd import journal [as 别名]
# 或者: from systemd.journal import Reader [as 别名]
def get_journal_records():
'''
Get syslog records as returned by
journalctl -l SYSLOG_FACILITY=10 --priority=5 --since "1 hour ago"
'''
j = journal.Reader()
j.this_boot()
j.log_level(journal.LOG_INFO)
last_hour = time.time() - 60**2
j.seek_realtime(last_hour)
j.add_match(SYSLOG_FACILITY=10)
return j
示例5: configure_readers
# 需要导入模块: from systemd import journal [as 别名]
# 或者: from systemd.journal import Reader [as 别名]
def configure_readers(self):
new_config = self.config.get("readers", {})
if self.readers_active_config == new_config:
# No changes in readers, no reconfig required
return
# replace old readers with new ones
for reader in self.readers.values():
reader.request_stop()
# Don't close the journald_reader here because it could currently be in use.
# This may in some situations leak some resources but possible leak is small
# and config reloads are typically quite infrequent.
reader.unregister_from_poll(self.poller)
self.readers = {}
state = self.load_state()
for reader_name, reader_config in new_config.items():
reader_state = state.get("readers", {}).get(reader_name, {})
resume_cursor = None
for sender_name, sender in reader_state.get("senders", {}).items():
sender_cursor = sender["sent"]["cursor"]
if sender_cursor is None:
self.log.info("Sender %r for reader %r needs full sync from beginning",
sender_name, reader_name)
resume_cursor = None
break
# TODO: pick the OLDEST cursor
resume_cursor = sender_cursor
self.log.info("Reader %r resuming from cursor position: %r", reader_name, resume_cursor)
initial_position = reader_config.get("initial_position")
reader = JournalReader(
name=reader_name,
config=reader_config,
field_filters=self.field_filters,
geoip=self.geoip,
stats=self.stats,
msg_buffer_max_length=self.config.get("msg_buffer_max_length", 50000),
seek_to=resume_cursor,
initial_position=initial_position,
tags=self.make_tags(),
searches=reader_config.get("searches", {}),
)
self.readers[reader_name] = reader
self.readers_active_config = new_config