Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System Logs v2 #2424

Merged
merged 12 commits into from
May 1, 2017
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe make this write to the log instead of die()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, if DEBUG is set, all queries should be logged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm that is now outside MVP... the goal of this PR is to ensure we don't crash... please open a issue to track it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http://propelorm.org/documentation/07-logging.html

You can also disable the debug mode at runtime, by calling PropelPDO::useDebug(false). Using this method, you can choose to enable the debug mode for only one particular query, or for all queries.

Alternatively, you can ask Propel to always enable the debug mode for a particular connection by using the Propel\Runtime\Connection\DebugPDO class instead of the default ConnectionWrapper class. This is accomplished in the configuration file, in the classname node of a given datasource connection (see the configuration reference for more details).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again please open an issue to track, the goal was not to crash the system

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$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