Closed (fixed)
Project:
File logger
Version:
6.x-1.0
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
22 Apr 2010 at 14:33 UTC
Updated:
12 Nov 2010 at 19:50 UTC
Hi, Thanks for the nice module.
I want to use your module for logging module activity, not only for dev on 1 module at a time but for several modules. Therefor it would be very nice when you could include someting like this:
flog_file('/var/log/name_of_log_file');
If you put this command in the code, it will output to that file from there on
Example for code in 1 script writing to two log files:
<?php
$a = 'Hello Earth'
flog_file('/var/log/logfile_1.log');
flog_it($a);
flog_file('/var/log/logfile_2.log');
flog_it($a);
?>Hope that this is simple to do and that it could be implemented soon.
Thanks in advance
Jan
Comments
Comment #1
dwightaspinwall commentedThat's a good idea, Jan. Let me see if I can get it in.
Comment #2
rjbrown99 commented+1
I'd like to also split up the logging between different files, preferably in a more dynamic way then originally suggested. Perhaps something along the lines of:
... where foo.log is an optional argument to whatever that log file should be. I intentionally do not log to the Drupal database for performance and this would be a nice alternative logger I can use for per-module debug statistics. I use flog_it constantly btw - for me it's easier than dsm() in most cases and can handle giant dumps of forms.
Comment #3
dwightaspinwall commentedThanks for the feedback guys. I'll see if I can get this in. Of course, patches are welcome. ;-)
Comment #4
tunicI think this can be achieved using channels. You define channels, and when you call log function you can specify a channel. This way any message is attached to a channel and you can group several channels in a single file, or use one file per channel or even disable a channel so every message from that channel is ignored (very usefull if you are debugging something related to other channel). Usually you use same channel for logs of same functionality or module.
I've developped a module of internal use similar to flog that uses those channels. I think I could patch flog to use them, but I'll need some time.
Also, there's a problem when system goes to production. What to do with those log calls? Remove them from code? It can be tedious to search all the code and remove them, specially in large proejcts, and some logs may be usefull in the future even in a prodcution site. What I've done is to include a third parameter with the severity of the message (the watchdog severity levels). So, in production low levels are ignored, but higher levels are redirected to dblog, if active. This way you can have all importante messages in file while developping, and have important messages looged to database while in production. Of course they can rerouted in any other way (even mail them, like an alert service).
Well, there are some rough edges that I've to solve, but I guess it can be useful.
I'll try to comment more when I finnish my actual project and have more time ;-)
Comment #5
dwightaspinwall commentedtunic, the channel approach seems promising as long as it isn't overly complicated. Part of the goal here was to keep things simple.
As for what happens in production. Obviously, if logging is turned off nothing happens; i.e. your flog_it() calls have no effect. That's configurable in the settings. If logging is turned on and you've configured an accessible file, it will get the writes. If there's something wrong with the configuration (e.g. no path or filename has been set) you'll get messages (maybe these should be watchdog calls instead...)
In my situation, I always turn off flog in production (although the module is still enabled). I also clear out flog_it() calls from my code before a release. Of course, I rest a little easier knowing they'll have no effect if I forget.
Comment #6
dwightaspinwall commentedAdded multi-file logging in 6.x-1.1. Thanks for the suggestions.
Implemented using optional third argument to flog_it():
The file is assumed to be in the directory you've configured.