diff --git a/.gitignore b/.gitignore
index c9b716dd..95c69e33 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,6 +26,7 @@ ext/home
ext/image_hash_ban
ext/ipban
ext/link_image
+ext/log_db
ext/news
ext/notes
ext/notes
diff --git a/contrib/log_db/main.php b/contrib/log_db/main.php
new file mode 100644
index 00000000..6049b278
--- /dev/null
+++ b/contrib/log_db/main.php
@@ -0,0 +1,66 @@
+get_int("ext_log_database_version") < 1) {
+ $database->create_table("score_log", "
+ id SCORE_AIPK,
+ date_sent DATETIME NOT NULL,
+ section VARCHAR(32) NOT NULL,
+ username VARCHAR(32) NOT NULL,
+ address SCORE_INET NOT NULL,
+ priority INT NOT NULL,
+ message TEXT NOT NULL,
+ INDEX(section)
+ ");
+ $config->set_int("ext_log_database_version", 1);
+ }
+
+ $config->set_default_int("log_db_priority", SCORE_LOG_INFO);
+ }
+
+ public function onSetupBuilding($event) {
+ $sb = new SetupBlock("Logging (Database)");
+ $sb->add_choice_option("log_db_priority", array(
+ "Debug" => SCORE_LOG_DEBUG,
+ "Info" => SCORE_LOG_INFO,
+ "Warning" => SCORE_LOG_WARNING,
+ "Error" => SCORE_LOG_ERROR,
+ "Critical" => SCORE_LOG_CRITICAL,
+ ), "Debug Level: ");
+ $event->panel->add_block($sb);
+ }
+
+ public function onPageRequest($event) {
+ global $database, $user;
+ if($event->page_matches("log/view")) {
+ if($user->is_admin()) {
+ $events = $database->get_all("SELECT * FROM score_log");
+ $this->theme->display_events($events);
+ }
+ }
+ }
+
+ public function onUserBlockBuilding($event) {
+ $event->add_link("Event Log", make_link("log/view"));
+ }
+
+ public function onLog($event) {
+ global $config, $database, $user;
+ if($event->priority >= $config->get_int("log_db_priority")) {
+ $database->execute("
+ INSERT INTO score_log(date_sent, section, priority, username, address, message)
+ VALUES(now(), ?, ?, ?, ?, ?)
+ ", array($event->section, $event->priority, $user->name, $_SERVER['REMOTE_ADDR'], $event->message));
+ }
+ }
+}
+?>
diff --git a/contrib/log_db/test.php b/contrib/log_db/test.php
new file mode 100644
index 00000000..80209a75
--- /dev/null
+++ b/contrib/log_db/test.php
@@ -0,0 +1,8 @@
+log_in_as_admin();
+ $this->log_out();
+ }
+}
+?>
diff --git a/contrib/log_db/theme.php b/contrib/log_db/theme.php
new file mode 100644
index 00000000..4104fcd8
--- /dev/null
+++ b/contrib/log_db/theme.php
@@ -0,0 +1,27 @@
+";
+ $table .= "Time | Module / Priority | Username / Address | Message | ";
+ $table .= "
";
+ $n = 0;
+ foreach($events as $event) {
+ $oe = ($n++ % 2 == 0) ? "even" : "odd";
+ $table .= "";
+ $table .= "".$event['date_sent']." | ";
+ $table .= "".$event['section']." / ".$event['priority']." | ";
+ $table .= "".html_escape($event['username'])." / ".$event['address']." | ";
+ $table .= "".html_escape($event['message'])." | ";
+ $table .= "
";
+ }
+ $table .= "";
+
+ global $page;
+ $page->set_title("Event Log");
+ $page->set_heading("Event Log");
+ $page->add_block(new NavBlock());
+ $page->add_block(new Block("Events", $table));
+ }
+}
+?>
diff --git a/core/event.class.php b/core/event.class.php
index 4ce3a795..feee5518 100644
--- a/core/event.class.php
+++ b/core/event.class.php
@@ -139,17 +139,6 @@ class LogEvent extends Event {
$this->priority = $priority;
$this->message = $message;
$this->time = time();
-
- // this should be an extension
- if(defined("X-HALFASSED-LOGGING")) {
- global $user;
- $ftime = date("Y-m-d H:i:s", $this->time);
- $username = $user->name;
- $ip = $_SERVER['REMOTE_ADDR'];
- $fp = fopen("shimmie.log", "a");
- fputs($fp, "$ftime\t$section/$priority\t$username/$ip\t$message\n");
- fclose($fp);
- }
}
}
?>
diff --git a/core/util.inc.php b/core/util.inc.php
index a54151d8..a5c681a5 100644
--- a/core/util.inc.php
+++ b/core/util.inc.php
@@ -406,12 +406,12 @@ function format_text($string) {
* Logging convenience *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-if(!defined("LOG_CRITICAL")) define("LOG_CRITICAL", 50);
-if(!defined("LOG_ERROR")) define("LOG_ERROR", 40);
-if(!defined("LOG_WARNING")) define("LOG_WARNING", 30);
-if(!defined("LOG_INFO")) define("LOG_INFO", 20);
-if(!defined("LOG_DEBUG")) define("LOG_DEBUG", 10);
-if(!defined("LOG_NOTSET")) define("LOG_NOTSET", 0);
+define("SCORE_LOG_CRITICAL", 50);
+define("SCORE_LOG_ERROR", 40);
+define("SCORE_LOG_WARNING", 30);
+define("SCORE_LOG_INFO", 20);
+define("SCORE_LOG_DEBUG", 10);
+define("SCORE_LOG_NOTSET", 0);
/**
* A shorthand way to send a LogEvent
@@ -424,14 +424,14 @@ function log_msg($section, $priority, $message) {
* A shorthand way to send a LogEvent
*/
function log_info($section, $message) {
- log_msg($section, LOG_INFO, $message);
+ log_msg($section, SCORE_LOG_INFO, $message);
}
/**
* A shorthand way to send a LogEvent
*/
function log_error($section, $message) {
- log_msg($section, LOG_ERROR, $message);
+ log_msg($section, SCORE_LOG_ERROR, $message);
}
diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php
index 6c794061..cbc6e6b5 100644
--- a/ext/alias_editor/main.php
+++ b/ext/alias_editor/main.php
@@ -39,6 +39,7 @@ class AliasEditor implements Extension {
if($user->is_admin()) {
if(isset($_POST['oldtag'])) {
$database->Execute("DELETE FROM aliases WHERE oldtag=?", array($_POST['oldtag']));
+ log_info("alias_editor", "Deleted alias for ".$_POST['oldtag']);
$page->set_mode("redirect");
$page->set_redirect(make_link("alias/list"));
@@ -102,6 +103,7 @@ class AliasEditor implements Extension {
}
else {
$database->Execute("INSERT INTO aliases(oldtag, newtag) VALUES(?, ?)", $pair);
+ log_info("alias_editor", "Added alias for {$event->oldtag} -> {$event->newtag}");
}
}
diff --git a/ext/comment/main.php b/ext/comment/main.php
index 35bf2214..61fcd336 100644
--- a/ext/comment/main.php
+++ b/ext/comment/main.php
@@ -444,7 +444,7 @@ class CommentList extends SimpleExtension {
"VALUES(?, ?, ?, now(), ?)",
array($image_id, $user->id, $_SERVER['REMOTE_ADDR'], $comment));
$cid = $database->db->Insert_ID();
- log_info("comment", "Comment #$cid added");
+ log_info("comment", "Comment #$cid added to Image #$image_id");
}
}
// }}}
diff --git a/ext/ext_manager/main.php b/ext/ext_manager/main.php
index fa374658..c45a566f 100644
--- a/ext/ext_manager/main.php
+++ b/ext/ext_manager/main.php
@@ -141,12 +141,14 @@ class ExtManager extends SimpleExtension {
else {
full_copy("contrib/$fname", "ext/$fname");
}
+ log_info("ext_manager", "Enabling $fname");
}
}
else {
// disable if currently enabled
if(file_exists("ext/$fname")) {
deltree("ext/$fname");
+ log_info("ext_manager", "Disabling $fname");
}
}
}
diff --git a/ext/setup/main.php b/ext/setup/main.php
index f2b131ab..44a2100a 100644
--- a/ext/setup/main.php
+++ b/ext/setup/main.php
@@ -280,6 +280,7 @@ class Setup extends SimpleExtension {
}
}
}
+ log_info("setup", "Configuration updated");
}
public function onUserBlockBuilding($event) {
diff --git a/ext/user/main.php b/ext/user/main.php
index 1db4fe7d..f22a4966 100644
--- a/ext/user/main.php
+++ b/ext/user/main.php
@@ -74,7 +74,7 @@ class UserPage extends SimpleExtension {
}
else if($event->get_arg(0) == "logout") {
set_prefixed_cookie("session", "", time()+60*60*24*$config->get_int('login_memory'), "/");
- log_info("user", "Logged out");
+ log_debug("user", "Logged out");
$page->set_mode("redirect");
$page->set_redirect(make_link());
}