當前位置: 首頁>>代碼示例>>Python>>正文


Python journal.Reader方法代碼示例

本文整理匯總了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 
開發者ID:rpm-software-management,項目名稱:dnf-plugin-system-upgrade,代碼行數:18,代碼來源:system_upgrade.py

示例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 
開發者ID:aiven,項目名稱:journalpump,代碼行數:20,代碼來源:journalpump.py

示例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) 
開發者ID:ogarcia,項目名稱:sysdweb,代碼行數:5,代碼來源:systemd.py

示例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 
開發者ID:WoTTsecurity,項目名稱:agent,代碼行數:14,代碼來源:journal_helper.py

示例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 
開發者ID:aiven,項目名稱:journalpump,代碼行數:49,代碼來源:journalpump.py


注:本文中的systemd.journal.Reader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。