summaryrefslogtreecommitdiff
path: root/docs/journal.rst
blob: 8e4b5b6518aaba37dab9093e60903e3a6177222c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
`systemd.journal` module
========================

.. automodule:: systemd.journal
   :members: send, sendv, stream, stream_fd
   :undoc-members:

`JournalHandler` class
----------------------

.. autoclass:: JournalHandler

Accessing the Journal
---------------------

.. autoclass:: _Reader
   :undoc-members:
   :inherited-members:

.. autoclass:: Reader
   :undoc-members:
   :inherited-members:

   .. automethod:: __init__

.. autofunction:: _get_catalog
.. autofunction:: get_catalog

.. autoclass:: Monotonic

.. autoattribute:: systemd.journal.DEFAULT_CONVERTERS

Example: polling for journal events
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This example shows that journal events can be waited for (using
e.g. `poll`). This makes it easy to integrate Reader in an external
event loop:

  >>> import select
  >>> from systemd import journal
  >>> j = journal.Reader()
  >>> j.seek_tail()
  >>> journal.send('testing 1,2,3')   # make sure we have something to read
  >>> j.add_match('MESSAGE=testing 1,2,3')
  >>> p = select.poll()
  >>> p.register(j, j.get_events())
  >>> p.poll()                        # doctest: +SKIP
  [(3, 1)]
  >>> j.get_next()                    # doctest: +SKIP
  {'_AUDIT_LOGINUID': 1000,
   '_CAP_EFFECTIVE': '0',
   '_SELINUX_CONTEXT': 'unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023',
   '_GID': 1000,
   'CODE_LINE': 1,
   '_HOSTNAME': '...',
   '_SYSTEMD_SESSION': 52,
   '_SYSTEMD_OWNER_UID': 1000,
   'MESSAGE': 'testing 1,2,3',
   '__MONOTONIC_TIMESTAMP':
      journal.Monotonic(timestamp=datetime.timedelta(2, 76200, 811585),
                        bootid=UUID('958b7e26-df4c-453a-a0f9-a8406cb508f2')),
   'SYSLOG_IDENTIFIER': 'python3',
   '_UID': 1000,
   '_EXE': '/usr/bin/python3',
   '_PID': 7733,
   '_COMM': '...',
   'CODE_FUNC': '<module>',
   'CODE_FILE': '<doctest journal.rst[4]>',
   '_SOURCE_REALTIME_TIMESTAMP':
       datetime.datetime(2015, 9, 5, 13, 17, 4, 944355),
   '__CURSOR': 's=...',
   '_BOOT_ID': UUID('958b7e26-df4c-453a-a0f9-a8406cb508f2'),
   '_CMDLINE': '/usr/bin/python3 ...',
   '_MACHINE_ID': UUID('263bb31e-3e13-4062-9bdb-f1f4518999d2'),
   '_SYSTEMD_SLICE': 'user-1000.slice',
   '_AUDIT_SESSION': 52,
   '__REALTIME_TIMESTAMP': datetime.datetime(2015, 9, 5, 13, 17, 4, 945110),
   '_SYSTEMD_UNIT': 'session-52.scope',
   '_SYSTEMD_CGROUP': '/user.slice/user-1000.slice/session-52.scope',
   '_TRANSPORT': 'journal'}



Journal access types
~~~~~~~~~~~~~~~~~~~~

.. autoattribute:: systemd.journal.LOCAL_ONLY
.. autoattribute:: systemd.journal.RUNTIME_ONLY
.. autoattribute:: systemd.journal.SYSTEM
.. autoattribute:: systemd.journal.CURRENT_USER

Journal event types
~~~~~~~~~~~~~~~~~~~

.. autoattribute:: systemd.journal.NOP
.. autoattribute:: systemd.journal.APPEND
.. autoattribute:: systemd.journal.INVALIDATE