Skip to content

Commit aa5b1ee

Browse files
committed
feat: inject log instance into SQS class and update logging methods to use it
1 parent b413290 commit aa5b1ee

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

packages/serverless-offline-sqs/src/index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ const {
1212
toPairs
1313
} = require('lodash/fp');
1414

15-
const log = require('@serverless/utils/log').log;
16-
1715
const SQS = require('./sqs');
1816

1917
const OFFLINE_OPTION = 'serverless-offline';
@@ -32,12 +30,13 @@ const defaultOptions = {
3230
const omitUndefined = omitBy(isUndefined);
3331

3432
class ServerlessOfflineSQS {
35-
constructor(serverless, cliOptions) {
33+
constructor(serverless, cliOptions, { log }) {
3634
this.cliOptions = null;
3735
this.options = null;
3836
this.sqs = null;
3937
this.lambda = null;
4038
this.serverless = null;
39+
this.log = log;
4140

4241
this.cliOptions = cliOptions;
4342
this.serverless = serverless;
@@ -67,7 +66,7 @@ class ServerlessOfflineSQS {
6766

6867
await Promise.all(eventModules);
6968

70-
this.serverless.cli.log(
69+
this.log.notice(
7170
`Starting Offline SQS at stage ${this.options.stage} (${this.options.region})`
7271
);
7372
}
@@ -83,7 +82,7 @@ class ServerlessOfflineSQS {
8382

8483
signals.map(signal =>
8584
process.on(signal, async () => {
86-
this.serverless.cli.log(`Got ${signal} signal. Offline Halting...`);
85+
this.log.notice(`Got ${signal} signal. Offline Halting...`);
8786

8887
await this.end();
8988
})
@@ -100,7 +99,7 @@ class ServerlessOfflineSQS {
10099
return;
101100
}
102101

103-
this.serverless.cli.log('Halting offline server');
102+
this.log.notice('Halting offline server');
104103

105104
const eventModules = [];
106105

@@ -129,7 +128,7 @@ class ServerlessOfflineSQS {
129128
async _createSqs(events, skipStart) {
130129
const resources = this._getResources();
131130

132-
this.sqs = new SQS(this.lambda, resources, this.options);
131+
this.sqs = new SQS(this.lambda, resources, this.options, this.log);
133132

134133
await this.sqs.create(events);
135134

@@ -155,7 +154,7 @@ class ServerlessOfflineSQS {
155154
omitUndefined(this.cliOptions)
156155
);
157156

158-
log.debug('options:', this.options);
157+
this.log.debug('options:', this.options);
159158
}
160159

161160
_getEvents() {

packages/serverless-offline-sqs/src/sqs.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const {
1111
toString,
1212
values
1313
} = require('lodash/fp');
14-
const log = require('@serverless/utils/log').log;
1514
const {default: PQueue} = require('p-queue');
1615
const SQSEventDefinition = require('./sqs-event-definition');
1716
const SQSEvent = require('./sqs-event');
@@ -22,10 +21,11 @@ const delay = timeout =>
2221
});
2322

2423
class SQS {
25-
constructor(lambda, resources, options) {
24+
constructor(lambda, resources, options, log) {
2625
this.lambda = null;
2726
this.resources = null;
2827
this.options = null;
28+
this.log = log;
2929

3030
this.lambda = lambda;
3131
this.resources = resources;
@@ -138,7 +138,7 @@ class SQS {
138138
)
139139
);
140140
} catch (err) {
141-
log.warning(err.stack);
141+
this.log.warning(err.stack);
142142
}
143143
}
144144

@@ -170,7 +170,7 @@ class SQS {
170170
} catch (err) {
171171
if (remainingTry > 0 && err.name === 'AWS.SimpleQueueService.NonExistentQueue')
172172
return this._createQueue({queueName}, remainingTry - 1);
173-
log.warning(err.stack);
173+
this.log.warning(err.stack);
174174
}
175175
}
176176
}

0 commit comments

Comments
 (0)