-
-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use theming-log for logging. #161
Conversation
I updated this pr based on the current |
docs/html/js/write-msg-list.js
Outdated
@@ -0,0 +1,117 @@ | |||
'use strict'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. This file is not used. I'll remove it.
docs/html/js/theme-dic.js
Outdated
params: [ | ||
{ example: 'This is a code message.' }, | ||
], | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. I mistook about items from ansi-colors
. There are more items and code
does not exist. I'll modify them.
I've modified the above two points about document. |
This is a sample: $ cat .gulp.js
module.exports = {
log: {
theme: require('./my-theme'),
messages: require('./my-msgs'),
}
};
$ cat my-theme.json
{
"ICON": "🥤",
"VERSION": "{bold: {magenta: {1}}}",
"TIMESTAMP": "{yellow: [{NOW: YYYY/MM/DD HH:mm:ss}]} ",
"DESC": "{cyan: {1}}"
}
$ cat my-msgs.json
{
"info": {
"version": "{ICON} {DESC: Gulp version}: {VERSION: {2}}\n{ICON} {DESC: CLI version}: {VERSION: {1}}"
},
"error": {
"gulpfileNotFound": "{ICON} {TIMESTAMP}{ERROR: No gulpfile found}"
}
} |
@sttk I'd like to start work on this again. I noticed the HTML files in this PR - what are those used for? |
@phated Thanks. |
@phated I created a new branch in my repository, which was based on the current master (v2.2.1), was merged with the change of this PR except https://github.com/sttk/gulp-cli/tree/use_theming-log_2 Should I update this PR with that new branch? |
@sttk Yes, please update this branch. It needed a rebase on master anyway. I hope to find time to review soon. |
@sttk would you want to include your gulp libraries inside the gulpjs organization? |
@phated I've updated!
Yeah, it's good. |
I forgot to test about #177, and did it. |
@sttk thank you! I have confirmed that gulpjs members can create and transfer repositories, so you can transfer those projects when you have time. |
@sttk are you planning to bring this up-to-date for the gulp-cli v3.0.0 release or should I plan to finish the remaining tasks without color configuration? |
@phated I'm tackling this issue. Hopefully, I'll finish this weekend. |
@sttk 👍 sounds good. I will wait for your changes. |
6265e8b
to
9034164
Compare
@phated I've completed the changes for this PR. Please review it. |
I've added handling for yargs error message. |
I've made several changes. In Addition, I've removed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for preparing this @sttk 🙏
I'm pretty concerned how much needs to change to support this feature. Is there a way we can reduce it?
var pid = chalk.magenta(child.pid); | ||
log.info('Node flags detected:', nodeFlags); | ||
log.info('Respawned to PID:', pid); | ||
log.info(msgs.info.respawn, flags.join(', '), child.pid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should not be combined, one message is about detecting node flags and one if about the respawn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that users configuring this would consider these two lines as one.
Additionally, in this way, it is also possible to either output only one line or not output both lines.
if (error) { | ||
log.warn(chalk.yellow(error.toString())); | ||
} | ||
log.warn(msgs.warn.preloadFailure, name, Boolean(error), error.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like combining the preload message failure and the error printing. Can we keep them separate?
if (error) { | ||
log.warn(chalk.yellow(error.toString())); | ||
} | ||
log.warn(msgs.warn.loaderFailure, name, Boolean(error), error.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like combining the preload message failure and the error printing. Can we keep them separate?
if (optsErr) { | ||
log.error(msgs.error.failToParseCliOpts, optsErr.message); | ||
makeHelp(parser).showHelp(console.error); | ||
exit(1); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is needed against an error process of yargs for invalid option.
For example, gulp -f
causes a yargs error because -f/—gulpfile
requires an argument. By default, yargs outputs the error message Not enough arguments following: f
, outputs help messages, and exits the program.
To control this behavior and configure these messages, I added this part and another part in lib/shared/options/parser.js
.
index.js
Outdated
var gulpVersion = env.modulePackage.version || 'Unknown'; | ||
console.log(format(theme, msgs.info.version, cliVersion, gulpVersion)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want to allow this to be configured. We ask for this specific information in our bug reports.
Anywhere we use console.log
instead of the logger we don't need to support configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. I think that's reasonable.
lib/shared/log/tasks.js
Outdated
var maxLabelWidth = 0; | ||
|
||
tree.nodes.forEach(function(node, idx, arr) { | ||
var isLast = idx === arr.length - 1; | ||
var w = createTreeLines(node, lines, opts, 1, '', isLast); | ||
maxLabelWidth = Math.max(maxLabelWidth, w || 0); | ||
maxLabelWidth = Math.max(maxLabelWidth, w || /* istanbul ignore next */ 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add this comment now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For increasing coverage. However, in the first place,|| 0
is unnecessary.
var spaces = ' '.repeat(maxLabelWidth - line.label.length) + ' '; | ||
s += spaces + line.desc; | ||
var spaces = ' '.repeat(maxLabelWidth - line.width) + ' '; | ||
log.info(line.fmt, line.bars, line.name, true, spaces, line.desc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think users will configure this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least, those colors should be configurable according to console background color.
IF: function(text) { | ||
var idx = text.indexOf('?'); | ||
var cond = text.substring(0, idx).trim(); | ||
if (cond === '' || cond === 'false') { | ||
return ''; | ||
} | ||
return text.slice(idx + 1); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do we use this? Can we avoid it?
@@ -0,0 +1,55 @@ | |||
'use strict'; | |||
|
|||
function timestamp(format) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this used for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is used to display the timestamp at the beginning of logs, similar to fancy-log.
Some users may want to append dates to timestamps, while others may not want to display the timestamp itself for specific messages like #206. There may also be users who want to change the color, as in gulpjs/gulp#2271. To meet such demands, I made displaying timestamp configurable, too.
} | ||
|
||
log[level] = themingLog(theme, log[level]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why you are doing this but I don't think I want to override the logging functions here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right! This is wrong. This code replaces global gulplog methods, affecting other plugins that use gulplog. Instead of gulplog, we should create our own logger specific to gulp-cli. To use own logger would also eliminate separate the need to consider the issue #249 (and #254).
One idea I have is to pass the namespace Symbol('gulp-cli')
to glogg to create a new logger.
--
This is a digression and a future discussion, but could we potentially resolve #72 by creating loggers by glogg with namespace by task names and plugin names and establishing rules for plugins to use it? It’s still rough idea, and I don’t have thought of specific methods yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've mistaken. Initialization of the logging functions of gulplog v1 is necessary, even so.
@phated I've modified what you pointed out except some points still under discussion. |
@phated I want to add Can I add them to this PR? |
I've implemented configurable logs with theming-log.
But it is needed js-liftoff#95 to configure logs for require flag and completion flag.