10

Is there any good log library for message, warning and errors flogging for PHP?AFAIK error_log is only used for logging errors but i need to store also debug messages.

And should work with CLI. Thanks

j0k
  • 22,600
  • 28
  • 79
  • 90
gremo
  • 47,186
  • 75
  • 257
  • 421

3 Answers3

14

I suggest you to have a look at Monolog

spider
  • 1,164
  • 9
  • 16
5

error_log() can write to arbitrary files...

error_log('Something blew up!', 3, '/some/path/debug.txt');
Marc B
  • 356,200
  • 43
  • 426
  • 500
  • Only problem with that is you need to either do a wrapper function so you don't have a bunch of references to the same file, or refer to the file all over the place. I think the OP is looking for something that simplifies that process. – Jared Farrish Nov 25 '11 at 20:29
  • @JaredFarrish: Actually, you can set the log destination with ini_set('error_log', 'syslog'). Instead of "syslog", you can specify a file path. You only need to do this once. The actual downside to using "error_log" is that you need some sort of wrapper in order to suppress logging. For instance, you might want debug logs to be written while in your dev environment, but suppress these logs in production. error_log doesn't do that for you, you'd need to roll that in yourself. – Wil Moore III Dec 20 '11 at 21:02
5

Personally I appreciate the flexibility of log4php

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • 1
    I like it, but cant live in its own folder? Does it require PEAR package? – gremo Nov 25 '11 at 18:29
  • Use composer. That way, your project and the composer.json with the log4php dependency can live together. – asiby May 31 '19 at 18:13