Skip to content
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

Closed
wants to merge 10 commits into from
Closed

Conversation

sttk
Copy link
Contributor

@sttk sttk commented Apr 16, 2018

I've implemented configurable logs with theming-log.

But it is needed js-liftoff#95 to configure logs for require flag and completion flag.

@sttk
Copy link
Contributor Author

sttk commented Jun 10, 2019

I updated this pr based on the current master branch.

@@ -0,0 +1,117 @@
'use strict';
Copy link
Contributor Author

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.

params: [
{ example: 'This is a code message.' },
],
},
Copy link
Contributor Author

@sttk sttk Jun 10, 2019

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.

@sttk
Copy link
Contributor Author

sttk commented Jun 12, 2019

I've modified the above two points about document.

@sttk
Copy link
Contributor Author

sttk commented Jun 12, 2019

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}"
  }
}

gulp_theming_log

@phated
Copy link
Member

phated commented May 20, 2020

@sttk I'd like to start work on this again. I noticed the HTML files in this PR - what are those used for?

@sttk
Copy link
Contributor Author

sttk commented May 20, 2020

@phated Thanks.
HTML files (and other files in docs/html) are sample documents to configure themes and messages. It's not necessary and use as refernece of Gulp document.

@sttk
Copy link
Contributor Author

sttk commented May 20, 2020

@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 doc/html, and was modified for #177.

https://github.com/sttk/gulp-cli/tree/use_theming-log_2

Should I update this PR with that new branch?

@phated
Copy link
Member

phated commented May 20, 2020

@sttk Yes, please update this branch. It needed a rebase on master anyway.

I hope to find time to review soon.

@phated
Copy link
Member

phated commented May 20, 2020

@sttk would you want to include your gulp libraries inside the gulpjs organization?

@sttk
Copy link
Contributor Author

sttk commented May 20, 2020

@phated I've updated!

would you want to include your gulp libraries inside the gulpjs organization?

Yeah, it's good.
I'd like to include copy-props, each-props and theming-log into gulp organization.

@sttk
Copy link
Contributor Author

sttk commented May 21, 2020

I forgot to test about #177, and did it.

@phated
Copy link
Member

phated commented May 21, 2020

@sttk thank you! I have confirmed that gulpjs members can create and transfer repositories, so you can transfer those projects when you have time.

@phated phated self-requested a review October 21, 2020 21:52
@phated phated removed this from In Progress in v4 Oct 21, 2020
@phated phated added this to In progress in v5 Oct 21, 2020
@phated
Copy link
Member

phated commented Jan 7, 2024

@sttk I believe this needs conflicts resolved since I merged #239

@phated
Copy link
Member

phated commented Feb 7, 2024

@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?

@sttk
Copy link
Contributor Author

sttk commented Feb 8, 2024

@phated I'm tackling this issue. Hopefully, I'll finish this weekend.
I hope to include this feature into gulp-cli v3.0.0. Please give me a little more time.

https://github.com/sttk/gulp-cli/commits/ci-test/

@phated
Copy link
Member

phated commented Feb 9, 2024

@sttk 👍 sounds good. I will wait for your changes.

@sttk
Copy link
Contributor Author

sttk commented Feb 12, 2024

@phated I've completed the changes for this PR. Please review it.

@sttk
Copy link
Contributor Author

sttk commented Feb 12, 2024

I've added handling for yargs error message.

@sttk
Copy link
Contributor Author

sttk commented Feb 12, 2024

I've made several changes. In Addition, I've removed config.description as its purpose overlaps with config.log.msgs.tasks/tasksJson.description.

Copy link
Member

@phated phated left a 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);
Copy link
Member

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.

Copy link
Contributor Author

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());
Copy link
Member

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());
Copy link
Member

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?

Comment on lines +127 to +131
if (optsErr) {
log.error(msgs.error.failToParseCliOpts, optsErr.message);
makeHelp(parser).showHelp(console.error);
exit(1);
}
Copy link
Member

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?

Copy link
Contributor Author

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
Comment on lines 139 to 140
var gulpVersion = env.modulePackage.version || 'Unknown';
console.log(format(theme, msgs.info.version, cliVersion, gulpVersion));
Copy link
Member

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.

Copy link
Contributor Author

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.

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);
Copy link
Member

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?

Copy link
Contributor Author

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);
Copy link
Member

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?

Copy link
Contributor Author

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.

Comment on lines +37 to +44
IF: function(text) {
var idx = text.indexOf('?');
var cond = text.substring(0, idx).trim();
if (cond === '' || cond === 'false') {
return '';
}
return text.slice(idx + 1);
},
Copy link
Member

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) {
Copy link
Member

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?

Copy link
Contributor Author

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]);
Copy link
Member

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.

Copy link
Contributor Author

@sttk sttk Feb 17, 2024

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.

Copy link
Contributor Author

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.

@sttk
Copy link
Contributor Author

sttk commented Feb 17, 2024

@phated I've modified what you pointed out except some points still under discussion.

@sttk
Copy link
Contributor Author

sttk commented Mar 6, 2024

@phated I want to add --no-theme cli flag and flags.noTheme config flag that are not to use log theme and messages in a config file. I believe they could be useful when reporting issues or when not using the theme specified in the project.

Can I add them to this PR?

@phated phated closed this in #260 Mar 23, 2024
@phated phated moved this from In progress to Done in v5 Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
v5
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants