From 78a234c6d3b82775a41c866b3a242d7829851b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbyszek=20J=C4=99drzejewski-Szmek?= Date: Tue, 10 Jul 2012 10:14:56 +0200 Subject: Wrap README to 80 lines --- README.md | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 21e9111..69ae4f6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ journald-python =============== -Python module for native access to the journald facilities in recent versions of systemd. In particular, this capability includes passing key/value pairs as fields that journald can use for filtering. +Python module for native access to the journald facilities in recent +versions of systemd. In particular, this capability includes passing +key/value pairs as fields that journald can use for filtering. Installation ============ @@ -17,15 +19,20 @@ Usage Quick example: import journald - journald.send('MESSAGE=Hello world.') - journald.send('MESSAGE=Hello, again, world.', 'FIELD2=Greetings!', 'FIELD3=Guten tag.') + journald.send('MESSAGE=Hello world') + journald.send('MESSAGE=Hello, again, world', 'FIELD2=Greetings!', 'FIELD3=Guten tag') journald.send('ARBITRARY=anything', 'FIELD3=Greetings!') Notes: - * Each argument must be in the form of a KEY=value pair, environmental variable style. - * Unlike the native C version of journald's sd_journal_send(), printf-style substitution is not supported. Perform any substitution using Python's % operator or .format() capabilities first. - * The base message is usually sent in the form MESSAGE=hello. The MESSAGE field is, however, not required. + * Each argument must be in the form of a KEY=value pair, + environmental variable style. + * Unlike the native C version of journald's sd_journal_send(), + printf-style substitution is not supported. Perform any + substitution using Python's % operator or .format() capabilities + first. + * The base message is usually sent in the form MESSAGE=hello. The + MESSAGE field is, however, not required. * Invalid or zero arguments results in nothing recorded in journald. Viewing Output -- cgit v1.2.1 From 48a2295bb7578804bd8106c7425585479c28e03b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 28 Jun 2012 07:12:21 -0400 Subject: Check the return value from sd_journal_sendv --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index 69ae4f6..f7d4912 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,9 @@ Notes: first. * The base message is usually sent in the form MESSAGE=hello. The MESSAGE field is, however, not required. - * Invalid or zero arguments results in nothing recorded in journald. + * A ValueError is thrown is thrown if sd_journald_sendv() results in + an error. This might happen if there are no arguments or one of them + is invalid. Viewing Output ============== -- cgit v1.2.1 From 557184bb56240bfcf05d250e5bf9049eaf6d0ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 28 Jun 2012 13:32:03 -0400 Subject: Add frontend module in pure-Python and hide old module journald.send() is renamed to journald.sendv(), and a replacement journald.send() is added. This new function has a more pythonic API, where one positional argument is used for the message, and keyword arguments can be used to specify other fields. Implementing argument parsing in C would be really painful, for little gain, so a pure-python module is added, which provides send(), which in turn calls sendv(). --- README.md | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index f7d4912..e21b601 100644 --- a/README.md +++ b/README.md @@ -19,14 +19,26 @@ Usage Quick example: import journald - journald.send('MESSAGE=Hello world') - journald.send('MESSAGE=Hello, again, world', 'FIELD2=Greetings!', 'FIELD3=Guten tag') - journald.send('ARBITRARY=anything', 'FIELD3=Greetings!') + journald.send('Hello world') + journald.send('Hello, again, world', FIELD2='Greetings!', FIELD3='Guten tag') + journald.send('Binary message', BINARY='\xde\xad\xbe\xef') + +There is one required argument -- the message, and additional fields +can be specified as keyword arguments. Following the journald API, all +names are uppercase. + +The journald sendv call can also be accessed directly: + + import journald + journald.sendv('MESSAGE=Hello world') + journald.sendv('MESSAGE=Hello, again, world', 'FIELD2=Greetings!', + 'FIELD3=Guten tag') + journald.sendv('MESSAGE=Binary message', 'BINARY=\xde\xad\xbe\xef') + +The two examples should give the same results in the log. Notes: - * Each argument must be in the form of a KEY=value pair, - environmental variable style. * Unlike the native C version of journald's sd_journal_send(), printf-style substitution is not supported. Perform any substitution using Python's % operator or .format() capabilities -- cgit v1.2.1 From 2b1a5c9ff41e6c48d9837a24e4afdafce34e74d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbyszek=20J=C4=99drzejewski-Szmek?= Date: Thu, 12 Jul 2012 10:41:17 +0200 Subject: Allow UTF-8 in message payload Allow UTF-8, and force encoding as UTF-8 if the payload is known to be text. Under Python 3, this means that bytes payload is sent as-is, and strings are encoded to UTF-8. Under Python 2, this means that unicode payload is encoded to UTF-8, and the rest is sent as-is, because there we are missing the extra information to distinguish text and binary data. IOW, under Python 2, it is the responsibility of the called to provide properly encoded payload, and under Python 3, there is extra hand-holding which should help catch mistakes. Fields which are certain to be text (MESSAGE, MESSAGE_ID, CODE_FILE, CODE_FUNC) are text-only. The names of fields are text-only too. The payload of other fields can be binary. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index e21b601..3fc925e 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Quick example: import journald journald.send('Hello world') journald.send('Hello, again, world', FIELD2='Greetings!', FIELD3='Guten tag') - journald.send('Binary message', BINARY='\xde\xad\xbe\xef') + journald.send('Binary message', BINARY=b'\xde\xad\xbe\xef') There is one required argument -- the message, and additional fields can be specified as keyword arguments. Following the journald API, all @@ -33,7 +33,7 @@ The journald sendv call can also be accessed directly: journald.sendv('MESSAGE=Hello world') journald.sendv('MESSAGE=Hello, again, world', 'FIELD2=Greetings!', 'FIELD3=Guten tag') - journald.sendv('MESSAGE=Binary message', 'BINARY=\xde\xad\xbe\xef') + journald.sendv('MESSAGE=Binary message', b'BINARY=\xde\xad\xbe\xef') The two examples should give the same results in the log. -- cgit v1.2.1