Skip to content

Commit

Permalink
Merge pull request #2424 from ChurchCRM/2.7.4-log-fixes
Browse files Browse the repository at this point in the history
System Logs v2
  • Loading branch information
crossan007 authored May 1, 2017
2 parents 9339465 + 21ab3d6 commit f2216bf
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ src/ChurchCRM/model/ChurchCRM/Map
src/signatures.json
src/integrityCheck.json
src/tmp_attach
src/logs/*.log
21 changes: 18 additions & 3 deletions src/ChurchCRM/dto/SystemConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,26 @@ private static function getSupportedLocales()

}

public static function getMonoLogLevels()
{
return [
"Choices" => [
gettext("DEBUG").":100",
gettext("INFO").":200",
gettext("NOTICE").":250",
gettext("WARNING").":300",
gettext("ERROR").":400",
gettext("CRITICAL").":500",
gettext("ALERT").":550",
gettext("EMERGENCY").":600"
]
];
}

private static function buildConfigs()
{
return array(
"debug" => new ConfigItem(2, "debug", "boolean", "1", gettext("Set debug mode\r\nThis may be helpful for when you're first setting up ChurchCRM, but you should\r\nprobably turn it off for maximum security otherwise. If you are having trouble,\r\nplease enable this so that you'll know what the errors are. This is especially\r\nimportant if you need to report a problem on the help forums.")),
"sLogFile" => new ConfigItem(3, "sLogFile", "text", "/tmp/ChurchCRM.log", gettext("If debug is enabled the location of log files.")),
"sLogLevel" => new ConfigItem(4, "sLogLevel", "choice", "200", gettext("Event Log severity to write, used by ORM and App Logs"), json_encode(SystemConfig::getMonoLogLevels())),
"sDirClassifications" => new ConfigItem(5, "sDirClassifications", "text", "1,2,4,5", gettext("Include only these classifications in the directory, comma seperated")),
"sDirRoleHead" => new ConfigItem(6, "sDirRoleHead", "text", "1", gettext("These are the family role numbers designated as head of house")),
"sDirRoleSpouse" => new ConfigItem(7, "sDirRoleSpouse", "text", "2", gettext("These are the family role numbers designated as spouse")),
Expand Down Expand Up @@ -179,7 +194,7 @@ private static function buildCategories()
gettext('User setup') => ["sMinPasswordLength","sMinPasswordChange","iMaxFailedLogins","sSessionTimeout","sDisallowedPasswords"],
gettext('Email Setup') => ["sSMTPHost","sSMTPAuth","sSMTPUser","sSMTPPass", "iSMTPTimeout","sToEmailAddress","mailChimpApiKey"],
gettext('Member Setup') => ["sDirClassifications","sDirRoleHead","sDirRoleSpouse","sDirRoleChild","sDefaultCity","sDefaultState","sDefaultCountry","bShowFamilyData","bHidePersonAddress","bHideFriendDate","bHideFamilyNewsletter","bHideWeddingDate","bHideLatLon","cfgForceUppercaseZip","sEnableGravatarPhotos","sEnableSelfRegistration", "bAllowEmptyLastName", "iPersonNameStyle"],
gettext('System Settings') => ["sLastBackupTimeStamp","sExternalBackupAutoInterval","sExternalBackupPassword","sEnableExternalBackupTarget","sExternalBackupType","sExternalBackupEndpoint","sExternalBackupUsername","debug","sLogFile", "bRegistered","sXML_RPC_PATH","sGZIPname","sZIPname","sPGPname","bCSVAdminOnly","sHeader","sEnableIntegrityCheck","sIntegrityCheckInterval","sLastIntegrityCheckTimeStamp"],
gettext('System Settings') => ["sLastBackupTimeStamp","sExternalBackupAutoInterval","sExternalBackupPassword","sEnableExternalBackupTarget","sExternalBackupType","sExternalBackupEndpoint","sExternalBackupUsername","sLogLevel", "bRegistered","sXML_RPC_PATH","sGZIPname","sZIPname","sPGPname","bCSVAdminOnly","sHeader","sEnableIntegrityCheck","sIntegrityCheckInterval","sLastIntegrityCheckTimeStamp"],
gettext('Map Settings') => ["sGeoCoderProvider","sGoogleMapKey","sBingMapKey","sGMapIcons", "iMapZoom","sISTusername","sISTpassword","sGeocoderID","sGeocoderPW"],
gettext('Report Settings') => ["sQBDTSettings","leftX","incrementY","sTaxReport1","sTaxReport2","sTaxReport3","sTaxSigner","sReminder1","sReminderSigner","sReminderNoPledge","sReminderNoPayments","sConfirm1","sConfirm2","sConfirm3","sConfirm4","sConfirm5","sConfirm6","sDear","sConfirmSincerely","sConfirmSigner","sPledgeSummary1","sPledgeSummary2","sDirectoryDisclaimer1","sDirectoryDisclaimer2","bDirLetterHead","sZeroGivers","sZeroGivers2","sZeroGivers3"],
gettext('Localization') => ["sLanguage","sDistanceUnit","sPhoneFormat","sPhoneFormatWithExt","sDateFormatLong","sDateFormatNoYear","sDateFormatShort","sDateTimeFormat","sDateFilenameFormat"],
Expand Down
2 changes: 1 addition & 1 deletion src/Include/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ function RunQuery($sSQL, $bStopOnError = true)
if ($result = mysqli_query($cnInfoCentral, $sSQL)) {
return $result;
} elseif ($bStopOnError) {
if (SystemConfig::getValue('debug')) {
if (SystemConfig::getValue('sLogLevel ') == "100") { // debug level
die(gettext('Cannot execute query.')."<p>$sSQL<p>".mysqli_error());
} else {
die('Database error or invalid data');
Expand Down
29 changes: 19 additions & 10 deletions src/Include/LoadConfigs.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,25 @@ function buildConnectionManagerConfig($sSERVERNAME, $sDATABASE, $sUSER, $sPASSWO

// enable logs if we are in debug mode
// **************************************************
$logFile = SystemConfig::getValue("sLogFile");
if (SystemConfig::getBooleanValue("debug")) {
$dbClassName = "\\Propel\\Runtime\\Connection\\DebugPDO";
$manager->setConfiguration(buildConnectionManagerConfig($sSERVERNAME, $sDATABASE, $sUSER, $sPASSWORD, $dbClassName));
$logger = new Logger('defaultLogger');
$logger->pushHandler(new StreamHandler($logFile));
$serviceContainer->setLogger('defaultLogger', $logger);
ini_set('log_errors', 1);
ini_set('error_log', $logFile);
}

$logFilePrefix = SystemURLs::getDocumentRoot().'/logs/'.date("Y-m-d");
$logLevel = intval(SystemConfig::getValue("sLogLevel"));

// PHP Logs
ini_set('log_errors', 1);
ini_set('error_log', $logFilePrefix.'-php.log');

// APP Logs
$logger = new Logger('defaultLogger');
$logger->pushHandler(new StreamHandler($logFilePrefix.'-app.log', $logLevel));

// ORM Logs
$ormLogger = new Logger('ormLogger');
$dbClassName = "\\Propel\\Runtime\\Connection\\DebugPDO";
$manager->setConfiguration(buildConnectionManagerConfig($sSERVERNAME, $sDATABASE, $sUSER, $sPASSWORD, $dbClassName));
$ormLogger->pushHandler(new StreamHandler($logFilePrefix.'-orm.log', $logLevel));
$serviceContainer->setLogger('defaultLogger', $ormLogger);


if (isset($_SESSION['iUserID'])) { // Not set on Login.php
// Load user variables from user config table.
Expand Down
1 change: 1 addition & 0 deletions src/logs/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deny from all

0 comments on commit f2216bf

Please sign in to comment.