Join 34,000+ subscribers and receive articles from our
blog about software quality, testing, QA and security.

Logging messages of different purpose to different files


#1

Is it possible to have two or more log files for different purposes? For instance, I want to log regular notifications and messages to one file and errors to another file? I saw how to create multiple connections but I think that sends every message to all connections?


#2

Hi Rick!

Yes, that’s possible and you can use the following configuration for this:

file(filename=..), file(filename=.., level=error)

This will create two file-based connections: the first one will receive all log messages and the second one will only add log messages of level error or higher to the log file. Is this what you are looking for?

Regards,
Tobias


#3

I will look into this and see if it would work, but not exactly what I was thinking. I typically used 4 logs - (1) the main log having everything that will go into production, (2) a test or debug log I used for output specifically related to designing/programming. This was to make my life easier rather than having to dig through the main log for specific output, (3) an error log that logged errors, that was also emailed, (4) a statistics log that would output certain statistics to a CSV for external analysis (this relates to my other question).

If I want to use SmartInspect maybe I would need to rethink how i use logs.


#4

Hi Rick,

Thanks for your reply. An alternative would be to use different SmartInspect and Session objects. You can then easily use different sessions/files depending on the log context (e.g. debug/production/errors, etc) and this would be more flexible than the log level filter per connection. Using the log level filter (and same SmartInspect instance) is usually sufficient though and should also cover your scenario.

Regards,
Tobias