Home  /  Questions  /  Question



50   50
Jun 28, 2011


RE: Log project

How do I set up different logging severity levels for different log types?  For instance, I can set the log severity to Info, but that covers all log types, do I just need to add a log severity for each type of log?  That way I can set the logseverity for email and the log severity for file and the log severity for console.  And yes they need to be different, since when the log event happens if it is an error it should not only log into the log file but also send an email, but if it is info then it should only write to the log file and not send an email. 

Or is there something I am missing?



90   96.5
Aug 15, 2011

Hi
[The question needs to be more clear, but somehow am able to get what you are looking for.]

My assumption:

When you get an error, you would pass your error object to an logging class, which will decide at runtime-
if it is an error (?) or just an info (?) and log that into appropriate source (like file, DB etc)

If yes, I would recommend to go for a Chain Of Responsibility pattern.

Steps I could think of :"

1) Build the chain of Loggers (File, email, DB etc.,)

2) Pass the error (or Info) obejct to First in the chain , say File Logger, this Class will decide if it need to log, if yes, will log and then send your "Error object" to next in the chain - say "Email Logger (sender)"

3) Email Logger Class will check if it eligible to be sent , if yes will send email and will pass it to next in the chain, say DB.

4) DB Logger will check and lets us assume its not a eligible one and will end the chain signallig the completion.

Please refer to my blog where I have talked more about this pattern (of course with  a Builder Pattern variation)

http://techietarriq.blogspot.com/2011_02_01_archive.html

Hope this helps.

Thanks,

Tarriq Ferrose Khan