[Ann] Simple logging framework

Russell Allen mail at russell-allen.com
Thu Oct 23 06:33:41 UTC 2014


Hi all,

I needed a simple logging framework for the webserver - there is a bunch of partial ‘warning:’ ‘error:’ etc methods spread about the image but mostly they just print raw strings to stdout. I’ve written a very simple one which allows for pluggable handlers. It’s currently in the ‘logging’ branch on github.com/russellallen/self <http://github.com/russellallen/self>

Below is the, um, somewhat minimal documentation.

If you want to look at it, checkout the logging branch, then build a new snapshot. Then have a look at the ‘log’ slot of globals.

Any feedback would be great. If people think this is a good idea I’d like to merge it (or something like it) into the main branch for the next release.  

Cheers, Russell

Logging
=======

``log`` is a useful system-wide logging mechanism. You can find it in the ``system`` category of ``globals``.

How to log 
----------

There are a number of useful messages in the ``logging`` category of ``log`` which allow you to simply and cleanly log messages. For example::

  log warn: 'This is a warning.'
  
You can log with one of five levels found at ``log levels``. These are, in order of severity, ``debug``, ``info``, ``warn``, ``error``, ``fatal``.

You can also tag log entries, for example::

  log fatal: 'The server has caught fire' For: 'webserver'
  
By default, entries of either error or fatal severity which aren't tagged are logged to stderr in the form::

  [Thu Oct 23 16:25:07 2014] error -- Something went wrong!
  
How logging works
-----------------

The helper methods shown above constuct a ``log entry`` and hand it to the ``log dispatcher``. The dispatcher has a number of handlers, each is given a chance to handle the log entry. The handlers can choose which entries to act on. Example handlers are in ``log prototypeHandlers``.

When making a handler, please keep in mind that the log entry's ``message`` is expected to be something which understands ``value``, returning an object (or itself) which understands ``asString``. If you do not need to resolve the message by sending it ``value`` please don't; that way logs can be sent blocks which are only resolved if necessary; eg::

  log debug: ['We have reached: ', somethingComplicatedToCalculate]
  
will not slow down your code if no log handler is interested in handling debuggers.

If your handler breaks the logging process you can restart it by::

  log dispatcher hup

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.selflanguage.org/pipermail/self-interest/attachments/20141023/0fb8b543/attachment.html>


More information about the Self-interest mailing list