summaryrefslogtreecommitdiff
path: root/systemd/journal.py
Commit message (Collapse)AuthorAgeFilesLines
* journal: fix repr of JournalHandler to match python3.6Zbigniew Jędrzejewski-Szmek2017-03-251-1/+1
| | | | | | We get <systemd.journal.JournalHandler object at ...> in older versions, and <JournalHandler (NOTSET)> in since Python 3.6. https://github.com/python/cpython/commit/c0752011472790e34d171b89f4b862cc3fd8ad08
* journal: do not convert extra args to string in JournalHandlerZbigniew Jędrzejewski-Szmek2017-03-191-4/+6
| | | | | | send() already does conversions in a type-specific way, and doing it in journal handler would defeat those conversions. In particular, UUIDs would be converted to early and have dashes.
* Remove mid from JournalHandlerWesley Bowman2017-03-191-2/+0
| | | | | | Removed mid variable from JournalHandler since the MESSAGE_ID is already in the extras variable. MESSAGE_ID was being set to None, but this won't appear in the logs.
* journal: rename SENDER_FUNCTION to sender_functionZbigniew Jędrzejewski-Szmek2017-03-191-2/+5
| | | | | | | Let's not try to make it look like a journal field. It should be a normal parameter. Followup for dce0a855c3281e7051b1cbe0f73386d1c90ef320.
* Fix styling to match PEP8 in most places (#45)Wesley Bowman2017-03-141-6/+19
| | | | Backwards compatibility for mapPriority is retained.
* journal: improve docstring formatting a bitZbigniew Jędrzejewski-Szmek2017-03-121-4/+4
|
* Adjust import order, spacing, operators as recommended by pylintZbigniew Jędrzejewski-Szmek2017-03-121-5/+6
|
* Prevent non-str values from being concatenated with + (#40)Jimmy Cao2017-03-121-3/+3
| | | | Make _make_line concatenate only strings directly.
* Merge pull request #31 from keszybz/is_socket_sockaddrZbigniew Jędrzejewski-Szmek2017-03-111-4/+4
|\ | | | | daemon: add basic support for sd_is_socket_sockaddr
| * tests: skip journal.stream tests on ENOENT errorZbigniew Jędrzejewski-Szmek2016-12-151-4/+4
| | | | | | | | | | | | | | | | When running in a chroot, doctests that called journal.stream would fail with ENOENT. Move the tests to test_journal, where we can skip tests properly (without uglyfying the documentation). Fixes #32.
* | replace dict.iteritems() with dict.items() to support py3 (#39)Jeongsoo, Park2017-03-111-12/+14
| | | | | | py3 doesn't have dict.iteritems() anymore.
* | Python 3.6 invalid escape sequence deprecation fixes (#43)Ville Skyttä2017-03-111-2/+2
|/ | | https://docs.python.org/3/whatsnew/3.6.html#deprecated-python-behavior
* Include all fields from record (#30)Oleksii Shevchuk2016-10-271-1/+16
| | | | This approach allows to use LoggerAdapter+extra or .info(.., extra={}) to transparently add extra fields to journal.
* journal: allow stream() to be used without any argumentsZbigniew Jędrzejewski-Szmek2016-10-171-3/+12
| | | | | | | | | It's fairly easy to provide a reasonable default for the first argument. Let's do that. Also, the documentation was misleading, suggesting that the function itself can be passed as file parameter to print(). Use a different name for the temporary variable to clarify that.
* journal: bump default log level for stream() to INFOZbigniew Jędrzejewski-Szmek2016-10-171-1/+1
| | | | | By default debug messages are ignored, and INFO should be used for "normal" messages.
* docs: fix sphinx format warningZbigniew Jędrzejewski-Szmek2016-09-221-3/+3
| | | | build/lib.linux-x86_64-3.5/systemd/journal.py:docstring of systemd.journal.stream:15: WARNING: Literal block expected; none found.
* journal: convert seek_realtime argument to microsecondsZbigniew Jędrzejewski-Szmek2016-09-211-5/+16
| | | | | | | | | | | | | This somewhat breaks backwards compatibility, but not for the previously documented arguments: floats are now interpreted differently, but ints and datetime.datetime objects are interpreted the same as before. But the documentation clearly stated that only ints and datetime.datetime objects were allowed. This makes seek_realtime match seek_monotonic and other functions which take time and follows the principle of least surprise. Fixes #21.
* reader: add SD_JOURNAL_OS_ROOT and rework flag passingZbigniew Jędrzejewski-Szmek2016-09-211-1/+9
| | | | | | | | | | | | | | | | | Let's pass any flags through to the journal functions without checking validity. Those functions do their own checking, so there's no need to second-guess. The semantics for _Reader(flags=0) are a bit changed: before, this would be transformed into sd_journal_open(SD_J_LOCAL_ONLY). Now, this results in sd_journal_open(0). Previous behaviour should be achieved by not specifying the flags at all. This change is necessary, because previously it was not possible to pass flags=0 to sd_journal_open(0), i.e. it was not possible to "merge" journals through the Python interface. Similarly, Reader(flags=0) now means to open all journals, and Reader(flags=None) is the same as Reader(flags=LOCAL_ONLY).
* journal: allow sd_journal_open_directory_fd to be usedZbigniew Jędrzejewski-Szmek2016-09-211-2/+3
|
* Reformat documentation to be more PEP257-compliantZbigniew Jędrzejewski-Szmek2016-09-201-118/+131
| | | | | | | | | | Wrapping the sources to ~80 columns means that the formatted output is annoying to read. Rewrap to ~74 columns in the output. Also remove some obsolete descritions of journal permissions and refer to journalctl(1) instead. Add some missing docstrings.
* Use log.warning instead of deprecated log.warn in example codeVille Skyttä2016-05-211-2/+2
|
* Fixes Reader.seek_monotonic(datetime.timedelta)Michael Herold2015-12-101-1/+1
|
* Do not assume specific output from the journalZbigniew Jędrzejewski-Szmek2015-10-251-2/+1
| | | | | While we *usually* get those messages from udev, in many tests environments this will not be true, so just do not try to check the output at all.
* journal: allow numbers in field identifiersZbigniew Jędrzejewski-Szmek2015-09-171-2/+2
|
* tests: add tests for Reader initializationZbigniew Jędrzejewski-Szmek2015-09-171-1/+1
|
* journal: reindent to 4 spacesZbigniew Jędrzejewski-Szmek2015-09-171-158/+156
|
* Normalize some strange indentationZbigniew Jędrzejewski-Szmek2015-09-081-7/+8
|
* tests: adapt to python2.7 output againZbigniew Jędrzejewski-Szmek2015-09-051-3/+2
|
* tests: enable doctests in the sourcesZbigniew Jędrzejewski-Szmek2015-09-051-6/+12
| | | | | | | | | Unfortunately the "standard" way to access the names in the defined module does not work. I find it nicer to explicitly import, e.g. from systemd import journal, because then the examples correspond more closely to what a user would use. The only exception is made for JournalHandler, because journal.JournalHandler is a tad to long.
* tree-wide: systemd→python-systemd in headersZbigniew Jędrzejewski-Szmek2015-08-071-3/+3
|
* Update LICENSE file and classifiersZbigniew Jędrzejewski-Szmek2015-07-051-1/+0
| | | | | | The license was originally MIT, but when this module became part of systemd, it was changed to LGPLv2+. All files had correct headers, so only the LICENSE file needs updating. Take the opportunity to add classifiers to setup.py.
* systemd-python: use .hex instead of .get_hex()Zbigniew Jędrzejewski-Szmek2015-07-051-3/+3
| | | | | | It turns out the latter got removed in Python 3. https://bugs.freedesktop.org/show_bug.cgi?id=77086
* systemd-python: convert keyword value to stringRichard Marko2015-07-051-0/+2
| | | | | | | | Allows using journal.send('msg', PRIORITY=journal.LOG_CRIT) Before this commit this results in TypeError: cannot concatenate 'str' and 'int' objects and requires passing PRIORITY value as string to work.
* systemd-python: add support for sd_j_open_filesZbigniew Jędrzejewski-Szmek2015-07-051-3/+4
| | | | Also export missing flags.
* systemd-python: fix iterationZbigniew Jędrzejewski-Szmek2015-07-051-12/+12
| | | | | Back in 6a58bf4135 raising stop iteration was removed from the C code, but wasn't added in the Python counterpart.
* systemd-python: do not attempt to convert str to bytesZbigniew Jędrzejewski-Szmek2015-07-051-0/+4
| | | | Bug-spotted-by: Steven Hiscocks <steven-systemd@hiscocks.me.uk>
* systemd-python: add __version__ stringsZbigniew Jędrzejewski-Szmek2015-07-051-1/+1
|
* Spelling fixesVille Skyttä2015-07-051-1/+1
|
* systemd-python: attach fields to JournalHandler, add SYSLOG_IDENTIFIERZbigniew Jędrzejewski-Szmek2015-07-051-9/+33
| | | | | | | | | Arbitrary fields can be attached at the level of the handler, and they'll be sent with all messages from this handler. This facility is used to attach SYSLOG_IDENTIFIER to all messages, since otherwise journald attaches SYSLOG_IDENTIFIER=python or something similar, which is completely useless.
* python-systemd: Reader return special fields and _Reader changesSteven Hiscocks2015-07-051-3/+42
| | | | | | | | | | | | | | | | | | | | | | | | Changes to _Reader make it match closer to C API, by removing `get_next` and `get_previous`. A `get_all` method added, which returns dictionary of fields using C API SD_JOURNAL_FOREACH_DATA macro, which can be used in conjunction with `next`. _Reader `get`, `next`, `get_{realtime,monotonic,cursor}` and new `previous` methods are made private. This is so the traversal and getting of journal fields can be made transparent in the python interface. Reader now solely implements `get_next` and `get_previous`, returning a standard dictionary (future: other mapping types?) with all standard and special fields through the converters. This makes the output the same as journalctl json/export format output. Iterator methods also moved to Reader, as they do not function as intend with changes to _Reader. These changes also mean that more optimised journal interfaces can be made more easily from _Reader, by avoiding getting of unrequired fields by using the `_get` method, and avoiding field conversions.
* systemd-python: fix wait bugSteven Hiscocks2015-07-051-2/+1
|
* systemd-python: allow retrieval of single fieldsZbigniew Jędrzejewski-Szmek2015-07-051-1/+9
| | | | | This can give huge efficiency gains, e.g. if only MESSAGE is required and all other fields can be ignored.
* systemd-python: cleanup up usec_t handlingZbigniew Jędrzejewski-Szmek2015-07-051-4/+16
| | | | | | | | | The behaviour wrt. seconds vs. microseconds was inconsistent. Now _Reader always uses native units (us), while Reader always uses seconds and accepts both floats and ints. This way the conversion is always done in the Python layer, and the lower level API allows access to the journal API without the potentially lossy conversion between double and uint64_t.
* systemd-python: add journal.get_catalog()Zbigniew Jędrzejewski-Szmek2015-07-051-1/+2
| | | | | This one wraps sd_journal_get_catalog_from_message_id. Thanks to Python namespacing, we can stick to a shorter name.
* systemd-python: update documentation for new systemd-journal groupZbigniew Jędrzejewski-Szmek2015-07-051-1/+1
|
* systemd-python: refuse path and flags together in __init__Zbigniew Jędrzejewski-Szmek2015-07-051-3/+2
| | | | | | | | | It's better to explictly check, instead of just documenting it. The return value from init is changed from 1 to -1 on error. Python seems to ignore 1 every second time. Looks like a bug in Python, but the return value doesn't seem to be documented anywhere, and -1 works as expected... so let's just use that.
* systemd-python: split .seek() into .seek_head() and .seek_tail()Zbigniew Jędrzejewski-Szmek2015-07-051-1/+0
| | | | | This way python code follows the original interface more closely. Also, .seek(0, journal.SEEK_END) was just to much to type.
* systemd-python: catch only ValueErrors in conversion codeZbigniew Jędrzejewski-Szmek2015-07-051-38/+60
| | | | | | | | | | | | | | | | | | First of all, 'try: ... except: ...' (with no exception specified) is always a no-no, since it catches all BaseExceptions, which includes ^C and other stuff which should almost never be caught. Now the conversion is stricter, and only one conversion is attempted, and only a ValueEror is caught. It seems reasonable to catch ValueErrors, since the entries in the journal are not verified, and any erroneous application might log a field which cannot be converted. The consumer of events must only check if a field is an instance of bytes and can otherwise assume that the conversion was performed correctly. Order of arguments in Reader.__init__ has been changed to match order in _Reader.__init__. Conversions have been updated to work under Python 2 and 3.
* python-systemd: rename Journal to ReaderZbigniew Jędrzejewski-Szmek2015-07-051-14/+14
| | | | | | It seems inevitable that we'll also grow a writing interface, and then it'll be cumbersome to have a "Journal" for reading, and a "Writer" for writing.
* systemd-python: return both parts of sd_journal_get_monotonic_usecZbigniew Jędrzejewski-Szmek2015-07-051-1/+7
| | | | | In Python 3, a named tuple is used. In Python 2, a simple tuple is used. In either case, the pair is (timestamp, bootid).