Skip to content

Commit

Permalink
refactor: Replace internal old logging utils with modern interface
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Dec 23, 2021
1 parent 0de3bc3 commit 5a451ad
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 61 deletions.
7 changes: 0 additions & 7 deletions lib/utils/log/consoleLog.js

This file was deleted.

12 changes: 0 additions & 12 deletions lib/utils/log/fileLog.js

This file was deleted.

14 changes: 0 additions & 14 deletions lib/utils/log/log.js

This file was deleted.

11 changes: 0 additions & 11 deletions lib/utils/log/serverlessLog.js

This file was deleted.

28 changes: 19 additions & 9 deletions lib/utils/telemetry/index.js
Expand Up @@ -8,10 +8,12 @@ const fetch = require('node-fetch');
const fse = require('fs-extra');
const fsp = require('fs').promises;
const telemetryUrl = require('@serverless/utils/analytics-and-notfications-url');
const log = require('../log/serverlessLog');
const { legacy, log } = require('@serverless/utils/log');
const isTelemetryDisabled = require('./areDisabled');
const cacheDirPath = require('./cache-path');

const debugLog = log.get('telemetry');

const timestampWeekBefore = Date.now() - 1000 * 60 * 60 * 24 * 7;

const isUuid = RegExp.prototype.test.bind(
Expand All @@ -21,8 +23,9 @@ const isUuid = RegExp.prototype.test.bind(
let serverlessRunEndTime;

const logError = (type, error) => {
debugLog('User stats error: %s: %O', type, error);
if (!process.env.SLS_STATS_DEBUG) return;
log(format('User stats error: %s: %O', type, error));
legacy.log(format('User stats error: %s: %O', type, error));
};

const markServerlessRunEnd = () => (serverlessRunEndTime = Date.now());
Expand All @@ -38,14 +41,21 @@ const processResponseBody = async (response, ids, startTime) => {
}

const endTime = Date.now();
if (serverlessRunEndTime && process.env.SLS_STATS_DEBUG) {
log(
format(
'Stats request prevented process from exiting for %dms (request time: %dms)',
endTime - serverlessRunEndTime,
endTime - startTime
)
if (serverlessRunEndTime) {
debugLog(
'Stats request prevented process from exiting for %dms (request time: %dms)',
endTime - serverlessRunEndTime,
endTime - startTime
);
if (process.env.SLS_STATS_DEBUG) {
legacy.log(
format(
'Stats request prevented process from exiting for %dms (request time: %dms)',
endTime - serverlessRunEndTime,
endTime - startTime
)
);
}
}
return result;
};
Expand Down
13 changes: 5 additions & 8 deletions lib/utils/yamlAstParser.js
Expand Up @@ -5,8 +5,7 @@ const BbPromise = require('bluebird');
const fs = BbPromise.promisifyAll(require('fs'));
const _ = require('lodash');
const os = require('os');
const chalk = require('chalk');
const log = require('./log/serverlessLog');
const { legacy, log } = require('@serverless/utils/log');

const findKeyChain = (astContent) => {
let content = astContent;
Expand All @@ -25,12 +24,10 @@ const parseAST = (ymlAstContent, astObject) => {
if (ymlAstContent.mappings && Array.isArray(ymlAstContent.mappings)) {
ymlAstContent.mappings.forEach((v) => {
if (!v.value) {
const errorMessage = [
'Serverless: ',
`${chalk.red('Your serverless.yml has an invalid value with key:')} `,
`${chalk.red(`"${v.key.value}"`)}`,
].join('');
log(errorMessage);
legacy.log(`Your serverless.yml has an invalid value with key: "${v.key.value}"`, {
color: 'red',
});
log.error(`Your serverless.yml has an invalid value with key: "${v.key.value}"`);
return;
}

Expand Down

0 comments on commit 5a451ad

Please sign in to comment.