summaryrefslogtreecommitdiffstats
path: root/Doc/howto
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2013-01-23 09:32:10 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2013-01-23 09:32:10 (GMT)
commit9427b0313346fc629d9b3f5e0134fbacb8533c06 (patch)
tree467f72d228636da8545dbae52204a997a021d64f /Doc/howto
parent8bea200b98356c931aed6ae3ddfe2e1f5400ab71 (diff)
parent3d9e972270270e1498712065a17ec3a589ae8986 (diff)
downloadcpython-9427b0313346fc629d9b3f5e0134fbacb8533c06.zip
cpython-9427b0313346fc629d9b3f5e0134fbacb8533c06.tar.gz
cpython-9427b0313346fc629d9b3f5e0134fbacb8533c06.tar.bz2
Merged doc update from 3.2.
Diffstat (limited to 'Doc/howto')
-rw-r--r--Doc/howto/logging-cookbook.rst11
1 files changed, 9 insertions, 2 deletions
diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst
index b812f7b..36a550e 100644
--- a/Doc/howto/logging-cookbook.rst
+++ b/Doc/howto/logging-cookbook.rst
@@ -1622,7 +1622,7 @@ Implementing structured logging
Although most logging messages are intended for reading by humans, and thus not
readily machine-parseable, there might be cirumstances where you want to output
messages in a structured format which *is* capable of being parsed by a program
-(without needed complex regular expressions to parse the log message). This is
+(without needing complex regular expressions to parse the log message). This is
straightforward to achieve using the logging package. There are a number of
ways in which this could be achieved, but the following is a simple approach
which uses JSON to serialise the event in a machine-parseable manner::
@@ -1647,6 +1647,9 @@ If the above script is run, it prints::
message 1 >>> {"fnum": 123.456, "num": 123, "bar": "baz", "foo": "bar"}
+Note that the order of items might be different according to the version of
+Python used.
+
If you need more specialised processing, you can use a custom JSON encoder,
as in the following complete example::
@@ -1655,6 +1658,7 @@ as in the following complete example::
import json
import logging
+ # This next bit is to ensure the script runs unchanged on 2.x and 3.x
try:
unicode
except NameError:
@@ -1677,7 +1681,7 @@ as in the following complete example::
s = Encoder().encode(self.kwargs)
return '%s >>> %s' % (self.message, s)
- _ = StructuredMessage
+ _ = StructuredMessage # optional, to improve readability
def main():
logging.basicConfig(level=logging.INFO, format='%(message)s')
@@ -1690,3 +1694,6 @@ When the above script is run, it prints::
message 1 >>> {"snowman": "\u2603", "set_value": [1, 2, 3]}
+Note that the order of items might be different according to the version of
+Python used.
+