starak / node-console-stamp Goto Github PK
View Code? Open in Web Editor NEWPatch NodeJS console methods in order to add timestamp information by pattern
License: MIT License
Patch NodeJS console methods in order to add timestamp information by pattern
License: MIT License
I am getting the following error when trying to use the latest 4.0.0 version. I have even rolled back and am getting the same issue.
node_modules\chalk\source\templates.js:115
throw new Error('Found extraneous } in Chalk template literal');
^
Error: Found extraneous } in Chalk template literal
at O:\XXXXXX\node_modules\chalk\source\templates.js:115:11
at String.replace ()
at module.exports (O:\XXXXXX\node_modules\chalk\source\templates.js:105:12)
at chalkTag (O:\XXXXXX\node_modules\chalk\source\index.js:212:9)
at chalk.template (O:\XXXXXX\node_modules\chalk\source\index.js:40:38)
at msg (O:\XXXXXX\server.js:14:25)
at O:\XXXXXX\node_modules\console-stamp\lib\utils.js:49:27
at String.replace ()
at O:\XXXXXX\node_modules\console-stamp\lib\utils.js:48:29
at Array.forEach ()
Here is my actual code:
const chalk = require('chalk');
const lMap = {
//log: chalk.hex('#183e69'),
log: '',
error: 'red',
info: 'blue',
warn: 'yellow',
debug: 'cyan'
}
require('console-stamp')(console, {
format: '(#).yellow :date(yy-mm-dd HH:MM:ss.l).green (#).yellow :msg',
tokens: {
msg: ( { method, msg } ) => {
return chalk{${lMap[method] || 'reset'} ${msg}}
;
}
}
});
global.Log = console.log.bind(console);
global.ILog = console.info.bind(console);
global.WLog = console.warn.bind(console);
global.ELog = console.error.bind(console);
global.DLog = console.debug.bind(console);
Has anyone else run into this issue.
When I use console-stamp (v2) with console.error
in Node.js 12.16.2, I get the error logged inside a "log" entry:
[... timestamp ...] LOG [... timestamp ...] ERROR
etc
I assume this is because console.error
is using console.log
internally, but there must be a way round this because the documentation doesn't look like this. So what am I doing wrong?
the type says there is a default export, but runtime doesn't say so.
import console_stamp from 'console-stamp';
(without esModuleInterop)
results into runtime error:
TypeError: console_stamp_1.default is not a function
I guess either the default export is missing, or the types sohould be fixed?
Thanks a lot!
Hi,
1 vulnerability (high severity) is introduced in console-stamp:
Vulnerability CVE-2021-33623 (high severity) is detected in package trim-newlines (versions: <3.0.1,>=4.0.0 <4.0.1): https://snyk.io/vuln/SNYK-JS-TRIMNEWLINES-1298042
The above vulnerable package is referenced by console-stamp via:
[email protected] ➔ [email protected] ➔ [email protected] ➔ [email protected]
Since [email protected].* is transitively referenced by 91 downstream projects (e.g., adr-log 2.2.0 (latest version), bespoken-tools 2.4.94 (latest version), zeebe-node 1.3.2 (latest version), bespoken-batch-tester 0.10.3 (latest version), @devexperts/tools 1.0.0-alpha.14 (latest version))
If [email protected].* removes the vulnerable package from the above version, then its fixed version can help downstream users decrease their pain.
Could you help update packages in this version?
In [email protected].*, you can kindly perform the following upgrades (not crossing their major versions):
dateformat ^1.0.11 ➔ 1.0.11
;
Note:
dateformat 1.0.11 transitively depends on [email protected](a vulnerability CVE-2021-33623 patched version)
Thanks for your contributions to the npm ecosystem!
Best regards,
Paimon
Hello!
In my code I am extending the console
object with custom wrapper functions, such as console.debug()
, console.fatal()
etc.
Internally they just call console.log()
and sometimes some minor extra code.
Now, I tried adding these method names to the options.include
array, but since these function names have no levelPriority
assigned, they are not returned by the getAllowedLogFunctions()
and thus filtered out at https://github.com/starak/node-console-stamp/blob/master/main.js#L67.
Is there a way to amend these filters so that functions that are in the options.include
array are always included?
I tried to use this but it does not work. Nothing inside the file stdout.log and stderr.log
`
require('console-stamp')(console, {
format: ':date(yyyy/mm/dd HH:MM:ss.l) :label'
} );
const fs = require('fs');
const output = fs.createWriteStream('./stdout.log');
const errorOutput = fs.createWriteStream('./stderr.log');
const logger = new console.Console(output, errorOutput);
require('console-stamp')(logger, {
stdout: output,
stderr: errorOutput
});
console.log("Sad Life")
console.info("Sad Life")
console.warn("Sad Life")
console.debug("Sad Life")
console.error("Sad Life")
`
When I define:
require('console-stamp')(console, {
pattern:"dd/mm/yyyy HH:MM:ss.l",
extend:{debug:5},
include:["debug", "info", "warn", "error"],
level:"debug"
});
and use it somewhere:
console.debug('startvalue ' + s.format('HH:mm:ss,SSS') + ' is valid');
I get:
[12/02/2017 22:06:13.938] [DEBUG] /home/pi/escape/node_modules/console-stamp/main.js:153
return org.apply( con, args );
^TypeError: Cannot read property 'apply' of undefined
at Console.con.(anonymous function) [as debug] (/home/pi/escape/node_modules/console-stamp/main.js:153:23)
at generatefile (/home/pi/escape/countdowngenerator.js:82:25)
at /home/pi/escape/countdowngenerator.js:48:7
at /home/pi/escape/countdowngenerator.js:68:11
at ChildProcess.exithandler (child_process.js:202:7)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:192:7)
at maybeClose (internal/child_process.js:890:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
I use version:
pi@raspberrypi:~/escape $ npm -v console-stamp
4.1.2
pi@raspberrypi:~/escape $ node -v
v7.5.0
logger = require('node-console-stamp').console;
The dir, time, timeEnd, trace and assert functions do not have timestamps added to them.
${generatePrefix( method, config, customConsoleStream.last_msg )}
);in index.js,I think in line 32 is wrong because the arguments should inclue generatePrefix(xxx)....
just like this:
let prefix = ${generatePrefix( method, config, customConsoleStream.last_msg )}
arguments.unshift(prefix)
customConsole.log.apply( context, arguments );
i just fix it with these code .
Hello.
I'm in Italy (CET) and we currently have daylight saving, so it's UTC+2. but console-stamps seems to be ignoring that and shows time as UTC+1.
Sorry if this issue is not related to console-stamp, would appreciate if you can redirect me to the proper place.
Thanks
with the previous version, i could set the color of the type of log
Is there a way to ommit those prefixes from log?
Trying to log out a string that includes a filename and am getting:
deploy/node_modules/console-stamp/node_modules/chalk/source/templates.js:90
throw new Error(`Unknown Chalk style: ${styleName}`);
^
Error: Unknown Chalk style: csv
at buildStyle
A simple repro case to produce the above:
console.log('Test (1).csv');
Looks like chalk is picking up the (1) and trying to interpret the .csv that follows as a style.
Is there any way to disable the chalk styling?
I played a bit with colored messages and since I also still have CommonJS projects, and the latest version of chalk no longer supports CommonJS, it was not possible (without using an old chalk version) in the way that was used in your example.
I then solved it with ansis. Wouldn't that also be a good replacement for this project? ansis has a few other advantages besides CommonJS support - check out this comparison.
I could understand if you reject this, as it would probably a breaking change.
Hello,
I would like to use moment.js to get a custom timestamp. Is it possible to define a function that returns the timestamp to be used or to remove the timestamp (so that I can add a custom one with the meta-data)
Idly wondering if it's possible to optionally display different colors by type of console call, like red for error, yellowish for warning, blue for info.
Would this be a doable enhancement?
Thanks for considering it!
Him how to use node-console-stamp with the esm helper?
require('console-stamp')(myConsole, options);
turnes into:
import * from "console-stamp"
,
but how to perform console patching?
setup:
require( 'console-stamp' )( console, { format: 'HH:MM:ss' })
console.log( '123' )
result:
HH:MM:ss 123
What am I doing wrong?
The fact that you pass in a console
object somewhat implies that you can use this module without messing with any global stuff, however, it always uses process.stdout
and process.stderr
and not the streams the console
object actually uses.
It should ether use the consols own streams or (if it is not possible to get those streams) it should provide options to set them explicitly.
Thanks for your consideration!
Dear console-stamp maintainers,
Thank you for your contribution to the open-source community.
This issue was automatically created to inform you a new version (3.0.4) of console-stamp was published without a matching tag in this repo.
Our service monitors the open-source ecosystem and informs popular packages' owners in case of potentially harmful activity.
If you find this behavior legitimate, kindly close and ignore this issue. Read more
we need a way to change the timezone
ps: node seems to have problems with timezone on windows
For instance, in our cli tool, we would like to print extra with console-stamp patch info when excuting some commands. It works perfect~
[26/11/2018 15:28:47.995] [LOG] [119ms] finished jsx build
[26/11/2018 15:28:48.216] [LOG] [350ms] finished js build
however, we don't want to print the prefix when the cli tool prints a help message:
[26/11/2018 15:28:47.995] [LOG] Usage: my-cli <command> [options]
[26/11/2018 15:28:47.995] [LOG]
[26/11/2018 15:28:47.995] [LOG] Options:
[26/11/2018 15:28:47.995] [LOG] -V, --version output the version number
[26/11/2018 15:28:47.995] [LOG] -h, --help output usage information
we prefer:
Usage: my-cli <command> [options]
Options:
-V, --version output the version number
-h, --help output usage information
I am wondering how to implement this, and i tried this:
console.commonLog = console.log;
require('console-stamp')(console, options);
but it does not work.
I'd love to use this library for controlling how much logging is actually output. Is it possible to add an option similar to include
that allows you to disable functions?
If not, I'll make another package that does the same style patching, but for that to work and to maintain compatibility with your implementation I'd need the patched indicator's name to change to include the name of this package or something similar - so they can be double-patched and then unpatched.
I tried this:
require("console-stamp")(console);
It works when I run the node program from the command line, but does not work when I run the program from the VSCode debugger. In debug mode the console prints the regular message without a timestamp.
For example, you can write console.log("%s is %d years old.", "Bob", 42).
This should give you "[timestamp] Bob is 42 years old." but now you get "[timestamp] %s is %d years old. Bob 42"
I have version 3 of console-stamp
and I want to save a log file by date.
When I have everything configured ... I see that it is saved in the file (incorrectly ... I explain now why) but it does not print by console. Ideally, the two would work at the same time and the log level could be configured for each of them.
Now I explain the problem that is inside the log file ... I have console-stamp
with colors and that is what is saving me in the log
-> Console Output
Starting Script
Environment is 'development'
Connecting to database...
Timeout: 5000
Configure connection...
-> Log File
�[35m[24.03.2020 13:49:51]�[39m �[34m[INFO] �[39m �[35m[24.03.2020 13:49:51]�[39m �[34m[INFO] �[39m �[35m[24.03.2020 13:49:51]�[39m
-> Code
const fs = require('fs');
require('console-stamp')(console, {
format: ':date(dd.mm.yyyy HH:MM:ss, true).magenta :label(7)',
tokens: {
label: ( obj ) => {
const color = {
log: 'cyanBright',
error: 'red',
info: 'blue',
warn: 'yellow',
}[obj.method];
return require('chalk')`{${color || 'reset'} ${
obj.defaultTokens.label( obj )
}}`;
},
},
stdout: fs.createWriteStream(`./stderr-${new Date().getTime()}.log`),
});
colors module dependency is not available in package.json. Should be added.
without it getting error as below
Error: Cannot find module 'colors'
I have filed this issue on stack overflow (to avoid duplication) : issue
It would be cool if this could run in the browser. Then I could tee output from the Karma test runner to a txt file and process the timestamps.
What is the correct way to use this with workers? When I use both console.log
and console.error
(or console.warn
) inside a worker, the output appears to be all over the place:
[2021/07/27 12:57:37.738] [LOG] [2021/07/27 12:57:37.739] [ERROR] Log 1 from worker
[2021/07/27 12:57:37.740] [LOG] Log 2 from worker
Error 1 from worker
[2021/07/27 12:57:37.740] [ERROR] Error 2 from worker
const { Worker } = require('worker_threads')
const worker = new Worker('./test-worker.js')
require('console-stamp')(console, { format: ':date(yyyy/mm/dd HH:MM:ss.l) :label' })
console.log('Log 1 from worker')
console.error('Error 1 from worker')
console.log('Log 2 from worker')
console.error('Error 2 from worker')
I'm using Ubuntu 20.04 and node v14.15.4. Thanks!
Is there a way to color code the "label" based on if its a log or error etc..?
[Mon Jun 10 2019 19:41:18] [LOG]
[Mon Jun 10 2019 19:41:18] [ERROR]
It would be cool to see "ERROR" in red so it stands out from all the "LOG"s
I have a problem regarding the assert method.
I am using node v10 and according to the docs (https://nodejs.org/api/console.html#console_console_assert_value_message) the implementation of assert did change with v10.0.0.
The following code:
require('console-stamp')(console, { pattern: 'dd/mm/yyyy HH:MM:ss.l' });
console.assert(false, "test");
outputs:
[27/09/2018 20:34:15.680] [ASSERT][27/09/2018 20:34:15.687] [WARN] Assertion failed: test
whereas expected is something like:
[27/09/2018 20:34:15.680] [ASSERT] Assertion failed: test
Seems like assert internally calls the warn method.
Hi, Am I missing something? It seems if an exception is throw the stack trace is missing. Is there a way to include the stack trace in the case of an error?
For whatever reason I am just not getting this where is console_stamp defined?
require('console-stamp')(console, {
colors: {
stamp: 'yellow',
label: 'white',
metadata: 'green'
}
});
const output = fs.createWriteStream(`./logs/stdout.${getLogFileDate()}.log`);
const errorOutput = fs.createWriteStream(`./logs/stderr.${getLogFileDate()}.log`);
const logger = new console.Console(output, errorOutput);
console_stamp(logger, {
stdout: output,
stderr: errorOutput
});
I thought it might be from const console_stamp = require('console-stamp')
but that proved to be incorrect. I keep getting the error TypeError: console_stamp is not a function
here is the first line I inserted require('console-stamp')(console, '[HH:mm:ss.l]');
and the result is the mm was always 3 today I was wondering if it takes the month and not the minutes.
Full disclosure: the logger in question is what comes with a node-windows package that creates a Windows service.
I know. I'm sorry, too. I occasionally think fondly of when I originally set this up on an Ubuntu server...
But anyway, that piece of middleware creates separate log files based on protocol -- error and log. And unfortunately, when I use console-stamp, the timestamp portion winds up in the wrong log file.
.out.log:
[14:09:55.404] Test
[14:09:55.404] [14:09:55.419] Express server listening on port xxxx in development mode.
.err.log:
Test 2
Obviously that middle timestamp should be in the error log.
A quick glance at the source code tells me the issue is that process.stdout is being used to write timestamps; a check to use process.stderr in the event of console.error calls would fix it.
Is it even possible using your module ?
So using this module with default settings gives me time in UTC.
How can i change and get it in IST format?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.