[Eis-commits] SF.net SVN: eis: [213] trunk
Status: Pre-Alpha
Brought to you by:
baslijnse
|
From: <bas...@us...> - 2007-09-17 09:14:14
|
Revision: 213
http://eis.svn.sourceforge.net/eis/?rev=213&view=rev
Author: baslijnse
Date: 2007-09-17 02:14:09 -0700 (Mon, 17 Sep 2007)
Log Message:
-----------
Added logging as pluggable service backend
Modified Paths:
--------------
trunk/cfg/environments.xml
trunk/lib/engine/application.lib.php
trunk/lib/engine/engine.lib.php
trunk/lib/engine/environment.lib.php
trunk/lib/engine/request.lib.php
trunk/lib/engine/session.lib.php
trunk/lib/engine/user.lib.php
trunk/mod/eis_engine/applications/servermanager.xml
Added Paths:
-----------
trunk/lib/engine/log.lib.php
trunk/mod/eis_log/
trunk/mod/eis_log/config/
trunk/mod/eis_log/config/module.php
trunk/mod/eis_log/module.xml
trunk/mod/eis_log/services/
trunk/mod/eis_log/services/FileLogService.php
Removed Paths:
-------------
trunk/lib/engine/logging.lib.php
trunk/mod/eis_user/elements/.UserSelectMembership.php.swp
trunk/mod/log/
Modified: trunk/cfg/environments.xml
===================================================================
--- trunk/cfg/environments.xml 2007-09-16 11:28:25 UTC (rev 212)
+++ trunk/cfg/environments.xml 2007-09-17 09:14:09 UTC (rev 213)
@@ -22,7 +22,7 @@
<mysql_user></mysql_user>
<mysql_password></mysql_password>
<mysql_database></mysql_database>
- <data_dir></data_dir>
+ <data_dir>data</data_dir>
</environment>
<environment>
<name>dev</name>
Modified: trunk/lib/engine/application.lib.php
===================================================================
--- trunk/lib/engine/application.lib.php 2007-09-16 11:28:25 UTC (rev 212)
+++ trunk/lib/engine/application.lib.php 2007-09-17 09:14:09 UTC (rev 213)
@@ -17,6 +17,7 @@
var $session_backend = null;
var $authentication_backend = null;
+ var $log_backend = null;
var $elements = array();
@@ -67,6 +68,7 @@
//Backends
$this->session_backend = $struct->getValue($app,'session_backend');
$this->authentication_backend = $struct->getValue($app,'authentication_backend');
+ $this->log_backend = $struct->getValue($app,'log_backend');
//Module configuration
$modules = $struct->getArray($app,'module');
@@ -307,6 +309,7 @@
$cache .= "\$this->title =".var_export($this->title, true).";\n";
$cache .= "\$this->session_backend =".var_export($this->session_backend, true).";\n";
$cache .= "\$this->authentication_backend =".var_export($this->authentication_backend, true).";\n";
+ $cache .= "\$this->log_backend =".var_export($this->log_backend, true).";\n";
$cache .= "\$this->elements =".var_export($this->elements, true).";\n";
$cache .= "\$this->page_root =".var_export($this->page_root, true).";\n";
$cache .= "\$this->page_notfound =".var_export($this->page_notfound, true).";\n";
@@ -329,6 +332,9 @@
function getAuthenticationBackend() {
return $this->authentication_backend;
}
+ function getLogBackend() {
+ return $this->log_backend;
+ }
function getRequiredModules() {
return array_keys($this->modules);
}
Modified: trunk/lib/engine/engine.lib.php
===================================================================
--- trunk/lib/engine/engine.lib.php 2007-09-16 11:28:25 UTC (rev 212)
+++ trunk/lib/engine/engine.lib.php 2007-09-17 09:14:09 UTC (rev 213)
@@ -29,6 +29,7 @@
var $session = null; /**< The session instance */
var $user = null; /**< The user instance */
+ var $log = null; /**< The log instance */
/**
* Engine constructor, gathers basic info about the environment.
@@ -120,21 +121,13 @@
}
/**
- *Initialize logging
+ *Initialize log
*/
- /*
- function _initLogging() {
-
- $config = $this->_loadModuleConfig('log');
-
- $this->log = new Logging();
-
- $this->log->setEngine($this);
- $this->log->setOutput($config['log_output']);
- if($this->config['enable_datadir'])
- $this->log->setLogFile($this->getDatadir('log').'/'.$config['log_file']);
+ function _initLog() {
+ require("lib/engine/log.lib.php");
+ require("lib/base/logservice.lib.php");
+ $this->log = new Log($this);
}
- */
/**
* Return's the main locale for a module. The main locale is
* the locale in which a module is maintained. Other locales are
@@ -632,6 +625,7 @@
}
}
+
//Initialize the locale
$this->_initLocale('en_en'); //TODO configurable locale
@@ -641,6 +635,9 @@
//Initialize the user
$this->_initUser();
+ //Initialize log
+ $this->_initLog();
+
//Catch errors
ini_set('display_errors',TRUE);
ini_set('error_reporting',E_ALL);
@@ -1044,11 +1041,10 @@
/**
* Get the Datadir
*
- * @param module the module for which the datadir is requested
- * @result returns the path to the dir on succes and null on failure
+ * @return returns the path to the dir on succes and null on failure
*/
- function getDataDir($module) {
- return $this->environment->getDataDir($module);
+ function getDataDir() {
+ return $this->environment->getDataDir();
}
/**
Modified: trunk/lib/engine/environment.lib.php
===================================================================
--- trunk/lib/engine/environment.lib.php 2007-09-16 11:28:25 UTC (rev 212)
+++ trunk/lib/engine/environment.lib.php 2007-09-17 09:14:09 UTC (rev 213)
@@ -100,28 +100,18 @@
return $this->admin;
}
- function getDataDir($module) {
+ function getDataDir() {
if($this->datadir == null)
- $this->e->error(1020,'Datadir error: No datadir configured ');
+ $this->e->error(1020,'No datadir configured ');
- $dir = $this->datadir.'/'.$module;
-
- //Try to return the path
- if(file_exists($dir)) {
- if(is_writable($dir) && is_readable($dir))
- return $dir;
+ //Check if it is accessable
+ if(file_exists($this->datadir)) {
+ if(is_writable($this->datadir) && is_readable($this->datadir))
+ return $this->datadir;
else
- $this->e->error(1020,'Datadir error: Datadir for module \''.$module.'\' not writeable/readable');
+ $this->e->error(1020,'Datadir not writeable/readable');
}
- //Try to create the dir for the module
- if(is_writable($this->datadir)) {
- mkdir($dir);
- return $dir;
- } else {
- $this->e->error(1020,'Datadir error: Datadir not writeable');
- }
-
return null;
}
Copied: trunk/lib/engine/log.lib.php (from rev 212, trunk/lib/engine/logging.lib.php)
===================================================================
--- trunk/lib/engine/log.lib.php (rev 0)
+++ trunk/lib/engine/log.lib.php 2007-09-17 09:14:09 UTC (rev 213)
@@ -0,0 +1,57 @@
+<?php
+ /**
+ *class that contains all loging functions
+ */
+ class Log {
+
+ var $e; /**< varaiable for the engine */
+
+ function Log(&$engine) {
+ $this->e =& $engine;
+ }
+
+ /**
+ *add message to the logfile
+ *@param the message to be added
+ */
+ function logMessage($msg) {
+ $this->_writeLog($msg, 'message');
+ }
+ /**
+ *add warning to the logfile
+ *@param the warning to be added
+ */
+ function logWarning($msg) {
+ $this->_writeLog($msg, 'warning');
+ }
+ /**
+ *add error to the logfile
+ *@param the error to be added
+ */
+ function logError($msg) {
+ $this->_writeLog($msg, 'error');
+ }
+
+ /**
+ *write something to the logfile
+ *@param message to written to logfile
+ *@param type the type of log message ('message','warning','error')
+ */
+ function _writeLog($msg, $type) {
+
+ $backend = $this->e->application->getLogBackend();
+ if(!is_array($backend)) {
+ return;
+ }
+
+ $service =& $this->e->getService($backend['module'],$backend['service']);
+
+ $time = time();
+ $ip = $this->e->request->getClientIp();
+ $uid = $this->e->user->getId();
+ $sid = $this->e->session->getId();
+
+ $service->log($msg, $type, $time, $ip, $uid, $sid);
+ }
+ }
+?>
Deleted: trunk/lib/engine/logging.lib.php
===================================================================
--- trunk/lib/engine/logging.lib.php 2007-09-16 11:28:25 UTC (rev 212)
+++ trunk/lib/engine/logging.lib.php 2007-09-17 09:14:09 UTC (rev 213)
@@ -1,149 +0,0 @@
-<?php
- /**
- *class that contains all loging functions
- */
- class Logging {
-
- var $engine; /**< varaiable for the engine */
-
- var $output = 1; /**< variable that determines where the output goes, 0 = none, 1 = file, 2 = database, 3 = both */
- var $logFile = ""; /**< determins the default log file */
- var $useAnsiColor = true; /**< determines the coloring of the logfiles true = Default colored logfiles */
-
- /**
- *assign engine variable to engine reference
- *@param engine reference
- */
- function setEngine(&$engine) {
- $this->engine =& $engine;
- }
- /**
- *assign variable for the logfile
- *@param variable to be assigned to the logFile
- */
- function setLogFile($file) {
- $this->logFile = $file;
- }
- /**
- *assign variable for the output
- *@param variable to be assigned to the output
- */
- function setOutput($output) {
- $this->output = $output;
- }
- /**
- *add message to the logfile
- *@param the message to be added
- *@param the module the message refers to
- */
- function addMessage($msg, $module = null) {
- $this->_writeLog($msg, 10, $module);
- }
- /**
- *add warning to the logfile
- *@param the warning to be added
- *@param the module the message refers to
- */
- function addWarning($msg, $module = null) {
- $this->_writeLog($msg, 20, $module);
- }
- /**
- *add error to the logfile
- *@param the error to be added
- *@param the module the message refers to
- */
- function addError($msg, $module = null) {
- $this->_writeLog($msg, 30, $module);
- }
- /**
- *write something to the logfile
- *@param message to written to logfile
- *@param integer representing the level of the message
- *@param the module the message refers to
- */
- function _writeLog($msg, $level, $module = null) {
-
- if(isset($this->engine->session)) {
- $sid = $this->engine->session->getId();
- $uid = $this->engine->session->getUid();
- $ip = $this->engine->session->getIp();
- } else {
- $sid = 0;
- $uid = 0;
- $ip = '0.0.0.0';
- }
-
- if (($this->output >> 0)%2)
- $this->_logFile($uid, $sid, $ip, $level, $module, $msg);
- if (($this->output >> 1)%2)
- $this->_logDatabase($uid, $sid, $ip, $level, $module, $msg);
- }
-
- /**
- *Log an message to the database
- *@param integer containing the id of the user
- *@param integer conatining the session id
- *@param integer unsure what it contains
- *@param integer representing the level of the message
- *@param the module the message refers to
- *@param the message
- */
- function _logDatabase($uid, $sid, $ip, $level, $module, $msg) {
-
- $sLog =& $this->engine->getService('log');
-
- $obj = array();
- $obj['module'] = $module;
- $obj['level'] = $level;
- $obj['user'] = $uid;
- $obj['session'] = $sid;
- $obj['ip'] = $ip;
- $obj['message'] = $msg;
-
- if(! $sLog->createLog($obj)) {
- //Fallback to log file
- $this->_logFile($uid, $sid, $ip, $level, $module, $msg);
- $this->_logFile($uid, $sid, $ip, 30, 'log', 'Unable to log to database');
- }
- }
-
- /**
- *write log to the database
- *@param integer containing the id of the user
- *@param integer conatining the session id
- *@param integer unsure what it contains
- *@param integer representing the level of the message
- *@param the module the message refers to
- *@param the message
- *@result returns 0 on succes and -1 on failure
- */
- function _logFile($uid, $sid, $ip, $level, $module, $msg) {
-
- if (! $this->logFile)
- return -1;
-
- if (! $file = fopen($this->logFile, 'a'))
- return -1;
-
- $message = date("Y-m-d H:i:s")." - $ip (M $module, L$level, U$uid, S$sid) - $msg\n";
-
- //Add ansi color codes
- if ($this->useAnsiColor) {
- if($level <= 10) //Messages
- $message = sprintf("\x1b[32m%s\x1b[0m",$message);
- else if($level <= 20) //Warnings
- $message = sprintf("\x1b[33m%s\x1b[0m",$message);
- else if($level <= 30) //Errors
- $message = sprintf("\x1b[31m%s\x1b[0m",$message);
- }
-
- if (! fputs($file, $message)) {
- fclose($file);
- return -1;
- }
-
- fclose($file);
- return 0;
- }
- }
-?>
Modified: trunk/lib/engine/request.lib.php
===================================================================
--- trunk/lib/engine/request.lib.php 2007-09-16 11:28:25 UTC (rev 212)
+++ trunk/lib/engine/request.lib.php 2007-09-17 09:14:09 UTC (rev 213)
@@ -157,6 +157,13 @@
return $this->webservice;
}
+ function getClientIp() {
+ return $this->clientIp;
+ }
+ function getClientAgent() {
+ return $this->clientAgent;
+ }
+
/**
* Return whether the default application was selected.
*/
Modified: trunk/lib/engine/session.lib.php
===================================================================
--- trunk/lib/engine/session.lib.php 2007-09-16 11:28:25 UTC (rev 212)
+++ trunk/lib/engine/session.lib.php 2007-09-17 09:14:09 UTC (rev 213)
@@ -31,6 +31,10 @@
function setId($id) {
$this->id = intval($id);
}
+ function getId() {
+ return $this->id;
+ }
+
function setIp($ip) {
$this->ip = $ip;
}
Modified: trunk/lib/engine/user.lib.php
===================================================================
--- trunk/lib/engine/user.lib.php 2007-09-16 11:28:25 UTC (rev 212)
+++ trunk/lib/engine/user.lib.php 2007-09-17 09:14:09 UTC (rev 213)
@@ -60,17 +60,20 @@
* @param user the user object returned by the authentication service
* @param error the error object returned by the authentication service
*/
- function _login($user, $error) {
+ function _login($username, $user, $error) {
if(is_array($user)) {
$this->_setUserProperties($user);
if($this->e->session !== null) {
$this->e->session->set('user',$user,'engine');
$this->e->session->setUid($user['id']);
$this->e->session->save();
+
+ $this->e->log->logMessage(sprintf('User \'%s\' logged in',$username));
return $user['id'];
}
return 0;
} else {
+ $this->e->log->logWarning(sprintf('Failed login attempt for username \'%s\'',$username));
$this->error = $error;
return 0;
}
@@ -105,7 +108,7 @@
$user = $service->authByCredentials($username, $password);
$error = $service->getError();
- return $this->_login($user,$error);
+ return $this->_login($username,$user,$error);
}
/**
* Log in a user based on their username and a hash of their password with a seed.
@@ -126,12 +129,15 @@
$user = $service->authByMD5($username, $seed, $hash);
$error = $service->getError();
- return $this->_login($user,$error);
+ return $this->_login($username,$user,$error);
}
/**
* Resets the user related properties and removes the user from the session
*/
function logout() {
+
+ $this->e->log->logMessage(sprintf('User \'%s\' logged out',$this->username));
+
$this->_resetUserProperties();
if($this->e->session !== null) {
$this->e->session->clear('user','engine');
Modified: trunk/mod/eis_engine/applications/servermanager.xml
===================================================================
--- trunk/mod/eis_engine/applications/servermanager.xml 2007-09-16 11:28:25 UTC (rev 212)
+++ trunk/mod/eis_engine/applications/servermanager.xml 2007-09-17 09:14:09 UTC (rev 213)
@@ -12,6 +12,11 @@
<service>FileStoreService</service>
</session_backend>
+ <log_backend>
+ <module>eis_log</module>
+ <service>FileLogService</service>
+ </log_backend>
+
<page_root>
<meta><name>menu-entry</name><value>eis_engine.l.home</value></meta>
<permission>eis_engine.administrator</permission>
Added: trunk/mod/eis_log/config/module.php
===================================================================
--- trunk/mod/eis_log/config/module.php (rev 0)
+++ trunk/mod/eis_log/config/module.php 2007-09-17 09:14:09 UTC (rev 213)
@@ -0,0 +1,4 @@
+<?php
+ $cfg['logfile_filename'] = 'message.log';
+ $cfg['logfile_ansicolor'] = true;
+?>
Added: trunk/mod/eis_log/module.xml
===================================================================
--- trunk/mod/eis_log/module.xml (rev 0)
+++ trunk/mod/eis_log/module.xml 2007-09-17 09:14:09 UTC (rev 213)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<module>
+ <name>eis_log</name>
+ <version>0.1.0</version>
+ <description>Management of EIS logs</description>
+ <author>EIS Team</author>
+ <homepage>http://eis.sourceforge.net/</homepage>
+ <license>BSD License</license>
+</module>
Added: trunk/mod/eis_log/services/FileLogService.php
===================================================================
--- trunk/mod/eis_log/services/FileLogService.php (rev 0)
+++ trunk/mod/eis_log/services/FileLogService.php 2007-09-17 09:14:09 UTC (rev 213)
@@ -0,0 +1,31 @@
+<?php
+ class eis_log_FileLogService extends LogService {
+
+ function log($message, $type, $time, $ip, $uid, $sid ) {
+
+ $logfile = $this->e->getDataDir().'/'.$this->mc['logfile_filename'];
+ $f = fopen($logfile,'a');
+
+ $message = sprintf("[%s] %s - %s (IP: %s, U: %s, S: %s)\n",
+ $type,
+ date("Y-m-d H:i:s",$time),
+ $message,
+ $ip,
+ $uid,
+ $sid);
+
+ //Add ansi color codes
+ if ($this->mc['logfile_ansicolor']) {
+ if($type == 'message')
+ $message = sprintf("\x1b[32m%s\x1b[0m",$message);
+ else if($type == 'warning')
+ $message = sprintf("\x1b[33m%s\x1b[0m",$message);
+ else if($type == 'error')
+ $message = sprintf("\x1b[31m%s\x1b[0m",$message);
+ }
+
+ fputs($f, $message);
+ fclose($f);
+ }
+ }
+?>
Deleted: trunk/mod/eis_user/elements/.UserSelectMembership.php.swp
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|