global $conf;
/* Default handler. */
- $handler = new Horde_Log_Handler_Null();
-
- // Try to make sure that we can log messages somehow.
- if (!empty($conf['log']['enabled'])) {
- switch ($conf['log']['type']) {
- case 'file':
- try {
- $handler = new Horde_Log_Handler_Stream($conf['log']['name'], $conf['log']['params']['append'] ? 'a+' : 'w+');
- } catch (Horde_Log_Exception $e) {}
+ if (empty($conf['log']['enabled'])) {
+ return new Horde_Log_Logger(new Horde_Log_Handler_Null());
+ }
+
+ switch ($conf['log']['type']) {
+ case 'file':
+ case 'stream':
+ $append = ($conf['log']['type'] == 'file')
+ ? ($conf['log']['params']['append'] ? 'a+' : 'w+')
+ : null;
+
+ switch ($conf['log']['params']['format']) {
+ case 'custom':
+ $formatter = new Horde_Log_Formatter_Xml(array('format' => $conf['log']['params']['template']));
break;
- case 'stream':
- try {
- $handler = new Horde_Log_Handler_Stream($conf['log']['name']);
- } catch (Horde_Log_Exception $e) {}
+ case 'default':
+ // Use Horde_Log defaults.
+ $formatter = null;
break;
- case 'syslog':
- try {
- $handler = new Horde_Log_Handler_Syslog();
- } catch (Horde_Log_Exception $e) {}
+ case 'xml':
+ $formatter = new Horde_Log_Formatter_Xml();
break;
+ }
- // case 'null':
- // default:
- // // Use default null handler.
- // break;
+ try {
+ $handler = new Horde_Log_Handler_Stream($conf['log']['name'], $append, $formatter);
+ } catch (Horde_Log_Exception $e) {
+ return new Horde_Log_Logger(new Horde_Log_Handler_Null());
}
+ break;
- if (!is_string($conf['log']['priority'])) {
- $conf['log']['priority'] = 'NOTICE';
+ case 'syslog':
+ try {
+ $handler = new Horde_Log_Handler_Syslog();
+ } catch (Horde_Log_Exception $e) {
+ return new Horde_Log_Logger(new Horde_Log_Handler_Null());
}
- $handler->addFilter(constant('Horde_Log::' . $conf['log']['priority']));
+ break;
+
+ case 'null':
+ default:
+ // Use default null handler.
+ return new Horde_Log_Logger(new Horde_Log_Handler_Null());
+ break;
+ }
+
+ if (!is_string($conf['log']['priority'])) {
+ $conf['log']['priority'] = 'NOTICE';
}
+ $handler->addFilter(constant('Horde_Log::' . $conf['log']['priority']));
+ /* Horde_Core_Log_Logger contains code to format the log message. */
return new Horde_Core_Log_Logger($handler);
}
<configboolean name="append" required="false" desc="Should new log
entries be appended to an existing log file? If this is false, new log
files will overwrite existing ones.">true</configboolean>
+ <configswitch name="format" required="false" desc="What format should
+ the log entries be in?">default
+ <case name="custom" desc="Custom Template">
+ <configstring name="template" desc="The custom logging template
+ to use."></configstring>
+ </case>
+ <case name="default" desc="Default" />
+ <case name="xml" desc="XML" />
+ </configswitch>
</configsection>
</case>
<case name="stream" desc="PHP Stream">
<configstring name="name" desc="A valid-PHP stream interface to use
for logging."></configstring>
+ <configsection name="params">
+ <configswitch name="format" required="false" desc="What format should
+ the log entries be in?">default
+ <case name="custom" desc="Custom Template">
+ <configstring name="template" desc="The custom logging template
+ to use."></configstring>
+ </case>
+ <case name="default" desc="Default" />
+ <case name="xml" desc="XML" />
+ </configswitch>
+ </configsection>
</case>
<case name="syslog" desc="Syslog">