Skip to content

Commit

Permalink
Log all errors on the command line to /var/log/statusengine.log
Browse files Browse the repository at this point in the history
  • Loading branch information
nook24 committed Jan 13, 2016
1 parent b0bbaf0 commit 1e7b44b
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cakephp/app/Config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@
'file' => 'error',
));

App::uses('AppError', 'Lib');

CakePlugin::load('Legacy', array('bootstrap' => false, 'routes' => false));
CakePlugin::loadAll();
CakePlugin::load('BoostCake');
Expand Down
15 changes: 15 additions & 0 deletions cakephp/app/Config/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,18 @@
'serialize' => ($engine === 'File'),
'duration' => $duration
));

//Configure::write('Error.consoleHandler', 'AppError::handleError');

Configure::write('Error', array(
'consoleHandler' => 'AppError::handleError',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
));

Configure::write('Exception', array(
'consoleHandler' => 'AppError::handleException',
'renderer' => 'ExceptionRenderer',
'log' => true
));

78 changes: 78 additions & 0 deletions cakephp/app/Lib/AppError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**********************************************************************************
*
* #####
* # # ##### ## ##### # # #### ###### # # #### # # # ######
* # # # # # # # # # ## # # # # ## # #
* ##### # # # # # # #### ##### # # # # # # # # #####
* # # ###### # # # # # # # # # ### # # # # #
* # # # # # # # # # # # # ## # # # # ## #
* ##### # # # # #### #### ###### # # #### # # # ######
*
* the missing event broker
*
* --------------------------------------------------------------------------------
*
* Copyright (c) 2014 - present Daniel Ziegler <daniel@statusengine.org>
*
* This program 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 in version 2
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* --------------------------------------------------------------------------------
*
* Statusengine CLI Error handler to log Errors and Exception to Statusengine's
* core log file defined in app/Config/Statusengine.php
*
**********************************************************************************/
class AppError{

/** @var string path to the logfile */
public static $logfile = '';

/** @var ressource of the logile */
public static $loghandle = null;

public static function handleError($code, $description, $file = null,$line = null, $context = null){
if(!is_resource(self::$loghandle)){
self::openLog();
}

fwrite(self::$loghandle, 'Error: '.$code.PHP_EOL);
fwrite(self::$loghandle, $description.PHP_EOL);
fwrite(self::$loghandle, 'File: '.$file);
fwrite(self::$loghandle, ' Line: '.$line.PHP_EOL);

if(is_array($context) || is_object($context)){
fwrite(self::$loghandle, var_export($context, true));
return;
}

fwrite(self::$loghandle, $context.PHP_EOL);
}

public static function handleException($error){
if(!is_resource(self::$loghandle)){
self::openLog();
}
fwrite(self::$loghandle, $error);
}

public static function openLog(){
if(self::$logfile == ''){
Configure::load('Statusengine');
self::$logfile = Configure::read('logfile');
}
self::$loghandle = fopen(self::$logfile, 'a+');
}
}

2 changes: 1 addition & 1 deletion etc/init.d/statusengine
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fi
case $1 in
start)
echo "Starting Statusengine"
start-stop-daemon --start --pidfile $PIDFILE --make-pidfile --background --exec $DAEMON --chuid root:www-data -- $DAEMON_OPTS
start-stop-daemon --start --pidfile $PIDFILE --make-pidfile --background --startas $DAEMON --chuid root:www-data -- $DAEMON_OPTS
;;

stop)
Expand Down

0 comments on commit 1e7b44b

Please sign in to comment.