From: Sebastian Harl Date: Tue, 10 Apr 2007 22:27:54 +0000 (+0200) Subject: perl plugin: Exported plugin_log() to Perl. X-Git-Tag: collectd-4.0.0~81^2~1 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=f59d051e2087090f15545c65facbc507699ac7e6;p=collectd.git perl plugin: Exported plugin_log() to Perl. 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 --- diff --git a/src/collectd.pod b/src/collectd.pod index 08524901..6d298049 100644 --- a/src/collectd.pod +++ b/src/collectd.pod @@ -76,6 +76,10 @@ NFS utilization (I, Linux only) =item +Embedded Perl interpreter (I) + +=item + Network latency (I) =item @@ -269,10 +273,10 @@ I<5.2.4. Server Status Variables> for an explanation of these values. =head2 perl The C 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 above. If the I argument is any of the other types (B, B, -...) when I is expected to be a funtion reference. These functions are +...) then I 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 (I, I) -TODO. +Submits a I of level I 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 566a62c7..48da3389 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)