This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "FusionForge".

The branch, master has been updated
       via  c861ffded71094b933c3cd3f8e3932c2a07b8a56 (commit)
      from  b8657d955041f330c4a27559ab55c6f1b2191645 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://scm.fusionforge.org/anonscm/gitweb/?p=fusionforge/fusionforge.git;a=commitdiff;h=c861ffded71094b933c3cd3f8e3932c2a07b8a56

commit c861ffded71094b933c3cd3f8e3932c2a07b8a56
Author: Marc-Etienne Vargenau <[email protected]>
Date:   Thu Jan 12 12:13:27 2017 +0100

    New class: ForgeLog

diff --git a/src/common/include/FFError.class.php 
b/src/common/include/FFError.class.php
index 8040fc6..4132521 100644
--- a/src/common/include/FFError.class.php
+++ b/src/common/include/FFError.class.php
@@ -77,6 +77,7 @@ class FFError {
                $this->error_state=true;
                $this->error_message=$string;
                $this->error_code=$code;
+               ForgeLog::log($string, 'error');
                return false;
        }
 
diff --git a/src/common/include/ForgeLog.class.php 
b/src/common/include/ForgeLog.class.php
new file mode 100644
index 0000000..84b832d
--- /dev/null
+++ b/src/common/include/ForgeLog.class.php
@@ -0,0 +1,112 @@
+<?php
+/**
+ * FusionForge ForgeLog class file
+ *
+ * Copyright (C) 2011-2012 Alain Peyrat - Alcatel-Lucent
+ *
+ * This file is part of FusionForge. FusionForge is free software;
+ * you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the Licence, or (at your option)
+ * any later version.
+ *
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/**
+ * ForgeLog simple log class.
+ *
+ * Log events are displayed in the browser or in a logfile.
+ *
+ * Configuration example for production system (in .ini):
+ * log = error,auth
+ * log_destination = file
+ *
+ * Configuration example for development system (in .ini):
+ * log = error,auth,info,debug,sql
+ * log_destination = browser
+ *
+ * @since 5.2
+ */
+
+require_once $gfcommon.'include/FFError.class.php';
+
+class ForgeLog extends FFError
+{
+       static private $_logs = array();
+       static private $_format = "{ip} {login} [{date}] {type} \"{message}\" 
{url}\n";
+
+       /**
+        * @param string $message
+        * @param string $type
+        */
+       static public function log($message, $type='error') {
+               if (forge_get_config('log')) {
+                       if (array_intersect(explode(',', 
forge_get_config('log')), explode(',', $type))) {
+                               $date = new DateTime('now', new DateTimeZone( 
forge_get_config('default_timezone')));
+                               $user = function_exists('session_get_user')? 
session_get_user() : false;
+                               $login = $user ? $user->getUnixName() : '';
+
+                               self::$_logs[] = array(
+                                       'date'    => 
$date->format(DateTime::ISO8601),
+                                       'type'    => $type,
+                                       'ip'      => 
getStringFromServer('REMOTE_ADDR'),
+                                       'login'   => $login,
+                                       'message' => $message,
+                                       'url'     => 
getStringFromServer('REQUEST_URI')
+                               );
+                       }
+               }
+       }
+
+       static public function getLogs() {
+               return self::$_logs;
+       }
+
+       static public function getFormattedLogs($format='') {
+               if (!self::$_logs) {
+                       return '';
+               }
+               if (!$format) {
+                       $format = self::$_format;
+               }
+
+               $output = '';
+               foreach(self::$_logs as $log) {
+                       $msg = str_replace('{date}',    $log['date'], $format);
+                       $msg = str_replace('{type}',    $log['type'], $msg);
+                       $msg = str_replace('{ip}',      $log['ip'], $msg);
+                       $msg = str_replace('{login}',   $log['login'], $msg);
+                       $msg = str_replace('{message}', str_replace("\n", ' ', 
$log['message']), $msg);
+                       $msg = str_replace('{url}',     $log['url'], $msg);
+                       $output .= $msg;
+               }
+               return $output;
+       }
+
+       static public function saveLogs() {
+               if (!self::$_logs) {
+                       return;
+               }
+               if (forge_get_config('log_destination') != 'file') {
+                       return;
+               }
+               $filename = 
forge_get_config('log_path').'/forge-'.date('Ymd').'.log';
+               if (!file_exists($filename)) {
+                       touch($filename);
+                       chown($filename, forge_get_config('apache_user'));
+               }
+               $fp = fopen($filename, 'a+');
+               fwrite($fp, self::getFormattedLogs()."\n");
+               fclose($fp);
+       }
+}
+
+register_shutdown_function('ForgeLog::saveLogs');
diff --git a/src/common/include/pre.php b/src/common/include/pre.php
index a2159ce..8d51364 100644
--- a/src/common/include/pre.php
+++ b/src/common/include/pre.php
@@ -213,6 +213,7 @@ require $gfcommon.'include/constants.php';
 
 // Base error library for new objects
 require_once $gfcommon.'include/FFError.class.php';
+require_once $gfcommon.'include/ForgeLog.class.php';
 
 // Database abstraction
 // From here database is required

-----------------------------------------------------------------------

Summary of changes:
 src/common/include/FFError.class.php  |   1 +
 src/common/include/ForgeLog.class.php | 112 ++++++++++++++++++++++++++++++++++
 src/common/include/pre.php            |   1 +
 3 files changed, 114 insertions(+)
 create mode 100644 src/common/include/ForgeLog.class.php


hooks/post-receive
-- 
FusionForge

_______________________________________________
Fusionforge-commits mailing list
[email protected]
http://lists.fusionforge.org/cgi-bin/mailman/listinfo/fusionforge-commits

Reply via email to