[Mapbender-dev] State of Logging, Exceptions

Karim Malhas karim at malhas.de
Mon Feb 8 12:54:03 EST 2010

Dear All,

I recently looked into what Mapbender offers as it's logging options,
and I found this :
 //if you are familiar with the logging code, skip down to "While this works";


 classes in lib/exception.js:
  Mapbender.Exception, Mapbender.Warning, Mapbender.Notice
  all derived from the class Mb_log

    new Mapbender.Exception("exeption message goes here");

  The different classes differ internally in that they call
  Mb_log.throwException(message,level) with different levels
  this function in return checks if the loglevel is defined somewhere
  globally, and then depending on the value of another global variable,
  either posts the stuff to the server, issues a console.log, or simply

  If the logmessage reaches the serverside, they are translated into
  an approximate serverside log-equivalent (php/mb_js_exception.php)

    mb_exception, mb_warning, mb_notice 
    all derived from mb_log (which is an abstract class)

    $e = new mb_exception("exception message goes here");
    $e = new mb_warning("warning message goes here");

  The same way as the javascript logging classes, the difference between
  these different classes, ist just that they internally set a different
  string and pass it to the mb_log method they inherted from mb_log (the
  The messages end up in the "log/" directory of the Mapbender

While this works, to me this is not an ideal situation.

- The code mixes the concepts of Logging and Exceptions:
  When I think of Exceptions, I think of objects that can be thrown and
  caught, and when neccesary, logged to the DEBUG (or some other) level.
  But not every Exceptions needs to generate a log entry, rather, it
  should be dealt with, bubbled up, and only if all else fails should
  the user (via some kind of notification) or the developer (via the
  log) be informed of a problem.

- All logs go to a file, or configurable from core/system.php to FireBug
  There's no flexible way to change the location of the logfile (one has
  to change php/classes_mb_log.php).
  There's also no way to log to syslog, for example

So I propose we change it :-) maybe not right now, but we could keep it
in mind.

I am thinking something along the lines of the following: 


  var log = new Logger("mapbender_installation_5);

  var alertHandler = new AlertHandler();

  var serverHandler = new ServerHandler("log.php");

  log.notice("mapbender is starting up");
  log.debug("loaded 24 elements");
    if (E instanceOf TypeError){
      // tell user to enter better data

    // all else failed
    log.debug("caught Exception in the_method(): "+ E);
    // tell user that evreything went horribly wrong and they should
    // try turning it off and on again

(and something similar for serverside php)

So there are two components to generating the log message:

- a Logger class that takes care about which loglevels to provide, and
  which loglevels to log

- a logHandler class that actually formats and writes a logmessage.
  On the client side, the message could go into an alert, the console,
  written onto the page itself, displayed in a jquery dialog, set to the
  server, etc
  On the Server side the message could go into the normal mapbender log,
  to syslog, Firebug, the Windows eventlog, and wherever else you could want it.

  I am especially after being able taking advantage of syslog.

I actually have a (mostly complete) implementation of the above, and I
was wondering if anyone else is interested in having this integrated.

Maybe it's not the right time, with a release coming up, but it has
bothered me a bit for a while.


More information about the Mapbender_dev mailing list