Sebastian Potasiak
Sebastian Potasiak

Reputation: 135

Log lines formatting

I have a problem with implementation of logging system based on PSR-3 standards (and interfaces/classes delivered with it - https://github.com/php-fig/log).

I have created some classes extending PSR-3: logger, which uses adapters to do actual logging (logger class stores adapter instance and calls log() method in it) and I came to file adapter (adapter that writes log messages into file(s)) and I'm looking for some way to implement custom log line formats. I mean that I could log messages as

[01/01/2013 12:00:00] NOTICE: Log message content\n

as well as

user: Log message content (NOTICE) ~ 01-01-2013

(complete custom order and contents)

Also, I would like to create separate class for that.

Is there any way to do it in very get-at-able way, so others (even low-skilled phpers) won't have problem with changing this?

Upvotes: 0

Views: 696

Answers (1)

mark.sagikazar
mark.sagikazar

Reputation: 1042

Maybe it is mainstream, but have you looked at Monolog

You could implement HandlerInterface instead of LoggerInterface. Formatting would be solved by Monolog using your pattern.

This solution is also better as you can use ONE Logger and many Handlers in Monolog.

There is one downside/upside (you decide): you have to implement your level logging in the handler, which might be a bit ugly.

Upvotes: 0

Related Questions