[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Custom log file [dependency injection]
From: |
Jan-Henrik Haukeland |
Subject: |
Re: Custom log file [dependency injection] |
Date: |
Fri, 3 Jun 2005 02:23:17 +0200 |
Sorry for this spamming but my example was not very good. I wanted to
show how you could provide one log class implementation for different
contexts but managed to mix up the example with event handling :)
Event handling should be on a higher abstraction level.
On 3. jun. 2005, at 00.16, Jan-Henrik Haukeland wrote:
/* Initialization, setting up log delegators */
List_T loggers= List_new();
Logger_T errorLogger= Logger_new("/var/log/monit/error.log");
Logger_T customLogger= Logger_new("/var/log/blabla.log");
Logger_setLogFormat(customLogger, "%D, %T, %A, %S, %M, %T");
At least this shows a general log "class", which could be used to log
both errors and custom stuff.
/* Log an error to the error log */
Logger_log(errorLogger, "error message");
..
/* Log custom stuff to the custom stuff log */
Logger_log(customLogger, "<message>");
However the next bit is crap.
loggers_add(errorLogger);
loggers_add(customLogger);
....
/* Perform logging upon event handling */
for(int i= 0; i < loggers_length(loggers); i++)
Logger_log(loggers_get(i), Event_T e);
This is sort of a back of an envelope design; the main idea is that
handling of output from events should work as a general "dependency
injection"[1] pattern. Event handling could be conducted by providing
a function pointer similar to how protocol handling is implemented.
I.e. something like this,
/* Definition of a general output handler */
typedef struct myoutputhandler {
const char *name; /**<
Handler name */
const char *target; /* E.g. hostname for snmp or smtp, path for
log file */
int(*performOutput)(Event_T); /**< Output handler
function */
} *OutHandler_T;
Users would then configure in monitrc those alert or notification
handlers he wanted. Here, each create_function returns an
OutHandler_T object with a particular way to handle output for that
channel.
List_T outHandlers= List_new();
List_add(create_snmpHandler("trap"));
List_add(create_mailHandler("mail.foo.bar"));
List_add(create_logHandler("/var/log/custom.log", "<logformat>"));
In the event handling machinery output to various output channels
could simply be performed like so,
/* Perform output for event */
for(int i= 0; i < List_length(outHandlers); i++) {
OutHandler_T out= List_get(i);
out->performOutput(out, event);
}
Of course this is a major rewrite of the alert and event stuff and
something that would take time to implement.
I at least hope for this kind of direction for monit.
[1] Dependency injection is a term, much used in the Java community
and especially in the Spring framework. The idea is based on that
objects and delegators are configured and not hardcoded. Many Java
application servers use this concept, where you can assemble
different components which should be used in a particular instance of
the server. This assembling is done in a configuration file and not
hardcoded in the server. See for instance http://www.caucho.com/
resin-3.0/resource/tutorial/injection/index.xtp
--
Jan-Henrik Haukeland
Mobil +47 97141255