, Windows 10 ( 8.9.4), . , - :
Loading settings.json
at fs.readdirSync.filter.forEach (D:\Users\Piyin\Projects\test\settings.js:21:13)
Server is running on http://localhost:3000 or http://127.0.0.1:3000
at Server.app.listen (D:\Users\Piyin\Projects\test\index.js:67:11)
( ):
- , - ( - "
Error - , ) - ( __dirname,
D:\Users\Piyin\Projects\test). : , Javascript - Delete initial
at - Put file information in front of the actual log
- Format the information as
Class.method at path/to/file:line:column
Here:
['log','warn','error'].forEach((methodName) => {
const originalMethod = console[methodName];
console[methodName] = (...args) => {
try {
throw new Error();
} catch (error) {
originalMethod.apply(
console,
[
(
error
.stack
.split('\n')[2]
.trim()
.substring(3)
.replace(__dirname, '')
.replace(/\s\(./, ' at ')
.replace(/\)/, '')
),
'\n',
...args
]
);
}
};
});
And here is the new conclusion:
fs.readdirSync.filter.forEach at settings.js:21:13
Loading settings.json
Server.app.listen at index.js:67:11
Server is running on http://localhost:3000 or http://127.0.0.1:3000
Here is the code minimized by hand (240 bytes):
['log','warn','error'].forEach(a=>{let b=console[a];console[a]=(...c)=>{try{throw new Error}catch(d){b.apply(console,[d.stack.split('\n')[2].trim().substring(3).replace(__dirname,'').replace(/\s\(./,' at ').replace(/\)/,''),'\n',...c])}}});
Piyin source
share