Skip to content

Commit

Permalink
Merge branch 'main' into renovate/sinon-17.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmfg authored Jul 9, 2024
2 parents 9e0aad8 + f419420 commit 4817dd6
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 42 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "./node_modules/gts"
"extends": "./node_modules/gts",
"rules": {
"no-control-regex": 0
}
}
4 changes: 0 additions & 4 deletions .github/blunderbuss.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
assign_prs:
- HKWinterhalter

assign_issues:
- HKWinterhalter
28 changes: 15 additions & 13 deletions experimental/generate_cloud_events/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 17 additions & 4 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,24 @@ export function getModifiedData(
return data;
}
const {isJSON, processedData} = processData(data, encoding);
let dataWithContext;

let dataWithContext: {
message: string | Uint8Array;
'logging.googleapis.com/labels': {execution_id: string | undefined};
'logging.googleapis.com/trace': string | undefined;
'logging.googleapis.com/spanId': string | undefined;
severity?: string | undefined;
};
if (isJSON) {
dataWithContext = getJSONWithContext(processedData, currentContext);
if (stderr && !(SEVERITY in dataWithContext)) {
dataWithContext[SEVERITY] = 'ERROR';
}
} else {
dataWithContext = getTextWithContext(processedData, currentContext);
}
if (stderr) {
dataWithContext[SEVERITY] = 'ERROR';
if (stderr) {
dataWithContext[SEVERITY] = 'ERROR';
}
}

return JSON.stringify(dataWithContext) + '\n';
Expand Down Expand Up @@ -178,6 +188,9 @@ function processData(data: Uint8Array | string, encoding?: BufferEncoding) {
return {isJSON: false, processedData: data};
}

// strip any leading ANSI color codes from the decoded data
// to parse colored JSON objects correctly
decodedData = decodedData.replace(/\x1b[[(?);]{0,2}(;?\d)*./g, '');
try {
return {isJSON: true, processedData: JSON.parse(decodedData)};
} catch (e) {
Expand Down
8 changes: 6 additions & 2 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,13 @@ const ExecutionIdOption = new ConfigurableOption(
(typeof x === 'boolean' && x) ||
(typeof x === 'string' && x.toLowerCase() === 'true');
if (isTrue && !isVersionSatisfied) {
throw new OptionsError(
`Execution id is only supported with Node.js versions ${requiredNodeJsVersionForLogExecutionID} and above. Your current version is ${nodeVersion}. Please upgrade.`
console.warn(
`Execution id is only supported with Node.js versions
${requiredNodeJsVersionForLogExecutionID} and above. Your
current version is ${nodeVersion}. Please upgrade.`
);
console.warn('Proceeding with execution id support disabled...');
return false;
}
return isTrue;
}
Expand Down
30 changes: 30 additions & 0 deletions test/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,34 @@ describe('getModifiedData', () => {
) + '\n';
assert.equal(modifiedData, expectedOutput);
});

it('parses firebase warning severity and message', () => {
const modifiedData = <string>(
getModifiedData(
'\u001b[33m{"severity":"WARNING","message":"testing warning log level"}\u001b[39m\n',
undefined,
true
)
);
assert.equal('WARNING', JSON.parse(modifiedData)['severity']);
assert.equal(
'testing warning log level',
JSON.parse(modifiedData)['message']
);
});

it('parses firebase error severity and message', () => {
const modifiedData = <string>(
getModifiedData(
'\u001b[31m{"severity":"ERROR","message":"testing error log level"}\u001b[39m\n',
undefined,
true
)
);
assert.equal('ERROR', JSON.parse(modifiedData)['severity']);
assert.equal(
'testing error log level',
JSON.parse(modifiedData)['message']
);
});
});
6 changes: 2 additions & 4 deletions test/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,12 @@ describe('parseOptions', () => {

executionIdTestData.forEach(testCase => {
it(testCase.name, () => {
const options = parseOptions(testCase.cliOpts, testCase.envVars);
if (
semver.lt(process.versions.node, requiredNodeJsVersionForLogExecutionID)
) {
assert.throws(() => {
parseOptions(testCase.cliOpts, testCase.envVars);
});
assert.strictEqual(options.enableExecutionId, false);
} else {
const options = parseOptions(testCase.cliOpts, testCase.envVars);
assert.strictEqual(options.enableExecutionId, true);
}
});
Expand Down

0 comments on commit 4817dd6

Please sign in to comment.