better logging
This commit is contained in:
parent
44c8461f3b
commit
f4a74c4d4c
@ -43,14 +43,17 @@ class LogDatabase extends SimpleExtension {
|
||||
global $database, $user;
|
||||
if($event->page_matches("log/view")) {
|
||||
if($user->is_admin()) {
|
||||
$events = $database->get_all("SELECT * FROM score_log");
|
||||
$events = $database->get_all("SELECT * FROM score_log ORDER BY id DESC LIMIT 50");
|
||||
$this->theme->display_events($events);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function onUserBlockBuilding($event) {
|
||||
$event->add_link("Event Log", make_link("log/view"));
|
||||
global $user;
|
||||
if($user->is_admin()) {
|
||||
$event->add_link("Event Log", make_link("log/view"));
|
||||
}
|
||||
}
|
||||
|
||||
public function onLog($event) {
|
||||
|
@ -3,17 +3,23 @@
|
||||
class LogDatabaseTheme extends Themelet {
|
||||
public function display_events($events) {
|
||||
$table = "<table class='zebra'>";
|
||||
$table .= "<thead><th>Time</th><th>Module / Priority</th><th>Username / Address</th><th>Message</th></thead>";
|
||||
$table .= "<tbody>";
|
||||
$table .= "<thead><th>Time</th><th>Module</th><th>User</th><th>Message</th></thead>";
|
||||
$table .= "<tbody>\n";
|
||||
$n = 0;
|
||||
foreach($events as $event) {
|
||||
$oe = ($n++ % 2 == 0) ? "even" : "odd";
|
||||
$table .= "<tr class='$oe'>";
|
||||
$table .= "<td>".$event['date_sent']."</td>";
|
||||
$table .= "<td>".$event['section']." / ".$event['priority']."</td>";
|
||||
$table .= "<td>".html_escape($event['username'])." / ".$event['address']."</td>";
|
||||
$c = $this->pri_to_col($event['priority']);
|
||||
$table .= "<tr style='color: $c' class='$oe'>";
|
||||
$table .= "<td>".str_replace(" ", " ", $event['date_sent'])."</td>";
|
||||
$table .= "<td>".$event['section']."</td>";
|
||||
if($event['username'] == "Anonymous") {
|
||||
$table .= "<td>".$event['address']."</td>";
|
||||
}
|
||||
else {
|
||||
$table .= "<td><span title='".$event['address']."'>".html_escape($event['username'])."</span></td>";
|
||||
}
|
||||
$table .= "<td>".html_escape($event['message'])."</td>";
|
||||
$table .= "</tr>";
|
||||
$table .= "</tr>\n";
|
||||
}
|
||||
$table .= "</tbody></table>";
|
||||
|
||||
@ -23,5 +29,16 @@ class LogDatabaseTheme extends Themelet {
|
||||
$page->add_block(new NavBlock());
|
||||
$page->add_block(new Block("Events", $table));
|
||||
}
|
||||
|
||||
protected function pri_to_col($pri) {
|
||||
switch($pri) {
|
||||
case SCORE_LOG_DEBUG: return "#999";
|
||||
case SCORE_LOG_INFO: return "#000";
|
||||
case SCORE_LOG_WARNING: return "#800";
|
||||
case SCORE_LOG_ERROR: return "#C00";
|
||||
case SCORE_LOG_CRITICAL: return "#F00";
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -477,19 +477,11 @@ function log_msg($section, $priority, $message) {
|
||||
send_event(new LogEvent($section, $priority, $message));
|
||||
}
|
||||
|
||||
/**
|
||||
* A shorthand way to send a LogEvent
|
||||
*/
|
||||
function log_info($section, $message) {
|
||||
log_msg($section, SCORE_LOG_INFO, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* A shorthand way to send a LogEvent
|
||||
*/
|
||||
function log_error($section, $message) {
|
||||
log_msg($section, SCORE_LOG_ERROR, $message);
|
||||
}
|
||||
function log_debug($section, $message) {log_msg($section, SCORE_LOG_DEBUG, $message);}
|
||||
function log_info($section, $message) {log_msg($section, SCORE_LOG_INFO, $message);}
|
||||
function log_warning($section, $message) {log_msg($section, SCORE_LOG_WARNING, $message);}
|
||||
function log_error($section, $message) {log_msg($section, SCORE_LOG_ERROR, $message);}
|
||||
function log_critical($section, $message) {log_msg($section, SCORE_LOG_CRITICAL, $message);}
|
||||
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
||||
|
@ -15,7 +15,7 @@ class Handle404 implements Extension {
|
||||
if($page->mode == "page" && (!isset($page->blocks) || $this->count_main($page->blocks) == 0)) {
|
||||
$h_pagename = html_escape(implode('/', $event->args));
|
||||
header("HTTP/1.0 404 Page Not Found");
|
||||
log_info("handle_404", "Hit 404: $h_pagename");
|
||||
log_debug("handle_404", "Hit 404: $h_pagename");
|
||||
$page->set_title("404");
|
||||
$page->set_heading("404 - No Handler Found");
|
||||
$page->add_block(new NavBlock());
|
||||
|
@ -287,7 +287,7 @@ class Setup extends SimpleExtension {
|
||||
}
|
||||
}
|
||||
}
|
||||
log_info("setup", "Configuration updated");
|
||||
log_warning("setup", "Configuration updated");
|
||||
}
|
||||
|
||||
public function onUserBlockBuilding($event) {
|
||||
|
@ -242,7 +242,12 @@ class UserPage extends SimpleExtension {
|
||||
if(!is_null($duser)) {
|
||||
$user = $duser;
|
||||
$this->set_login_cookie($name, $pass);
|
||||
log_info("user", "Logged in");
|
||||
if($user->is_admin()) {
|
||||
log_warning("user", "Admin logged in");
|
||||
}
|
||||
else {
|
||||
log_info("user", "User logged in");
|
||||
}
|
||||
$page->set_mode("redirect");
|
||||
$page->set_redirect(make_link("user"));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user