diff options
author | Yugo Nagata | 2013-07-24 23:06:37 +0000 |
---|---|---|
committer | Yugo Nagata | 2013-07-24 23:06:37 +0000 |
commit | 8309cc7bd47f390d09ca00a828b44552c5ba7661 (patch) | |
tree | 9982c2eb09143bb8ee7161701d840a3a1250380e | |
parent | 0c3308f61ed31f7a02457ed5f4c7c9620f5e450b (diff) |
Add pagination fuctionality to log page
-rw-r--r-- | bootstrap.php | 1 | ||||
-rw-r--r-- | innerLog.php | 67 | ||||
-rw-r--r-- | lang/en.lang.php | 8 | ||||
-rw-r--r-- | lang/ja.lang.php | 8 | ||||
-rw-r--r-- | screen.css | 7 | ||||
-rw-r--r-- | status.php | 5 | ||||
-rw-r--r-- | templates/elements/status_js.tpl | 23 | ||||
-rw-r--r-- | templates/innerLog.tpl | 45 |
8 files changed, 143 insertions, 21 deletions
diff --git a/bootstrap.php b/bootstrap.php index bff53dd..24385c4 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -39,4 +39,5 @@ define('PCP_TIMEOUT', 10); define('PGPOOL_WAIT_SECONDS', 10); define('REFRESH_LOG_SECONDS', 2000); +define('EACH_LOG_LINES', 50); define('NO_ARGS', ' '); diff --git a/innerLog.php b/innerLog.php index 9bac2fe..7b8dcae 100644 --- a/innerLog.php +++ b/innerLog.php @@ -29,38 +29,77 @@ if (!isset($_SESSION[SESSION_LOGIN_USER])) { exit(); } +$logAction = (isset($_GET['logAction']) && $_GET['logAction'] ? + $_GET['logAction'] : 'all'); +$logOffset = (isset($_GET['logOffset']) && $_GET['logOffset'] ? + $_GET['logOffset'] : 0); +$logEnd = (isset($_GET['logEnd']) && $_GET['logEnd'] ? + $_GET['logEnd'] : 0); + $pgpoolLog = _PGPOOL2_LOG_FILE; if ($pgpoolLog == '') { $logDir = readLogDir(); $pgpoolLog = "$logDir/pgpool.log"; } -$logFile = @file($pgpoolLog); -if ($logFile == FALSE) { +$logFileAll = @file($pgpoolLog); +if ($logFileAll == FALSE) { $errorCode = 'e8001'; $tpl->assign('errorCode', $errorCode); $tpl->display('innerError.tpl'); exit(); } +$logTotalLines = count($logFileAll); -$logSplitFile = array(); -for ($i = 0; $i < count($logFile); $i++) { - $words = explode(" ", $logFile[$i]); - $words = array_merge(array_diff($words, array(""))); +switch ($logAction) { + case 'latest': + $logEnd = $logTotalLines; + $logOffset = $logTotalLines - EACH_LOG_LINES; + break; + case 'prev': + $logEnd = $logOffset; + $logOffset = $logOffset - EACH_LOG_LINES; + break; + case 'next': + $logOffset = $logEnd; + $logEnd = $logEnd + EACH_LOG_LINES; + break; + case 'all': + default: + $logEnd = $logTotalLines; + $logOffset = 0; + break; +} - $logFile[$i] = array('timestamp' => $words[0]. ' '. $words[1], - 'level' => $words[2], - 'pid' => $words[3]. ' '. $words[4], - 'message' => '' - ); +$logOffset = min(max($logOffset, 0), $logTotalLines); +$logEnd = min(max($logEnd, 0), $logTotalLines); +if ($logOffset == $logEnd) { + $logEnd = $logTotalLines; + $logOffset = 0; +} +$logFile = array(); +for ($i = $logOffset; $i < $logEnd; $i++) { + $words = explode(" ", $logFileAll[$i]); + $words = array_merge(array_diff($words, array(""))); + $logLine = array('timestamp' => $words[0]. ' '. $words[1], + 'level' => $words[2], + 'pid' => $words[3]. ' '. $words[4], + 'message' => '' + ); for ($j = 5; $j < count($words); $j++) { - $logFile[$i]['message'] .= ' '. $words[$j]; + $logLine['message'] .= ' '. $words[$j]; } - $logFile[$i]['message'] = trim($logFile[$i]['message']); + $logLine['message'] = trim($logLine['message']); + $logFile[] = $logLine; } -$tpl->assign('refreshTimeLog', REFRESH_LOG_SECONDS); $tpl->assign('logFile', $logFile); +$tpl->assign('logTotalLines', $logTotalLines); +$tpl->assign('logAction', $logAction); +$tpl->assign('logOffset', $logOffset); +$tpl->assign('logEnd', $logEnd); +$tpl->assign('refreshTimeLog', REFRESH_LOG_SECONDS); +$tpl->assign('eachLogLines', EACH_LOG_LINES); $tpl->display('innerLog.tpl'); ?> diff --git a/lang/en.lang.php b/lang/en.lang.php index 5735158..8feb756 100644 --- a/lang/en.lang.php +++ b/lang/en.lang.php @@ -260,7 +260,13 @@ $message = array( 'strLog' => 'Log', 'strLogin' => 'Login', 'strLoginName' => 'Login Name', + 'strLogLatest' => 'Show the Latest', + 'strLogNext' => 'Next', 'strLogout' => 'Logout', + 'strLogPrev' => 'Previous', + 'strLogReload' => 'Reload', + 'strLogShowAll' => 'Show the All Lines', + 'strLogShowLines' => 'Lines', 'strMasterServer' => 'Master Server', 'strMasterSlaveMode' => 'Master Slave mode', 'strMeasures' => 'Measures', @@ -348,7 +354,7 @@ $message = array( 'strVIP' => 'Virtual IP', 'strWdActive' => 'Active', 'strWdDown' => 'Down', - 'strWdInit' => 'Not Running', + 'strWdInit' => 'Not Started', 'strWdStandby' => 'Standby', 'strWeight' => 'Weight', diff --git a/lang/ja.lang.php b/lang/ja.lang.php index 686b4fb..972de53 100644 --- a/lang/ja.lang.php +++ b/lang/ja.lang.php @@ -251,7 +251,13 @@ $message = array( 'strLog' => 'ログ', 'strLogin' => 'ログイン', 'strLoginName' => 'ログイン名', + 'strLogLatest' => '最新', + 'strLogNext' => '次へ', 'strLogout' => 'ログアウト', + 'strLogPrev' => '前へ', + 'strLogReload' => '更新', + 'strLogShowAll' => '全ての行を表示', + 'strLogShowLines' => '行を表示', 'strMasterServer' => 'マスターサーバ', 'strMasterSlaveMode' => 'マスタースレーブモード', 'strMeasures' => '対策', @@ -297,8 +303,8 @@ $message = array( 'strQueryCache' => 'クエリキャッシュ', 'strQueryStr' => 'クエリ文字列', 'strReloadPgpool' => '設定リロード', - 'strReplicationMode' => 'レプリケーションモード', 'strReloadPgsql' => '設定リロード', + 'strReplicationMode' => 'レプリケーションモード', 'strReset' => 'リセット', 'strRestart' => '再起動', 'strRestartOption' => 'pgpool再起動オプション', @@ -67,7 +67,7 @@ td.pgconfig_msg img { /* --------------------------------------------------------------------- */ a:link { - color: red; + color: red; text-decoration: none; } a:visited { @@ -82,6 +82,11 @@ a img { border: none; } +#div_log a:link, #div_log a:visited { + color: orangered; + text-decoration: underline; +} + /* --------------------------------------------------------------------- */ /* input */ /* --------------------------------------------------------------------- */ @@ -53,7 +53,8 @@ $tpl->assign('pgpoolConf', _PGPOOL2_CONFIG_FILE); $tpl->assign('pcpConf', _PGPOOL2_PASSWORD_FILE); $tpl->assign('refreshTime', (0 <= _PGPOOL2_STATUS_REFRESH_TIME) ? _PGPOOL2_STATUS_REFRESH_TIME * 1000 : 5000); -$tpl->assign('refreshTimeLog', REFRESH_LOG_SECONDS); +$tpl->assign('refreshTimeLog', (0 <= REFRESH_LOG_SECONDS) ? + REFRESH_LOG_SECONDS * 1000 : 5000); $tpl->assign('useSyslog', useSyslog()); $tpl->assign('pipe', (isPipe(_PGPOOL2_LOG_FILE)) ? 1 : 0); $tpl->assign('msgStopPgpool', $message['msgStopPgpool']); @@ -195,7 +196,7 @@ function _doAction($action, $nodeNumber) return $viewPHP; } -/** Set node info from pgpool.conf when pgpool isn't active */ +/** Set node info from pgpool.conf when pgpool isn't running */ function setNodeInfoFromConf() { global $tpl; diff --git a/templates/elements/status_js.tpl b/templates/elements/status_js.tpl index 1bfbfb6..a42d1fb 100644 --- a/templates/elements/status_js.tpl +++ b/templates/elements/status_js.tpl @@ -3,6 +3,7 @@ var refreshTime = "{$refreshTime|escape}"; var refreshTimeLog = "{$refreshTimeLog|escape}"; var view = "{$viewPHP|escape}"; +var innerParameter = ''; var msgStartPgpool = "{$message.msgStartPgpool|escape}"; var msgStopPgpool = "{$message.msgStopPgpool|escape}"; var msgReloadPgpool = "{$message.msgReloadPgpool|escape}"; @@ -38,14 +39,14 @@ function load() if (content == null) { return; } content.innerHTML = ret; - if (view != "innerLog.php") { + if (view == "innerLog.php") { setTimeout("load()", refreshTimeLog); } else if (refreshTime > 0) { setTimeout("load()", refreshTime); } } } - xmlhttp.open('GET', view, true); + xmlhttp.open('GET', view + innerParameter, true); xmlhttp.setRequestHeader("If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT"); xmlhttp.send(""); } @@ -179,6 +180,24 @@ function execRemoveBackend(node_num) } /* --------------------------------------------------------------------- */ +/* Log Action */ +/* --------------------------------------------------------------------- */ + +function execLogAction(logAction) +{ + innerParameter = '?logAction=' + logAction + + '&logOffset=' + document.logForm.logOffset.value + + '&logEnd=' + document.logForm.logEnd.value; + return reloadLog(); +} + +function reloadLog() +{ + load(); + return false; +} + +/* --------------------------------------------------------------------- */ /* execute pgpool's commands */ /* --------------------------------------------------------------------- */ diff --git a/templates/innerLog.tpl b/templates/innerLog.tpl index ea7cf04..c9d2801 100644 --- a/templates/innerLog.tpl +++ b/templates/innerLog.tpl @@ -18,6 +18,51 @@ <br clear="all"> {/if} +<div id="div_log"> + <form action="status.php" name="logForm" method="post" /> + <input type="hidden" name="action" value="log"/> + + <input type="hidden" name="logAction" /> + <input type="hidden" name="logOffset" value="{$logOffset}"/> + <input type="hidden" name="logEnd" value="{$logEnd}"/> + + <p> + <input type="button" onClick="reloadLog()" + value="{$message.strLogReload|escape}"/> + {if $logAction == 'all'} + <input type="button" onClick="execLogAction('latest')" + value="{$message.strLogLatest|escape} {$eachLogLines} {$message.strLogShowLines|escape}"/> + {else} + <input type="button" onClick="execLogAction('all')" + value="{$message.strLogShowAll|escape}"/> + {/if} + </p> + <p> + <br /> + {if $logAction != 'all'} + <span> + {if $logOffset != 0} + <a href="javascript:void(0)" + onClick="execLogAction('prev')">{$message.strLogPrev|escape}</a> + {/if} + {if $logEnd < $logTotalLines} + <a href="javascript:void(0)" + onClick="execLogAction('next')">{$message.strLogNext|escape}</a> + {/if} + </span> + {/if} + <span> + {if $logAction == 'all'} + (Total {$logTotalLines} lines) + {else} + ({$logOffset + 1} - {$logEnd} + of {$logTotalLines} lines) + {/if} + </span> + </p> + </form> +</div> + <table> <thead> </thead> |