forked from winstonjs/logform
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.js
More file actions
Latest commit
39 lines (33 loc) · 1.08 KB
/
Copy patherrors.js
File metadata and controls
39 lines (33 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* eslint no-undefined: 0 */
'use strict';
constformat=require('./format');
const{LEVEL,MESSAGE}=require('triple-beam');
/*
* function errors (info)
* If the `message` property of the `info` object is an instance of `Error`,
* replace the `Error` object its own `message` property.
*
* Optionally, the Error's `stack` property can also be appended to the `info` object.
*/
module.exports=format((einfo,{ stack })=>{
if(einfoinstanceofError){
constinfo=Object.assign({},einfo,{
level: einfo.level,
[LEVEL]: einfo[LEVEL]||einfo.level,
message: einfo.message,
[MESSAGE]: einfo[MESSAGE]||einfo.message
});
if(stack)info.stack=einfo.stack;
returninfo;
}
if(!(einfo.messageinstanceofError))returneinfo;
// Assign all enumerable properties and the
// message property from the error provided.
Object.assign(einfo,einfo.message);
consterr=einfo.message;
einfo.message=err.message;
einfo[MESSAGE]=err.message;
// Assign the stack if requested.
if(stack)einfo.stack=err.stack;
returneinfo;
});