Skip to content

Write your custom handler and formatter

FabianM edited this page · 1 revision

Writing the handler.

A Handler should contain one method; publish. This method will be called when someone uses a log method. publish takes one argument, a LogRecord. This is a simple example of a handler.

this.myHandler = function() {
     this.publish = function(logrecord) {
         // Publish a log here.
     };
};

Writing the formatter.

A Formatter uses almost the exact same structure as a handler, but publish is renamed to format. This is a simple example of a formatter.

this.myFormatter = function() {
     this.formatter = function(logrecord) {
         // Format a log here.

         // Return the formatted log string.
         return "myFormatter";
     };
};

Let your handler use your formatter.

Simple...

this.myHandler = function() {
     this.formatter = new formatter.MyFormatter();
     this.publish = function(logrecord) {
         // Publish a log here.
         return this.formatter.format();
     };
};
Something went wrong with that request. Please try again.