Update: You can find KLogger on github.
Project Update: See the end of this post for details about KLogger’s current status
KLogger is a simple-to-use PHP text file logging class. It was made to have basic logging functionality, be lightweight, and be safe to use (permissions-wise). The reason for its creation is two-fold: I needed a simple logging class with priority hierarchies ( Debug, Info, Warn, etc .. ), and I couldn’t find it on the internet.
For small web applications or development sites, the use of logging libraries isn’t necessary. All you need is something like KLogger, a simple logging class.
KLogger supports:
- Safe logging (no PHP errors due to permissions)
- Smart file management (closing up resources)
- Priority heirarchies (OFF, DEBUG, INFO, WARN, ERROR, and FATAL)
Basic usage would look like this:
require_once 'KLogger.php'; ... $log = new KLogger ( "log.txt" , KLogger::DEBUG ); // Do database work that throws an exception $log->LogError("An exception was thrown in ThisFunction()"); // Print out some information $log->LogInfo("Internal Query Time: $time_ms milliseconds"); // Print out the value of some variables $log->LogDebug("User Count: $User_Count");
Using KLogger will eventually generate a log file that looks something like this one, which is the actual output from wpSearch, the Lucene based search plugin for wordpress. Tracking down a couple outstanding bugs became much easier once I started using KLogger.
If you happen to be wondering what that log reader is, it’s KTail, a yet-to-be-released log “tailer” written in C#. It is multithreaded, tabbed, and super-useful for reading log files which get updated frequently. It displays changes to almost instantly. (It has yet to be tested on a gigantic log file, though). It’s a side project that doesn’t get a whole lot of attention.
If you think KLogger is what you need, download it (below), and let me know your thoughts by sending an email to katzgrau@gmail.com or leaving a comment on CodeFury.
Update: The KLogger project has moved to GitHub as of June 22, 2010. The original file download will remain intact below. The GitHub equivalent (a tagged release of version 0.1) is available at github too.
http://codefury.net/wp-content/uploads/2008/07/klogger-1.0.0b.zip
To check out the GitHub project, go to:


7 Comments
I’m planning to use KLogger (http://codefury.net/projects/klogger/) for logging financial data and I’m wondering if it can handle race conditions properly.
There would be instances where multiple users would be accessing the site simultaneously and I’m wondering if the logger will mess up in those situations.
really thank you very much it’s exactly what i need,
Amazing stuff, wish I’d found this at the beginning! Finally can stop wasting time writing logging functionality that never works like I need.
Great post! I am extremely surprised at how many people don’t even use monitoring, tracing/debug and or log or timing tools for their applications that are out-grown and they don’t know why their sites are no longer working/ (scaling or able (scalable)). It almost makes me laugh, so thank you for the wonderful and sensible post …………….
.
XDEBUG is great too as well as ettercap.
What is the license for this? I would like to use it in a project at work, but didn’t see a license listed anywhere. Public domain? BSD?
I am using the good ol’ KLogger v0.1 (with some additions/changes I made), and I’m really happy to see that work is going on.
One suggestion: I’d like to have different output files for different levels (.err for fatal, warn, …, .log for complete debug tracing, for example). Maybe this can be achieved by creating different object instances (didn’t take a deeper look into the new class yet), but I think this would be a nice feature. What do you think?
Thanks for the code my friend. Your going to make my project a whole lot better.
4 Trackbacks
[...] I decided to write of the class myself, and it has turned out to be pretty handy. I figured someone else would probably find it useful as well, so I have posted it on it’s own project page. Click here to go to the KLogger project page. [...]
[...] also introducing some logging, using the excellent KLogger class to write a log file every time we save a [...]
[...] Klogger – the lightest option [...]
[...] KLogger http://codefury.net/projects/klogger/ Utile e semplice da implementare, mette a disposizione del programmatore le funzioni base per [...]