On Wednesday, September 28, 2011, Kenneth P. Oncinian wrote:

> I found the following perl script in the web that logs data from a
> serial port to a log file.
> I tested it on a PBX and it worked Ok - logging the the SMDR data to a
> log file.
> Can this script be extended so that it inserts the data to a MySQL table
> instead of using a log file? Or better yet using both log file and MySQL.
>
>
Sure, you'll probably need something like Log::Dispatch[0]  using a DBI[1]
backend along with regular logfile.

[0]:  http://metacpan.org/module/Log::Dispatch
[1]:  http://metacpan.org/module/Log::Dispatch::DBI

In the script below, you can do something like this, before creating the
Device::SerialPort object:

,----
| use Log::Dispatch;
|
| my $log = Log::Dispatch->new(
|   outputs => [
|     ['File', min_level => 'debug', filename => '/path/to/logfile'],
|     [ 'DBI',
|       min_level  => 'info',
|       datasource => 'dbi:mysql:log',
|       username   => 'logger',
|       password   => 'lumberjack',
|       table      => 'logging'
|     ]
|   ]
| );
`----

Then later on, if you want to log, just do the following, instead of `print
LOG $sStr':

,----
| $log->info($sStr);
`----

Of course, you have to create the MYSQL database prior; see the perldoc for
Log::Dispatch::DBI for more information.


-- 
Zak B. Elep  ||  zakame.net
1486 7957 454D E529 E4F1  F75E 5787 B1FD FA53 851D
_________________________________________________
Philippine Linux Users' Group (PLUG) Mailing List
http://lists.linux.org.ph/mailman/listinfo/plug
Searchable Archives: http://archives.free.net.ph

Reply via email to