Lars Yencken committed 8e33617

Adds some basic instructions for using hierarchical logs.

Comments (0)

Files changed (1)

-== Welcome ==
+== Console Logger  ==
-Welcome to your wiki! This is the default page we've installed for your convenience. Go ahead and edit it.
-=== Wiki features ===
-This wiki uses the [[|Creole]] syntax, and is fully compatible with the 1.0 specification.
-The wiki itself is actually a hg repository, which means you can clone it, edit it locally/offline, add images or any other file type, and push it back to us. It will be live immediately.
-Go ahead and try:
+The console logger provides a nice interface for hierarchical output. Here's a trivial example to get us started.
-$ hg clone
+>>> import consoleLog
+>>> def some_function(n):
+...     log = consoleLog.default
+...     log.start('Counting to %d' % n, nSteps=n)
+...     for i in xrange(n):
+...         log.log('Item %d' % i)
+...     log.finish()
+>>> some_function(5)
+Counting to 5
+├─ Item 0
+├─ Item 1
+├─ Item 2
+├─ Item 3
+└─ Item 4
-Wiki pages are normal files, with the .wiki extension. You can edit them locally, as well as creating new ones.
-=== Syntax highlighting ===
-You can also highlight snippets of text, we use the excellent [[|Pygments]] library.
-Here's an example of some Python code:
+This results in quite readable output. The real power is when logging calls are nested. The output then displays the full nesting hierarchy. You could do it like this:
-def wiki_rocks(text):
-	formatter = lambda t: "funky"+t
-	return formatter(text)
+from consoleLog import default as log 
+def make_breakfast():
+    log.start('Making breakfast')
+    fridge = open_fridge()
+    milk = get_milk(fridge)
+    museli = get_museli()
+    food = milk.pour(museli)
+    log.finish()
+    return food
-You can check out the source of this page to see how that's done, and make sure to bookmark [[|the vast library of Pygment lexers]], we accept the 'short name' or the 'mimetype' of anything in there.
+In this example, we don't know how many steps are involved in making breakfast. We just tell the logger when it starts and when it's finished. If any of the functions we call, such as open_fridge() logs any actions, then they will appear nested under "Making breakfast". If any of them use log.start or log.finish methods, these sub-lists will also be nested appropriately.
-Have fun!
+Try it out!