-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
log template messages and errors (#4856)
* log.error accepting multiple arguments * clean up * warn, info, debug methods * Update packages/dd-trace/src/log/writer.js Co-authored-by: Attila Szegedi <szegedi@users.noreply.github.com> * attila suggestion * include error type in the telemetry log * remove optional chaining to work in node 12 * remove optional chainingand ?? to work in node 12 --------- Co-authored-by: Attila Szegedi <szegedi@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
173 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict' | ||
|
||
const { format } = require('util') | ||
|
||
class Log { | ||
constructor (message, args, cause, delegate) { | ||
this.message = message | ||
this.args = args | ||
this.cause = cause | ||
this.delegate = delegate | ||
} | ||
|
||
get formatted () { | ||
const { message, args } = this | ||
|
||
let formatted = message | ||
if (message && args && args.length) { | ||
formatted = format(message, ...args) | ||
} | ||
return formatted | ||
} | ||
|
||
static parse (...args) { | ||
let message, cause, delegate | ||
|
||
const lastArg = args[args.length - 1] | ||
if (lastArg && typeof lastArg === 'object' && lastArg.stack) { // lastArg instanceof Error? | ||
cause = args.pop() | ||
} | ||
|
||
const firstArg = args.shift() | ||
if (firstArg) { | ||
if (typeof firstArg === 'string') { | ||
message = firstArg | ||
} else if (typeof firstArg === 'object') { | ||
message = String(firstArg.message || firstArg) | ||
} else if (typeof firstArg === 'function') { | ||
delegate = firstArg | ||
} else { | ||
message = String(firstArg) | ||
} | ||
} else if (!cause) { | ||
message = String(firstArg) | ||
} | ||
|
||
return new Log(message, args, cause, delegate) | ||
} | ||
} | ||
|
||
module.exports = { | ||
Log | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters