Skip to content

Commit

Permalink
Merge pull request #916 from humanmade/backport-913-to-v20-branch
Browse files Browse the repository at this point in the history
[Backport v20-branch] Flush Cavalcade Logs every job
  • Loading branch information
joehoyle authored Dec 9, 2024
2 parents bae3a88 + 594b069 commit 75f7224
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion inc/cavalcade_runner_to_cloudwatch/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function on_end_job( Worker $worker, Job $job, string $status ) {
$error_output_property->setAccessible( true );
$error_output = $error_output_property->getValue( $worker );

Cloud\get_logger( 'cavalcade', $status )->info( json_encode( [
Cloud\get_logger( 'cavalcade', $status, 1 )->info( json_encode( [
'hook' => $job->hook,
'id' => $job->id,
'site_url' => $job->get_site_url(),
Expand Down
7 changes: 5 additions & 2 deletions inc/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -1079,9 +1079,12 @@ function is_cloud() : bool {
* will not be created if it does not already exist.
* @param string $log_stream Name of the log stream. This value is used as
* provided.
* @param int $batch_size The amount of log items to buffer before flushing them.
* FLogs are automatically flushed / written out when the
* LoggerInterface is destructed. Defaults to 1000.
* @return Psr\Log\LoggerInterface
*/
function get_logger( string $log_group, string $log_stream ) : LoggerInterface {
function get_logger( string $log_group, string $log_stream, int $batch_size = 1000 ) : LoggerInterface {
// $tag_name is designed to be used with Fluent Bit and doubles as a nice
// index for storing our loggers in. Tags must be prefixed with 'app.' to be
// correctly routed by our Fluent Bit container. Fluent Bit is configured
Expand Down Expand Up @@ -1119,7 +1122,7 @@ function get_logger( string $log_group, string $log_stream ) : LoggerInterface {
Altis\get_environment_name() . '/' . $log_group,
$log_stream,
null, // log retention when creating a new group (we disable this).
1000, // how many logs to send in a single batch.
$batch_size, // how many logs to send in a single batch.
[], // tags for log group (we disable group creation).
Logger::DEBUG, // PSR log level.
true, // bubble logs through multiple handlers.
Expand Down

0 comments on commit 75f7224

Please sign in to comment.