Skip to content

Commit dc2e2bc

Browse files
Merge pull request #1048 from buildkite/fix-log-collector-date
Fix log collector date command
2 parents 9fd2e3f + 88c08fb commit dc2e2bc

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

utils/log-collector

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,16 @@ done
6969

7070
# CloudWatch stores the creationTime as milliseconds since epoch UTC.
7171
# Since macOS doesn't support calculating the time since epoch in milliseconds, we don't have perfect accuracy on this, but it should be as close to 24 hours as possible
72-
# while still being inclusive to all platforms that might run the script
72+
# We'll check to see if we're running on a macOS-based OS and adjust appropriately, otherwise use the standard date command
7373

7474
# Currently only collects the last 24h of logs, but it might be good to be able to specify a different value for this.
75-
logAge=$(date -v-1d "+%s000")
75+
76+
# check if we're running on a macOS based system, otherwise use the GNU-based date syntax
77+
if [[ $OSTYPE == 'darwin'* ]]; then
78+
logAge=$(date -v-1d "+%s000")
79+
else
80+
logAge=$(date --date="1day" "+%s000")
81+
fi
7682

7783
# Collect some information about the Lambda function and associated log groups
7884
lambdaFunction=$(aws cloudformation describe-stack-resources --stack-name "$stackName" --logical-resource-id Autoscaling --query "StackResources[*].PhysicalResourceId" --output text | sed -nr 's/.*stack\/(.*)\/.*/\1/p')
@@ -81,6 +87,7 @@ logStreams=$(aws logs describe-log-streams --log-group-name "$lambdaLogGroup" --
8187

8288
# Iterate through all of the log streams we collected from the lambda log group
8389
echo "Collecting Lambda logs for $lambdaFunction"
90+
8491
for i in $logStreams
8592
do
8693
fileName=$(echo "$i" | sed -r 's/\//-/g')

0 commit comments

Comments
 (0)