0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MTクラウドのサーバ配信ログを取得する

Posted at

Movable Typeクラウド版のサーバ配信機能は機能自体は申し分ないのですが、設定を行う画面しかないので、履歴等が確認できず使用していていまいち安心感がありません。

ですが、MTのログを見てみると「サーバー配信が正常に処理されました」というものが記録されていたりします。これをいい感じに表示すれば配信履歴として使用できそうです。

MTのログにはcategoryという情報を付けることができ、これによってログを分類することができます。前述のログには「contents_sync」というcategoryがつけられていた為、このcategoryでログを抜き出せばサーバ配信系のログだけを取得できるはずです。

ということで、以下のコードでサーバ配信系のログの最新5件を取得することができます。

    my @logs = MT::Log->load(
                   { blog_id => $blog->id, category => 'contents_sync' },
                   {
                        sort => 'created_on',
                        direction => 'descend',
                        limit => 5
                    }
    );

これを表示するダッシュボードウィジェットを適当にこしらえると安心感がましていい感じになります。

config.yaml
id  : MTCloudDeployLog
key : MTCloudDeployLog
name: MTクラウドサーバ配信ログ
version: 1.0
author_name: rryu
author_link: 
description: MTクラウドのサーバ配信ログを表示するダッシュボードウィジェットを追加します。

widgets:
    deploy_log:
        label: サーバ配信ログ
        plugin: $MTCloudDeployLog
        singular: 1
        set: main
        template: deploy_log_widget.tmpl
        handler: $MTCloudDeployLog::hdlr_deploy_log_widget
tmpl/deploy_log_widget.tmpl
<mtapp:widget
   label="サーバ配信ログ"
   id="deploy_log_widget"
   class="widget"
   can_close="1">

    <ul>
      <mt:Loop name="logs">
        <li>
          <$mt:Var name="log.format_created_on"$> : 
          <$mt:Var name="log.message"$>
        </li>
      </mt:Loop>
    </ul>

</mtapp:widget>
lib/MTCloudDeployLog.pm
package MTCloudDeployLog;
use strict;
use utf8;

sub hdlr_deploy_log_widget {
    my ($app, $tmpl, $param) = @_;

    my $blog = $app->blog;

    my @logs = MT::Log->load(
                   { blog_id => $blog->id, category => 'contents_sync' },
                   {
                        sort => 'created_on',
                        direction => 'descend',
                        limit => 5
                    }
    );

    @logs = map { 
        my $item = $_->to_hash();
        $item->{'log.format_created_on'} = _format_ts_gmt($app, $_->created_on, $blog);
        $item;
    } @logs;

    $param->{'logs'} = \@logs;
}


sub _format_ts_gmt {
    my ($app, $ts, $blog) = @_;

    return '' unless $ts;

    $blog = $app->blog unless $blog;
    my $epoch = MT::Util::ts2epoch(undef, $ts);
    $epoch = MT::Util::offset_time($epoch, undef, 1);
    $ts = MT::Util::epoch2ts(undef, $epoch);

    my $lang = $app->user ? $app->user->preferred_language : undef;

    return MT::Util::format_ts(MT::App::CMS::LISTING_TIMESTAMP_FORMAT(), $ts, $blog, $lang);
}

1;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?