#!/usr/bin/perl -w
#
# $Id: Log.pm,v 1.8 2002/03/08 10:02:54 fpmip Exp $
#
# Implements message logging
#
# Author : Tycho Fruru <tycho@fruru.com>
#
# Copyright (C) 2001 Tycho Fruru <tycho@fruru.com>
# Copyright (C) 2001 Conostix S.A. Luxembourg - Tycho Fruru <tycho@conostix.com>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
#
# 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 General Public License
# for more details.
#
package IPFC::Log;

use strict;
use warnings;

BEGIN {
	use Exporter ();
	our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,%EXPORT_TAGS);
	
	# set the version for version checking
	$VERSION     = 1.04;
	@ISA	     = qw(Exporter);
	@EXPORT	     = qw(&set_verbosity &logger);
	%EXPORT_TAGS = qw( );
	
	# exported package globals go here
	# as well as any optionally exported functions
	@EXPORT_OK   = qw( );
}

our @EXPORT_OK;

use POSIX ();
use Sys::Hostname ();

$| = 1;

my $verbosity = 1;
my $hostname  = Sys::Hostname::hostname();

sub set_verbosity($) { 
# takes a number, which is the verbosity.  Higher numbers mean more verbosity.
	$verbosity = shift;
}

sub logger($;$) {
# logger takes one or two parameters, [level,]message
	my $level   = shift;
	my $message = shift;
	
	if (!defined($message)) {
		$message = $level;
		$level = 1;
	}

	if ($level <= $verbosity) {
		chomp $message;
		my $timestamp = POSIX::strftime("%Y-%m-%d %H:%M:%S%z",localtime);
		print $timestamp." ".$hostname." ".$0."[".$$."] ".$message."\n";
	}
}


return 1;
