Ticket #1484850: syslog.diff

File syslog.diff, 5.6 kB (added by rjhughes, 10 months ago)

Patch against 1186 to allow the use of syslog, but continue to use file-based logging if you don't specify.

  • installer/config.php

     
    9999<div>Use this folder to store temp files (must be writebale for webserver)</div> 
    100100</dd> 
    101101 
     102<dt class="propname">log_driver</dt> 
     103<dd> 
     104<?php 
     105 
     106$select_log_driver = new select(array('name' => '_log_driver', 'id' => "cfglogdriver")); 
     107$select_log_driver->add(array('file', 'syslog'), array('file', 'syslog')); 
     108echo $select_log_driver->show($RCI->getprop('log_driver')); 
     109 
     110?> 
     111<div>How to do logging?  'file':  Write to files in the log directory.  'syslog': Use the syslog facility.</div> 
     112</dd> 
     113 
    102114<dt class="propname">log_dir</dt> 
    103115<dd> 
    104116<?php 
     
    107119echo $input_logdir->show($RCI->getprop('log_dir')); 
    108120 
    109121?> 
    110 <div>Use this folder to store log files (must be writebale for webserver)</div> 
     122<div>Use this folder to store log files (must be writebale for webserver).  Note that this only applies if you are using the 'file' log_driver.</div> 
    111123</dd> 
    112124 
     125<dt class="propname">syslog_id</dt> 
     126<dd> 
     127<?php 
     128 
     129$input_syslogid = new textfield(array('name' => '_syslog_id', 'size' => 30, 'id' => "cfgsyslogid")); 
     130echo $input_syslogid->show($RCI->getprop('syslog_id')); 
     131 
     132?> 
     133<div>What ID to use when logging with syslog.  Note that this only applies if you are using the 'syslog' log_driver.</div> 
     134</dd> 
     135 
    113136<dt class="propname">ip_check</dt> 
    114137<dd> 
    115138<?php 
  • config/main.inc.php.dist

     
    1818// system error reporting: 1 = log; 2 = report (not implemented yet), 4 = show, 8 = trace 
    1919$rcmail_config['debug_level'] = 1; 
    2020 
     21// log driver:  'syslog' or 'file'. 
     22$rcmail_config['log_driver'] = 'file'; 
     23 
     24// use this folder to store log files (must be writebale for apache user) 
     25// This is used by the 'file' log driver. 
     26$rcmail_config['log_dir'] = 'logs/'; 
     27 
     28// Syslog id to use, if using the 'syslog' log driver. 
     29$rcmail_config['syslog_id'] = 'roundcube'; 
     30 
    2131// enable caching of messages and mailbox data in the local database. 
    2232// this is recommended if the IMAP server does not run on the same machine 
    2333$rcmail_config['enable_caching'] = TRUE; 
     
    99109// use this folder to store temp files (must be writebale for apache user) 
    100110$rcmail_config['temp_dir'] = 'temp/'; 
    101111 
    102 // use this folder to store log files (must be writebale for apache user) 
    103 $rcmail_config['log_dir'] = 'logs/'; 
    104  
    105112// session lifetime in minutes 
    106113$rcmail_config['session_lifetime'] = 10; 
    107114 
  • program/include/bugs.inc

     
    8484      $CONFIG['log_dir'] = $INSTALL_PATH.'logs'; 
    8585       
    8686    // try to open specific log file for writing 
    87     if ($fp = @fopen($CONFIG['log_dir'].'/errors', 'a')) 
     87    if ($CONFIG['log_driver'] == 'syslog') 
    8888    { 
     89      syslog(LOG_ERR, $log_entry); 
     90    } 
     91    else if ($fp = @fopen($CONFIG['log_dir'].'/errors', 'a')) 
     92    { 
     93      // log_driver == 'file' is the default, assumed here. 
    8994      fwrite($fp, $log_entry); 
    9095      fclose($fp); 
    9196    } 
  • program/include/main.inc

     
    151151  else 
    152152    $conf['log_dir'] = unslashify($conf['log_dir']); 
    153153 
     154  if ($conf['log_driver'] == 'syslog') 
     155    openlog($conf['syslog_id'], 0, LOG_USER); 
     156 
    154157  // set PHP error logging according to config 
    155   if ($conf['debug_level'] & 1) 
    156     { 
     158  if ($conf['debug_level'] & 1) { 
    157159    ini_set('log_errors', 1); 
    158     ini_set('error_log', $conf['log_dir'].'/errors'); 
    159     } 
     160    if ($conf['log_driver'] == 'syslog') { 
     161      ini_set('error_log', 'syslog'); 
     162    } else { // log_driver == 'file' is assumed here. 
     163      ini_set('error_log', $conf['log_dir'].'/errors'); 
     164        } 
     165  } 
    160166  if ($conf['debug_level'] & 4) 
    161167    ini_set('display_errors', 1); 
    162168  else 
     
    16021608 * @param $name Name of logfile 
    16031609 * @param $line Line to append 
    16041610 */ 
    1605 function write_log($name, $line) 
    1606   { 
     1611function write_log($name, $line) { 
    16071612  global $CONFIG, $INSTALL_PATH; 
    16081613 
    16091614  if (!is_string($line)) 
     
    16161621  if (empty($CONFIG['log_dir'])) 
    16171622    $CONFIG['log_dir'] = $INSTALL_PATH.'logs'; 
    16181623       
    1619   // try to open specific log file for writing 
    1620   if ($fp = @fopen($CONFIG['log_dir'].'/'.$name, 'a'))     
    1621     { 
    1622     fwrite($fp, $log_entry); 
    1623     fclose($fp); 
     1624  if ($CONFIG['log_driver'] == 'syslog') { 
     1625    if ($name == 'errors') 
     1626      $priority = LOG_ERR; 
     1627    else 
     1628      $priority = LOG_INFO; 
     1629 
     1630    syslog($priority, $log_entry); 
     1631  } else { // log_driver == 'file' is assumed here 
     1632    // try to open specific log file for writing 
     1633    if ($fp = @fopen($CONFIG['log_dir'].'/'.$name, 'a')) { 
     1634      fwrite($fp, $log_entry); 
     1635      fclose($fp); 
    16241636    } 
    16251637  } 
     1638} 
    16261639 
    16271640 
    16281641/** 
  • program/steps/mail/sendmail.inc

     
    402402      $mailto, 
    403403      !empty($smtp_response) ? join('; ', $smtp_response) : ''); 
    404404 
    405     if ($fp = @fopen($CONFIG['log_dir'].'/sendmail', 'a')) 
     405    if ($CONFIG['log_driver'] == 'syslog')  
     406      syslog(LOG_INFO, $log_entry); 
     407    else if ($fp = @fopen($CONFIG['log_dir'].'/sendmail', 'a'))  
    406408      { 
     409      // log_driver == 'file' is assumed here. 
    407410      fwrite($fp, $log_entry); 
    408411      fclose($fp); 
    409412      }