Six Apart Code

<<

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 => 'MT::Log::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

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.

<<

Six Apart
Makers of weblog software and services for individuals, organizations and businesses.