katzgrau / KLogger

A Simple Logging Class For PHP
http://codefury.net/projects/klogger/
981 stars 284 forks source link

Klogger creates empty file even if not used to log() anything #89

Open johnykvsky opened 6 years ago

johnykvsky commented 6 years ago

After playting with Slim (middleware and stuff) I noticed that when logger is created and even not used, a log file is created with zero size. Construct run setFileHandle() witch do fopen(...,'a') and this creates empty file, even if I don't log() anything (on PHP7 to be precise).

First I thought of moving setFileHandle() outside constructor or playing with different than 'a' file open modes, but then - why not use file_put_contents. It won't create file until it try to write to it, performance is (according to google) the same.

Do you see any drawbacks of it? Change was quite easy, code got cleaner. If you want, I can make a PR.