I am revamping the logging for a program I maintain and trying to do it the "right way." Wanted to get your thoughts as I'm trying to avoid butchering this, as I have a unique architecture...
I want to write INFO+ to Screen... simple enough. However, as for files, I want to switch between files depending on program flow. The program is basically a wrapper that runs other jobs, like:
Launch program
Run Job 1
Run Job 2
Run Job 3
...
Exit program
The wrapper takes care of things at a "high level" and the jobs do the "low level" dirty work. So my idea was to write wrapper logging to a "main.log" and then each job gets its own log, like "job1.log", "job2.log", etc. The jobs are run in a "for" loop, by the way.
But both main.log and jobX.log will have the same range of severity levels, from DEBUG to ERROR, so I can't use those to distinguish. I have two ideas:
- Use two different loggers, one with the mainLogger category and one with the jobLogger category. Both would have the Screen appender but they'd have different File appenders. Use one logger or the other as needed. Downside is maintaining separate loggers plus now categories != packages
OR
- Use a single logger, but swap the file appenders when I get to different parts of the code, like:
[set appenders: Screen, Main]
...
for my $job (@jobs){
[set appenders: Screen, (current job)]
}
[set appenders: Screen, Main]
Downside is that I don't think appenders were meant to be dynamically swapped in this way, at least not frequently.
Wondering which of these (if either) seems best to you, according to best practices... thank you greatly!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.