owncloud/core — pull request #2664 by mmattel (2013-04-02 19:56:23+00:00)
Title: Expand Logwriter for additional logfiles used, managed as parameter from the caller

This is a extension of merger # 2620 (Log DB Queries) from eMerzh.

The basic idea behind is, that someone wants to write additional log information, but not into the main log. Thanks to @tanghus who encouraged me writing this code. I apologise in advance if I made something wrong.

What has been changed:

1.) you can create in config.php additional parameters, as best in pairs, so that coding could hook on. The first parameter is used to check if a special log needs to be written (true/false), the second parameter is used to define the log file name. Therefore I have renamed the original first parameter name defined by eMerzh from log_query to log_sql_query to be specific. The second parameter is new and called in this case log_sql_file. You can see the description in config\config.sample.php. Creating new parameter sets is logical and easy and I could think about log_music_query and log_music_file, but this is just an idea...

2.) I enhanced the calls from eMerzh in lib\db.php with a parameter, eg:
OC_Log::write('core', 'DB prepare : '.$query, OC_Log::DEBUG, OC_Config::getValue("log_sql_file"));
where the last parameter is optional and is in case it is used the log filename the logger writes to.
On the example given you can see, that it is not breaking existing calls, but you can now make calls where you can decide if the log entry is written to a separate logfile not filling up the main oC log.

3.) of course lib\log.php needed a upgrade to manage existing calls and a new call style with the additional logfile name as parameter.

4.) most critical was lib\log\owncloud.php because we need to manage different cases. What I have done there is, that I separated the log path from the log filename. This because, we always write to the log path but maybe to a different log file. Of course we have to manage various szenarios where paths are valid and writable. If not, I write a warning message to the default log path/name. BTW I have seen, that in the original code the config parameter "logfile" was at least not clear to me (but I may be wrong with my view), because I interpreted it as path+file because of the code (if (!file_exists(self::$logFile)) which needs a path to have a proper result. I have here set following definition on config.logfile. If a path is present, use it as alternative logging path, if only a filename is set use the default path and the filename given.

There is one restriction, we do not write into syslog, owncloud log only.

We can now use standard logging and enhanced (special) logging. The call format for special logging is:
standard:	OC_Log::write($app, $message, $level);
special:	OC_Log::write($app, $message, $level, OC_Config::getValue("config-parameter"));
where config-parameter is the config name used for the definition

I have tested this in all combinations and it works well, but I please you to do additional checking and review.

Best Regards
Martin

BTW: the idea some weeks ago posted to have split config files is getting more and more attractive...