Solstice::LogService - Provides a centralized logging facility to applications.


Solstice documentation Contained in the Solstice distribution.

Index


Code Index:

NAME

Top

Solstice::LogService - Provides a centralized logging facility to applications.

SYNOPSIS

Top



    $self->getLogService()->log({
        content     => 'User did blah',     #the content of the log message
        namespace   => 'appname',           #optional - the directory in the data root to use - defaults to the app's namespace
        username    => 'mcrawfor',          #optional - current user is pulled from userservice if not provided
        log_file    => 'blah_log',          #optional - defaults to 'log';
        model       => $model->getName(),   #Optional - a textual description of a model
        model_id    => $model->getID(),     #optional - the id of the model in question




DESCRIPTION

Top

Superclass

Solstice::Service

Export

No symbols exported.

Methods

new([$namespace])

Creates a new Solstice::LogService object.

log(\%params)
logAnonymous(\%params)

This is equivalent to log(), but the username and timestamp won't be passed on to the logging modules

add(\%params)

Alias for log().

Private Methods

_dispatch($message)
_getClassName()

Return the class name. Overridden to avoid a ref() in the superclass.

Modules Used

Solstice::Service, Solstice::Model::LogMessage (Solstice::Model::LogMessage).

AUTHOR

Top

Catalyst Group, <catalyst@u.washington.edu>

VERSION

Top

$Revision: 3364 $

COPYRIGHT

Top


Solstice documentation Contained in the Solstice distribution.
package Solstice::LogService;

# $Id: LogService.pm 3364 2006-05-05 07:18:21Z mcrawfor $
#
use 5.006_000;
use strict;
use warnings;

use base qw(Solstice::Service);

use Solstice::DateTime;
use Solstice::Model::LogMessage;

use constant DEFAULT_LOGFILE => 'log';

our ($VERSION) = ('$Revision: 3364 $' =~ /^\$Revision:\s*([\d.]*)/);

sub new {
    my $class = shift;
    my $namespace = shift;
    
    my $self = $class->SUPER::new(@_);

    unless (defined $namespace) {
        caller =~ m/^(\w+):.*$/;
        $namespace = $1;
    }

    $self->setNamespace($namespace);

    return $self;
}


sub log {
    my $self = shift;
    my $params = shift;
    return unless defined $params;
    
    my $message = Solstice::Model::LogMessage->new();
   
    if ($params->{'username'}) {
        $message->setUsername($params->{'username'});
    } else {
        my $user_service = $self->getUserService();
        $message->setUsername($user_service->getOriginalUser() ? $user_service->getOriginalUser()->getScopedLoginName() : undef);
        $message->setActingUsername($user_service->getUser() ? $user_service->getUser()->getScopedLoginName() : undef);
    }
        
    $message->setContent($params->{'content'});
    $message->setNamespace($params->{'namespace'} || $self->getNamespace());
    $message->setLogName($params->{'log_file'} || DEFAULT_LOGFILE);
    $message->setModel($params->{'model'});
    $message->setModelID($params->{'model_id'});
    $message->setDateTime(Solstice::DateTime->new(time));
    
    return $self->_dispatch($message);
}

sub logAnonymous {
    my $self = shift;
    my $params = shift;
    return unless defined $params;

    my $message = Solstice::Model::LogMessage->new();
    $message->setContent($params->{'content'});
    $message->setNamespace($params->{'namespace'} || $self->getNamespace());
    $message->setLogName($params->{'log_file'} || DEFAULT_LOGFILE);
    $message->setModel($params->{'model'});
    $message->setModelID($params->{'model_id'});

    return $self->_dispatch($message);
}

sub add {
    my $self = shift;
    return $self->log(@_);
}

sub _dispatch {
    my $self = shift;
    my $message = shift;

    for my $module (@{ $self->getConfigService()->getLogModules() }){
        $self->loadModule($module);
        my $logger = $module->new();
        $logger->writeLog($message) if $logger->can('writeLog');
    }
    return; 
}

sub _getClassName {
    return 'Solstice::LogService';
}

1;
__END__