@@ -100,25 +100,27 @@ private function createLoggingJob(string $type, int $timestamp, string $line, bo
100
100
$ config = $ this ->configFactory ->get (SettingsForm::$ configName );
101
101
$ plugin_id = $ config ->get ('provider ' ) ?? SettingsForm::OS2WEB_AUDIT_DEFUALT_PROVIDER ;
102
102
103
- $ queueStorage = $ this ->entityTypeManager ->getStorage ('advancedqueue_queue ' );
104
- /** @var \Drupal\advancedqueue\Entity\Queue $queue */
105
- $ queue = $ queueStorage ->load (self ::OS2WEB_AUDIT_QUEUE_ID );
106
- $ job = Job::create (LogMessages::class, [
103
+ $ payload = [
107
104
'type ' => $ type ,
108
105
'timestamp ' => $ timestamp ,
109
106
'line ' => $ line ,
110
107
'plugin_id ' => $ plugin_id ,
111
108
'metadata ' => $ metadata ,
112
- ]) ;
109
+ ];
113
110
114
- $ queue ->enqueueJob ($ job );
111
+ try {
112
+ $ queueStorage = $ this ->entityTypeManager ->getStorage ('advancedqueue_queue ' );
113
+ /** @var \Drupal\advancedqueue\Entity\Queue $queue */
114
+ $ queue = $ queueStorage ->load (self ::OS2WEB_AUDIT_QUEUE_ID );
115
115
116
- $ logger_context = [
117
- 'job_id ' => $ job ->getId (),
118
- 'operation ' => 'log message queued ' ,
119
- ];
116
+ $ job = Job::create (LogMessages::class, $ payload );
117
+
118
+ $ queue ->enqueueJob ($ job );
119
+ }
120
+ catch (\Exception $ exception ) {
121
+ $ this ->watchdog ->get (self ::OS2WEB_AUDIT_LOGGER_CHANNEL )->error (sprintf ('Failed creating job: %s ' , $ exception ->getMessage ()), $ payload );
122
+ }
120
123
121
- $ this ->watchdog ->get (self ::OS2WEB_AUDIT_LOGGER_CHANNEL )->notice ('Added audit logging message to queue for processing. ' , $ logger_context );
122
124
}
123
125
124
126
/**
@@ -135,22 +137,17 @@ private function createLoggingJob(string $type, int $timestamp, string $line, bo
135
137
* @param array<string, string> $metadata
136
138
* Additional metadata for the log message. Default is an empty array.
137
139
*
138
- * @throws \Exception.
140
+ * @throws \Drupal\Component\Plugin\Exception\PluginException
141
+ * @throws \Drupal\os2web_audit\Exception\ConnectionException
142
+ * @throws \Drupal\os2web_audit\Exception\AuditException
139
143
*/
140
144
public function log (string $ type , int $ timestamp , string $ line , string $ plugin_id , array $ metadata = []): void {
141
145
142
146
$ configuration = $ this ->configFactory ->get (PluginSettingsForm::getConfigName ())->get ($ plugin_id );
143
147
144
- try {
145
- /** @var \Drupal\os2web_audit\Plugin\AuditLogger\AuditLoggerInterface $logger */
146
- $ logger = $ this ->loggerManager ->createInstance ($ plugin_id , $ configuration ?? []);
147
- $ logger ->log ($ type , $ timestamp , $ line , $ metadata );
148
- }
149
- catch (\Exception $ e ) {
150
- // Log (not audit log) an error and throw error in order to retry.
151
- $ this ->watchdog ->get (self ::OS2WEB_AUDIT_LOGGER_CHANNEL )->error ($ e ->getMessage ());
152
- throw $ e ;
153
- }
148
+ /** @var \Drupal\os2web_audit\Plugin\AuditLogger\AuditLoggerInterface $logger */
149
+ $ logger = $ this ->loggerManager ->createInstance ($ plugin_id , $ configuration ?? []);
150
+ $ logger ->log ($ type , $ timestamp , $ line , $ metadata );
154
151
}
155
152
156
153
}
0 commit comments