Added basic Log class (#143)
This commit is contained in:
parent
61a868980e
commit
f479511454
13
php/database/log_table.sql
Normal file
13
php/database/log_table.sql
Normal file
@ -0,0 +1,13 @@
|
||||
# Dump of table lychee_log
|
||||
# Version 2.5
|
||||
# ------------------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `lychee_log` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`time` int(11) NOT NULL,
|
||||
`type` varchar(11) NOT NULL,
|
||||
`function` varchar(100) NOT NULL,
|
||||
`line` int(11) NOT NULL,
|
||||
`text` TEXT DEFAULT '',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
|
@ -29,7 +29,7 @@ class Database extends Module {
|
||||
if (!Database::createDatabase($database, $name)) exit('Error: Could not create database!');
|
||||
|
||||
# Check tables
|
||||
if (!$database->query('SELECT * FROM lychee_photos, lychee_albums, lychee_settings LIMIT 0;'))
|
||||
if (!$database->query('SELECT * FROM lychee_photos, lychee_albums, lychee_settings, lychee_log LIMIT 0;'))
|
||||
if (!Database::createTables($database)) exit('Error: Could not create tables!');
|
||||
|
||||
return $database;
|
||||
@ -119,6 +119,19 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
||||
# Check dependencies
|
||||
Module::dependencies(isset($database));
|
||||
|
||||
# Create log
|
||||
if (!$database->query('SELECT * FROM lychee_log LIMIT 0;')) {
|
||||
|
||||
# Read file
|
||||
$file = __DIR__ . '/../database/log_table.sql';
|
||||
$query = @file_get_contents($file);
|
||||
|
||||
# Create table
|
||||
if (!isset($query)||$query===false) return false;
|
||||
if (!$database->query($query)) return false;
|
||||
|
||||
}
|
||||
|
||||
# Create settings
|
||||
if (!$database->query('SELECT * FROM lychee_settings LIMIT 0;')) {
|
||||
|
||||
|
37
php/modules/Log.php
Normal file
37
php/modules/Log.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
###
|
||||
# @name Log Module
|
||||
# @author Tobias Reich
|
||||
# @copyright 2014 by Tobias Reich
|
||||
###
|
||||
|
||||
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
||||
|
||||
class Log extends Module {
|
||||
|
||||
public static function error($database, $function, $line, $text = '') {
|
||||
|
||||
# Check dependencies
|
||||
Module::dependencies(isset($database, $function, $line, $text));
|
||||
|
||||
# Get time
|
||||
$sysstamp = time();
|
||||
|
||||
# Escape
|
||||
$function = mysqli_real_escape_string($database, $function);
|
||||
$line = mysqli_real_escape_string($database, $line);
|
||||
$text = mysqli_real_escape_string($database, $text);
|
||||
|
||||
# Save in database
|
||||
$query = "INSERT INTO lychee_log (time, type, function, line, text) VALUES ('$sysstamp', 'error', '$function', '$line', '$text');";
|
||||
$result = $database->query($query);
|
||||
|
||||
if (!$result) return false;
|
||||
return $database->insert_id;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user