http://code.google.com/p/emt/source/detail?r=229
Added:
/trunk/plugins/log
/trunk/plugins/log/syslog.php
/trunk/plugins/log/text.php
Modified:
/trunk/base/config_file.php
/trunk/base/log.php
/trunk/bin/emt_gather
/trunk/etc/emt.cnf
/trunk/scripts/build_rpm.sh
/trunk/test/etc/emt.cnf
=======================================
--- /dev/null
+++ /trunk/plugins/log/syslog.php Mon Feb 6 13:38:39 2012
@@ -0,0 +1,44 @@
+<?php
+/***************************************************************************
+* Copyright (C) 2007 by Eric Bergen *
+* er...@provenscaling.com *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU Lesser General Public License as
published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+* This program is distributed in the hope that it will be useful, *
+* but WITHOUT ANY WARRANTY; without even the implied warranty of *
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+* GNU Lesser General Public License for more
details. *
+* *
+* You should have received a copy of the GNU Lesser General Public
License *
+* along with this program; if not, write to the *
+* Free Software Foundation, Inc., *
+* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+***************************************************************************/
+
+$log_mask = LOG_PID | LOG_PERROR;
+
+openlog("emt", $log_mask, LOG_LOCAL0);
+
+function log_error_and_exit($msg, $return_code = 1)
+{
+ sys_log(LOG_ERR, $msg);
+ exit($return_code);
+}
+
+function log_error($msg)
+{
+ sys_log(LOG_ERR, $msg);
+}
+
+function sys_log($log_lvl, $msg)
+{
+ if (!defined('DEBUG_OUTPUT') && $log_lvl == LOG_DEBUG)
+ return;
+
+ syslog($log_lvl, $msg);
+}
+
=======================================
--- /dev/null
+++ /trunk/plugins/log/text.php Mon Feb 6 13:38:39 2012
@@ -0,0 +1,51 @@
+<?php
+/***************************************************************************
+* Copyright (C) 2007 by Eric Bergen *
+* er...@provenscaling.com *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU Lesser General Public License as
published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+* This program is distributed in the hope that it will be useful, *
+* but WITHOUT ANY WARRANTY; without even the implied warranty of *
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+* GNU Lesser General Public License for more
details. *
+* *
+* You should have received a copy of the GNU Lesser General Public
License *
+* along with this program; if not, write to the *
+* Free Software Foundation, Inc., *
+* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+***************************************************************************/
+
+if (!isset($config['logger_text']['file']))
+{
+ die("The text logger was configured but there is no [logger_text]
section with a file.");
+}
+
+$logger_text_file = $config['logger_text']['file'];
+
+/**
+ * This file gets included in a function in base/config_file.php
+ * so things need to be globaled so they are available in functions
+ * later.
+ */
+global $logger_text_fp;
+$logger_text_fp = fopen($logger_text_file, 'a+')
+ or die("unable to open log file $logger_text_file");
+
+function log_error_and_exit($msg, $return_code = 1)
+{
+ log_error($msg);
+ exit($return_code);
+}
+
+function log_error($msg)
+{
+ global $logger_text_fp;
+
+ fwrite($logger_text_fp, date('Y-m-d H:i:s ') . $msg . "\n");
+}
+
+
=======================================
--- /trunk/base/config_file.php Thu Jan 12 15:31:08 2012
+++ /trunk/base/config_file.php Mon Feb 6 13:38:39 2012
@@ -19,11 +19,8 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
***************************************************************************/
-
-require_once(INSTALL_PATH . 'base/log.php');
-
-if (isset($_ENV['EMT_CNF']))
- $file_name = $_ENV['EMT_CNF'];
+if (getenv('EMT_CNF'))
+ $file_name = getenv('EMT_CNF');
else
$file_name = DEFAULT_CONF_FILE;
@@ -49,6 +46,7 @@
{
global $config;
global $module_instances;
+ $error = "";
$fp = open_config_file($fname);
@@ -68,7 +66,10 @@
$cur_heading = $matches[1];
if (isset($config[$cur_heading]) &&
$cur_heading != 'emt_gather')
- log_error_and_exit("Duplicate heading $cur_heading");
+ {
+ $error = "Duplicate heading $cur_heading in config file.";
+ break;
+ }
//The heading supports multiple instances. Colon denotes a
instance identifier
@@ -77,7 +78,10 @@
list($module_name, $instance_name) = preg_split('/:/',
$cur_heading);
if (isset($module_instances[$module_name]) &&
in_array($instance_name, $module_instances[$module_name]))
- log_error_and_exit("Duplicate heading $cur_heading.
Instance $instance_name of module $module_name already exists");
+ {
+ $error = "Duplicate heading $cur_heading. Instance
$instance_name of module $module_name already exists";
+ break;
+ }
$module_instances[$module_name][] = $instance_name;
}
@@ -98,7 +102,10 @@
$matches = preg_split('/=/', $line);
if (count($matches) > 2)
- log_error_and_exit("Invalid configuration value ($line)
under heading ($cur_heading)");
+ {
+ $error = "Invalid configuration value ($line) under
heading ($cur_heading)";
+ break;
+ }
$key = trim($matches[0]);
$value = trim($matches[1]);
@@ -114,6 +121,17 @@
$config[$cur_heading][$key] = $value;
}
}
+
+ if ($error)
+ {
+ /**
+ * log.php will instantiate the correct logger
+ * if it made it far enough in parsing the config file.
+ * otherwise it will log using the default logger
+ */
+ require_once(INSTALL_PATH . 'base/log.php');
+ log_error_and_exit($error);
+ }
}
function open_config_file($file = '/etc/emt.cnf')
@@ -128,3 +146,4 @@
if (isset($config['global']['extra_config_dir']))
parse_dir($config['global']['extra_config_dir']);
+
=======================================
--- /trunk/base/log.php Thu Jan 12 15:31:08 2012
+++ /trunk/base/log.php Mon Feb 6 13:38:39 2012
@@ -18,27 +18,12 @@
* Free Software Foundation, Inc.,
*
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
***************************************************************************/
-
-$log_mask = LOG_PID | LOG_PERROR;
-
-openlog("emt", $log_mask, LOG_LOCAL0);
-
-function log_error_and_exit($msg, $return_code = 1)
-{
- sys_log(LOG_ERR, $msg);
- exit($return_code);
-}
-
-function log_error($msg)
-{
- sys_log(LOG_ERR, $msg);
-}
-
-function sys_log($log_lvl, $msg)
-{
- if (!defined('DEBUG_OUTPUT') && $log_lvl == LOG_DEBUG)
- return;
-
- syslog($log_lvl, $msg);
-}
-
+if (isset($config['global']['logger']))
+{
+
require_once(INSTALL_PATH . "plugins/log/{$config['global']['logger']}.php");
+}
+else
+{
+ require_once(INSTALL_PATH . "plugins/log/syslog.php");
+}
+
=======================================
--- /trunk/bin/emt_gather Thu Jan 12 15:37:38 2012
+++ /trunk/bin/emt_gather Mon Feb 6 13:38:39 2012
@@ -36,6 +36,7 @@
declare(ticks = 1);
require_once(dirname(__FILE__) . '/../base/config.php');
+require_once(INSTALL_PATH . 'base/log.php');
require_once(INSTALL_PATH . 'base/gather_general.php');
require_once(INSTALL_PATH . 'base/command.php');
=======================================
--- /trunk/etc/emt.cnf Fri Oct 8 10:14:42 2010
+++ /trunk/etc/emt.cnf Mon Feb 6 13:38:39 2012
@@ -2,6 +2,7 @@
extra_config_dir=/etc/emt.d/
gather_time = 60
plugin_timeout = 10
+logger = syslog
[emt_gather]
field=timestamp
@@ -15,7 +16,7 @@
[dateindex_text]
output_dir=/var/tmp/emt
-[sqlite_output]
+[sqlite3_io]
data_file=/var/tmp/emt.db
[emt_view]
=======================================
--- /trunk/scripts/build_rpm.sh Fri Aug 20 15:27:38 2010
+++ /trunk/scripts/build_rpm.sh Mon Feb 6 13:38:39 2012
@@ -18,6 +18,7 @@
$BUILDROOT/opt/emt/plugins/configuration \
$BUILDROOT/opt/emt/plugins/extra \
$BUILDROOT/opt/emt/plugins/fields \
+ $BUILDROOT/opt/emt/plugins/log \
$BUILDROOT/opt/emt/plugins/output \
$BUILDROOT/opt/emt/plugins/views \
$BUILDROOT/etc/cron.d \
@@ -34,6 +35,7 @@
cp plugins/configuration/* $BUILDROOT/opt/emt/plugins/configuration/
cp plugins/extra/* $BUILDROOT/opt/emt/plugins/extra/
cp plugins/fields/* $BUILDROOT/opt/emt/plugins/fields/
+cp plugins/log/* $BUILDROOT/opt/emt/plugins/log/
cp plugins/output/* $BUILDROOT/opt/emt/plugins/output/
cp plugins/views/* $BUILDROOT/opt/emt/plugins/views/
cp etc/emt.cnf $BUILDROOT/opt/emt/sample/
=======================================
--- /trunk/test/etc/emt.cnf Thu Jan 12 15:31:08 2012
+++ /trunk/test/etc/emt.cnf Mon Feb 6 13:38:39 2012
@@ -1,5 +1,9 @@
[global]
gather_time = 5
+logger = text
+
+[logger_text]
+file = ./tmp/log.txt
[emt_gather]
field=timestamp