[collectd] [PATCH] perl plugin: Exported plugin_log() to Perl.

Sebastian Harl sh<span style="display: none;">.trailing-username</span>(a)<span style="display: none;">leading-domain.</span>tokkee.org
Wed Apr 11 00:27:54 CEST 2007


This adds the following function to collectd's Perl API:

Collectd::plugin_log:
  pass a message to collectd's logging mechanism

  arguments:
  level - log level
  message - log message

The log level should be any of the Collectd::LOG_* constants.

Signed-off-by: Sebastian Harl <sh.trailing-username(a)leading-domain.tokkee.org>
---
 src/collectd.pod |   13 +++++++++----
 src/perl.c       |   27 ++++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/src/collectd.pod b/src/collectd.pod
index 0852490..6d29804 100644
--- a/src/collectd.pod
+++ b/src/collectd.pod
@@ -76,6 +76,10 @@ NFS utilization (I<nfs>, Linux only)
 
 =item
 
+Embedded Perl interpreter (I<perl>)
+
+=item
+
 Network latency (I<ping>)
 
 =item
@@ -269,10 +273,10 @@ I<5.2.4. Server Status Variables> for an explanation of these values.
 =head2 perl
 
 The C<perl plugin> includes a Perl-interpreter in collectd and provides
-Perl-equvalents of the plugin-functions. This makes it possible to write
+Perl-equivalents of the plugin-functions. This makes it possible to write
 plugins in Perl.
 
-There are two more comlex types you need to know about:
+There are two more complex types you need to know about:
 
 =over 4
 
@@ -345,7 +349,7 @@ array-reference which points to an array of hashes. Each hash describes one
 data-source. For the exact layout see B<Data-Set> above.
 
 If the I<type> argument is any of the other types (B<TYPE_INIT>, B<TYPE_READ>,
-...) when I<data> is expected to be a funtion reference. These functions are
+...) then I<data> is expected to be a function reference. These functions are
 called in the various stages of the daemon and are passed the following
 arguments:
 
@@ -388,7 +392,8 @@ registered with the daemon.
 
 =item B<plugin_log> (I<log-level>, I<message>)
 
-TODO.
+Submits a I<message> of level I<log-level> to collectd's logging mechanism.
+The message is passed to all log-callbacks that are registered with collectd.
 
 =back
 
diff --git a/src/perl.c b/src/perl.c
index 566a62c..48da338 100644
--- a/src/perl.c
+++ b/src/perl.c
@@ -56,6 +56,7 @@ void boot_DynaLoader (PerlInterpreter *, CV *);
 static XS (Collectd_plugin_register);
 static XS (Collectd_plugin_unregister);
 static XS (Collectd_plugin_dispatch_values);
+static XS (Collectd_plugin_log);
 
 
 /*
@@ -104,6 +105,7 @@ static struct {
 	{ "Collectd::plugin_register",        Collectd_plugin_register },
 	{ "Collectd::plugin_unregister",      Collectd_plugin_unregister },
 	{ "Collectd::plugin_dispatch_values", Collectd_plugin_dispatch_values },
+	{ "Collectd::plugin_log",             Collectd_plugin_log },
 	{ "", NULL }
 };
 
@@ -828,7 +830,6 @@ static XS (Collectd_plugin_dispatch_values)
 
 	dXSARGS;
 
-	items = 2;
 	if (2 != items) {
 		log_err ("Usage: Collectd::plugin_dispatch_values(name, values)");
 		XSRETURN_EMPTY;
@@ -857,6 +858,30 @@ static XS (Collectd_plugin_dispatch_values)
 } /* static XS (Collectd_plugin_dispatch_values) */
 
 /*
+ * Collectd::plugin_log (level, message).
+ *
+ * level:
+ *   log level (LOG_DEBUG, ... LOG_ERR)
+ *
+ * message:
+ *   log message
+ */
+static XS (Collectd_plugin_log)
+{
+	dXSARGS;
+
+	if (2 != items) {
+		log_err ("Usage: Collectd::plugin_log(level, message)");
+		XSRETURN_EMPTY;
+	}
+
+	log_debug ("Collectd::plugin_log: level = %i, message = \"%s\"",
+			SvIV (ST (0)), SvPV_nolen (ST (1)));
+	plugin_log (SvIV (ST (0)), SvPV_nolen (ST (1)));
+	XSRETURN_YES;
+} /* static XS (Collectd_plugin_log) */
+
+/*
  * Collectd::bootstrap ().
  */
 static XS (boot_Collectd)
-- 
1.4.4.4

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20070411/c1f47a97/attachment.pgp


More information about the collectd mailing list