NAME
MT::Log - Movable Type activity log record
SYNOPSIS
use MT::Log; my $log = MT::Log->new; $log->message('This is a message in the activity log.'); $log->save or die $log->errstr;
Extended log example:
use MT::Log; my $log = MT::Log->new; $log->message("This is a debug message"); $log->level(MT::Log::DEBUG()); $log->save or die $log->errstr;
You can also log directly with the MT package:
MT->log({ message => "A new entry has been posted.", metadata => $entry->id, class => 'entry' });
DESCRIPTION
An MT::Log object represents a record in the Movable Type activity log.
USAGE
As a subclass of MT::Object, MT::Log inherits all of the data-management and -storage methods from that class; thus you should look at the MT::Object documentation for details about creating a new object, loading an existing object, saving an object, etc.
SUBCLASSING
MT::Log may be subclassed for different types of log records. The MT Activity Feeds make use of this feature.
# MyCustomLog.pm package MyCustomLog; use base 'MT::Log'; sub description { # returns html presentation of log message; used in activity # log view and activity feeds... } 1;
If you do define your own subclass, you will want to register it when your plugin loads. The key/value pairs assigned to the plugin's "log_classes" element should be unique enough to not conflict with other plugins.
# Plugin file MT->add_plugin({ name => "My custom plugin", log_classes => { customlog => "MyCustomLog" } }); 1;
METHODS
CLASS->new()
Creates a new log object.
$log->init()
Initializes the created_on and modified_on properties of the object to the current time (these are overwritten if an object is being loaded from the database).
CLASS->class_label
Returns a localized string identifying the kind of log record the class is for.
$log->description
Provides an extended view of the log data; this may contain HTML.
$log->metadata_class()
Returns a Perl package name for the metadata object related to the log record.
$log->metadata_object
The base MT::Log metadata_object method will return a MT data object that is related to this log object in the event that:
- 1. The metadata column is populated with a number.
- 2. The class column has an identifier that maps to a registered MT::Log subclass.
- 3. The class identified for the log record is provided by the
metadata_class
method. - 2. The class column has an identifier that maps to a registered MT::Log subclass.
If these conditions are met, this method will attempt to load a record using the package name provided by the metadata_class
method with the id given in the metadata column.
MT::Log->add_class($identifier => $package_name)
Registers a MT::Log subclass with an identifier that is stored in the 'class' column of log records.
$log->set_values(\%values)
Overrides the MT::Object set_values method and reblesses the object with the appropriate MT::Log subclass based on the identifier in the 'class' column.
$log->to_hash()
Returns a hashref of data that represents the data held by the log object and any associated metadata_object that it points to.
DATA ACCESS METHODS
The MT::Log object holds the following pieces of data. These fields can be accessed and set using the standard data access methods described in the MT::Object documentation.
- id
The numeric ID of the log record.
- message
The log entry.
- blog_id
For log messages that occurred within the context of a blog, the blog's id is stored in this column.
- author_id
For log messages that were created from the action of a user, their author id is recorded in this column.
- class
Optional. An identifier that relates to a Perl package name that is a valid MT::Log descendant class (or relates to MT::Log itself).
- category
Optional. A field to further categorize the message being logged. Being an indexed column, it is possible to filter on this column when selecting log records.
- level
Optional. A number that defines the level or priority of the log message. This column may be one of the following values (shown below are the package constants for each level followed by their numeric equivalent).
- INFO / 1
- WARNING / 2
- ERROR / 4
- SECURITY / 8
- DEBUG / 16
The default value for level is 1 (INFO).
- metadata
A storage field for additional information about this particular log message. Different log classes utilize this field in different ways.
- ip
The IP address related with the message; this is useful, for example, when the message pertains to a failed login, to determine the IP address of the user who attempted to log in.
- created_on
The timestamp denoting when the log record was created, in the format
YYYYMMDDHHMMSS
. This timestamp is always in GMT. - modified_on
The timestamp denoting when the log record was last modified, in the format
YYYYMMDDHHMMSS
. Note that the timestamp has already been adjusted for the selected timezone.
DATA LOOKUP
In addition to numeric ID lookup, you can look up or sort records by any combination of the following fields. See the load documentation in MT::Object for more information.
- created_on
- blog_id
- level
- class
AUTHOR & COPYRIGHTS
Please see the MT manpage for author, copyright, and license information.