Skip to content

Commit

Permalink
fix(jsontransport): refactor and simplify transport (UMAprotocol#2506)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismaree authored Feb 5, 2021
1 parent ac96ad1 commit 9a42531
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions packages/financial-templates-lib/src/logger/JsonTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@ function createJsonTransport() {
printf(info => {
let { timestamp, level, error, ...args } = info;
if (error) {
// If there is an error then convert it from a Javascript error object into a json object. Json.stringify is
// used to remove the javascript error notation with message and sack and convert it to a key-value paired object.
error = JSON.parse(
JSON.stringify(
error
.replace(/\r?\n|\r/g, "")
.replace(/\s\s+/g, " ") // Remove tabbed chars.
.replace(/\\"/g, ""), // Remove escaped quotes.
Object.getOwnPropertyNames(error) // Turn the json object into a parsable structure.
)
);
// If there is an error then strip out all punctuation to make it easily consumable by GCP within a log json
// object. Note this error object is assumed to be a string, converted within Logger.js that uses this transport.
error = error
.toString()
.replace(/\r?\n|\r/g, "")
.replace(/\s\s+/g, " ") // Remove tabbed chars.
.replace(/\\"/g, ""); // Remove escaped quotes.

info = { timestamp, level, error, ...args };
}
Expand Down

0 comments on commit 9a42531

Please sign in to comment.