Skip to content

Commit 0e119b3

Browse files
ryanrathjpwhite4
andauthored
PHP 8.2 Migration Prep: Logging Changes to support latest version of Monolog (#2086)
* Logging Updates to prepare for PHP 8.2 These updates are to prepare for the PHP 8.2 updates / Symfony Migration as the new version of Monolog we're updating to no longer allows us to provide arrays as messages. Thankfully the new version of Monolog does allow for classes that implement `\Stringable` to be provided as a message. To take advantage of this I created a new class called `LogOutput` that implements `\Stringable` and takes / provides as a public member variable an array. This array is used when `__toString()` is called and outputs information as we expect when logging to the console. When logging to the database we instead expect to output json_encoded data. To accomplish this I've added a new "Processor" ( right now this is just an anonymous function, in the Symfony Migration they have a class for these ) to the `CCRDBHandler` that will "enrich" the record being logged by setting a new property called 'formatted' (for the new version of Monolog) prior to CCRDBHandler writing the record to the db. The changes were originally included in the Symfony Migration PR but they don't actually require Symfony to function and will make the Symfony PR smaller. --------- Co-authored-by: Joe White <[email protected]>
1 parent 5157134 commit 0e119b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+690
-690
lines changed

background_scripts/batch_export_manager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@
8383
$logger = Log::factory('batch-export', $logConf);
8484
$logger->info('Command: ' . implode(' ', array_map('escapeshellarg', $argv)));
8585
// NOTE: "process_start_time" is needed for the log summary.
86-
$logger->notice(['message' => 'batch_export_manager start', 'process_start_time' => date('Y-m-d H:i:s')]);
86+
$logger->notice('batch_export_manager start', ['process_start_time' => date('Y-m-d H:i:s')]);
8787
$batchProcessor = new BatchProcessor($logger);
8888
$batchProcessor->setDryRun($dryRun);
8989
$batchProcessor->processRequests();
9090
// NOTE: "process_end_time" is needed for the log summary.
91-
$logger->notice(['message' => 'batch_export_manager end', 'process_end_time' => date('Y-m-d H:i:s')]);
91+
$logger->notice('batch_export_manager end', ['process_end_time' => date('Y-m-d H:i:s')]);
9292
@flock($lockFileHandle, LOCK_UN);
9393
@fclose($lockFileHandle);
9494
@unlink($lockFile);

background_scripts/report_schedule_manager.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@
6666
// =====================================================================
6767

6868
// NOTE: "process_start_time" is needed for log summary.
69-
$logger->notice(array(
70-
'message' => 'Report scheduler start',
71-
'process_start_time' => date('Y-m-d H:i:s'),
72-
));
69+
$logger->notice('Report scheduler start', ['process_start_time' => date('Y-m-d H:i:s')]);
7370

7471
$active_frequencies = getActiveFrequencies(true);
7572

@@ -90,10 +87,7 @@
9087
} catch (Exception $e) {
9188
$msg = "Failed to get user for id = {$details['user_id']}: "
9289
. $e->getMessage();
93-
$logger->err(array(
94-
'message' => $msg,
95-
'stacktrace' => $e->getTraceAsString(),
96-
));
90+
$logger->error($msg, ['stacktrace' => $e->getTraceAsString()]);
9791
continue;
9892
}
9993

@@ -121,10 +115,7 @@
121115
} catch(Exception $e) {
122116
$msg = "Error Preparing report on " . gethostname() . " {$details['report_id']}: "
123117
. $e->getMessage();
124-
$logger->err(array(
125-
'message' => $msg,
126-
'stacktrace' => $e->getTraceAsString(),
127-
));
118+
$logger->error($msg, ['stacktrace' => $e->getTraceAsString()]);
128119
}
129120

130121
if (isset($working_dir) && $working_dir != '/' && $working_dir != getcwd()) {
@@ -135,10 +126,7 @@
135126
}
136127

137128
// NOTE: "process_end_time" is needed for log summary.
138-
$logger->notice(array(
139-
'message' => 'Report scheduler end',
140-
'process_end_time' => date('Y-m-d H:i:s'),
141-
));
129+
$logger->notice('Report scheduler end', ['process_end_time' => date('Y-m-d H:i:s')]);
142130

143131
exit;
144132

bin/acl-config

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ function main()
246246

247247
$log->debug("*** Conducting Database Verification...");
248248
if (!verifyDatabase()) {
249-
$log->err("Unable to connect to the database, please check the following: \n\t - settings for 'database' in portal_settings.ini are correct.\n\t - the database identified by the 'database' section of portal_settings.ini is running, accepting connections, and that the user specified has connection privileges.");
249+
$log->error("Unable to connect to the database, please check the following: \n\t - settings for 'database' in portal_settings.ini are correct.\n\t - the database identified by the 'database' section of portal_settings.ini is running, accepting connections, and that the user specified has connection privileges.");
250250
exit(1);
251251
}
252252
$log->debug("*** Database Verification Passed!");
@@ -519,7 +519,7 @@ function processResult(iDatabase $db, $module, $moduleData, $modules)
519519
}
520520

521521
if ($modules === null) {
522-
$log->err("Unable to process $module, missing module information. Is there a $module.json file in CONF_DIR/datawarehouse.d?");
522+
$log->error("Unable to process $module, missing module information. Is there a $module.json file in CONF_DIR/datawarehouse.d?");
523523
return;
524524
}
525525

@@ -758,7 +758,7 @@ SQL;
758758
if ($updated === 1) {
759759
$log->info("[SUCCESS] Associated Module and Module Version.");
760760
} else {
761-
$log->err("[FAILURE] Unable to associate Module and Module Version.");
761+
$log->error("[FAILURE] Unable to associate Module and Module Version.");
762762
}
763763
}
764764

@@ -1836,7 +1836,7 @@ function verifyAclSetup()
18361836
$invalidSetupSections += ( ! verifyConfigData() ? 1 : 0);
18371837

18381838
if ($invalidSetupSections > 0) {
1839-
$log->err("*** Verification Failed!");
1839+
$log->error("*** Verification Failed!");
18401840
} else {
18411841
$log->notice("*** All Configuration File Verification Steps Passed!");
18421842
}
@@ -1871,7 +1871,7 @@ function verifyJsonSyntax()
18711871
$fileJson = Json::loadFile($primaryFilePath);
18721872

18731873
if (null === $fileJson) {
1874-
$log->err("[FAIL] $primaryFile in an invalid json file");
1874+
$log->error("[FAIL] $primaryFile in an invalid json file");
18751875
$inalid [] = $primaryFile;
18761876
} else {
18771877
$log->info("[SUCCESS] $primaryFile is a valid json file.");
@@ -1899,7 +1899,7 @@ function verifyJsonSyntax()
18991899
$log->info("[SUCCESS] $fileId is a valid json file.");
19001900
} catch (Exception $e) {
19011901
$reason = $e->getMessage();
1902-
$log->err("[FAIL] $fileId is not a valid json file. Reason:\n $reason");
1902+
$log->error("[FAIL] $fileId is not a valid json file. Reason:\n $reason");
19031903
$invalid [] = $filePath;
19041904
}
19051905
}
@@ -1909,7 +1909,7 @@ function verifyJsonSyntax()
19091909

19101910
$invalidCount = count($invalid);
19111911
if ($invalidCount > 0) {
1912-
$log->err("[FAIL] $invalidCount invalid files found");
1912+
$log->error("[FAIL] $invalidCount invalid files found");
19131913
return false;
19141914
} else {
19151915
$log->info("[SUCCESS] all files valid");
@@ -1957,7 +1957,7 @@ function syncTableData(iDatabase $db, array $tables)
19571957

19581958
$committed = $db->commit();
19591959
if ($committed === false) {
1960-
$log->crit("[FAIL] Attempt to commit staging data to production tables has failed. Rollback has been initiated");
1960+
$log->critical("[FAIL] Attempt to commit staging data to production tables has failed. Rollback has been initiated");
19611961
$rolledBack = $db->rollBack();
19621962

19631963
// We throw an Exception so that we do not leave the db in an inconsistent state.
@@ -1992,14 +1992,14 @@ function verifyConfigData()
19921992
\Configuration\XdmodConfiguration::assocArrayFactory("$section.json", CONFIG_DIR);
19931993
$log->info("[SUCCESS] $section loaded successfully.");
19941994
} catch (Exception $e) {
1995-
$log->err(sprintf('[FAIL] Unable to load section %s: %s', $section, $e->getMessage()));
1995+
$log->error(sprintf('[FAIL] Unable to load section %s: %s', $section, $e->getMessage()));
19961996
$invalid[] = $section;
19971997
}
19981998
}
19991999

20002000
$invalidCount = count($invalid);
20012001
if ($invalidCount > 0) {
2002-
$log->err("[FAIL] $invalidCount invalid sections found");
2002+
$log->error("[FAIL] $invalidCount invalid sections found");
20032003
return false;
20042004
} else {
20052005
$log->info("[SUCCESS] all sections valid");

bin/xdmod-admin

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ function main()
157157
$logger->info("Command: $cmd");
158158

159159
if ($entity === null) {
160-
$logger->crit('No entity type specified');
160+
$logger->critical('No entity type specified');
161161
exit(1);
162162
}
163163

164164
if ($action === null) {
165-
$logger->crit('No action specified');
165+
$logger->critical('No action specified');
166166
exit(1);
167167
}
168168

@@ -173,7 +173,7 @@ function main()
173173
listResources();
174174
break;
175175
default:
176-
$logger->crit("Cannot perform '$action' on '$entity'");
176+
$logger->critical("Cannot perform '$action' on '$entity'");
177177
exit(1);
178178
break;
179179
}
@@ -184,13 +184,13 @@ function main()
184184
truncateJobs();
185185
break;
186186
default:
187-
$logger->crit("Cannot perform '$action' on '$entity'");
187+
$logger->critical("Cannot perform '$action' on '$entity'");
188188
exit(1);
189189
break;
190190
}
191191
break;
192192
default:
193-
$logger->crit("Unknown entity type '$entity'");
193+
$logger->critical("Unknown entity type '$entity'");
194194
exit(1);
195195
break;
196196
}

bin/xdmod-build-filter-lists

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ function build($realms, $logger){
9696
$filterListBuilder->buildAllLists();
9797
}
9898
} catch (Exception $e) {
99-
$logger->crit(array(
100-
'message' => 'Filter list building failed: ' . $e->getMessage(),
101-
'stacktrace' => $e->getTraceAsString(),
102-
));
99+
$logger->critical('Filter list building failed: ' . $e->getMessage(), ['stacktrace' => $e->getTraceAsString()]);
103100
exit(1);
104101
}
105102
}

bin/xdmod-convert-innodb-fpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ function export_innodb_tables() {
208208
global $logger, $db, $directory, $file_suffix;
209209

210210
if ( $directory === null) {
211-
$logger->crit("You must specify the directory export the tables too using the ---dir flag");
211+
$logger->critical("You must specify the directory export the tables too using the ---dir flag");
212212
return;
213213
}
214214

@@ -286,7 +286,7 @@ function import_innodb_tables() {
286286
global $logger, $db, $directory, $file_suffix, $file_suffix_length;
287287

288288
if ( $directory === null) {
289-
$logger->crit("You must specify the directory export the tables too using the ---dir flag");
289+
$logger->critical("You must specify the directory export the tables too using the ---dir flag");
290290
return;
291291
}
292292

0 commit comments

Comments
 (0)