Skip to content

Use theming-log for logging. - #161

Closed
sttk wants to merge 10 commits into
gulpjs:masterfrom
sttk:use_theming-log
Closed

Use theming-log for logging.#161
sttk wants to merge 10 commits into
gulpjs:masterfrom
sttk:use_theming-log

Conversation

@sttk

@sttk sttk commented Apr 16, 2018

Copy link
Copy Markdown
Contributor

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

sttk commented Jun 10, 2019

Copy link
Copy Markdown
Contributor Author

I updated this pr based on the current master branch.

Comment thread docs/html/js/write-msg-list.js Outdated
@@ -0,0 +1,117 @@
'use strict';

Copy link
Copy Markdown
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.

Comment thread docs/html/js/theme-dic.js Outdated
params: [
{ example: 'This is a code message.' },
],
},

@sttk sttk Jun 10, 2019

Copy link
Copy Markdown
Contributor Author

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

sttk commented Jun 12, 2019

Copy link
Copy Markdown
Contributor Author

I've modified the above two points about document.

@sttk

sttk commented Jun 12, 2019

Copy link
Copy Markdown
Contributor Author

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

phated commented May 20, 2020

Copy link
Copy Markdown
Member

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

@sttk

sttk commented May 20, 2020

Copy link
Copy Markdown
Contributor Author

@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

sttk commented May 20, 2020

Copy link
Copy Markdown
Contributor Author

@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

phated commented May 20, 2020

Copy link
Copy Markdown
Member

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

I hope to find time to review soon.

@phated

phated commented May 20, 2020

Copy link
Copy Markdown
Member

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

@sttk

sttk commented May 20, 2020

Copy link
Copy Markdown
Contributor Author

@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

sttk commented May 21, 2020

Copy link
Copy Markdown
Contributor Author

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

@phated

phated commented May 21, 2020

Copy link
Copy Markdown
Member

@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 commented Jan 7, 2024

Copy link
Copy Markdown
Member

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

@phated

phated commented Feb 7, 2024

Copy link
Copy Markdown
Member

@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

sttk commented Feb 8, 2024

Copy link
Copy Markdown
Contributor Author

@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

phated commented Feb 9, 2024

Copy link
Copy Markdown
Member

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

@sttk

sttk commented Feb 12, 2024

Copy link
Copy Markdown
Contributor Author

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

@sttk

sttk commented Feb 12, 2024

Copy link
Copy Markdown
Contributor Author

I've added handling for yargs error message.

@sttk

sttk commented Feb 12, 2024

Copy link
Copy Markdown
Contributor Author

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

@phated phated left a comment

Copy link
Copy Markdown
Member

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?

Comment thread index.js
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
Copy Markdown
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
Copy Markdown
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.

Comment thread index.js
if (error) {
log.warn(chalk.yellow(error.toString()));
}
log.warn(msgs.warn.preloadFailure, name, Boolean(error), error.toString());

Copy link
Copy Markdown
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 thread index.js
if (error) {
log.warn(chalk.yellow(error.toString()));
}
log.warn(msgs.warn.loaderFailure, name, Boolean(error), error.toString());

Copy link
Copy Markdown
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 thread index.js
Comment on lines +127 to +131
if (optsErr) {
log.error(msgs.error.failToParseCliOpts, optsErr.message);
makeHelp(parser).showHelp(console.error);
exit(1);
}

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread 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
Copy Markdown
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
Copy Markdown
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.

Comment thread lib/shared/log/tasks.js Outdated
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
Copy Markdown
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
Copy Markdown
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.

Comment thread lib/shared/log/tasks.js
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
Copy Markdown
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
Copy Markdown
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 thread lib/shared/log/theme.js
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.on(level, consoleLog);
}

log[level] = themingLog(theme, log[level]);

Copy link
Copy Markdown
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.

@sttk sttk Feb 17, 2024

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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

sttk commented Feb 17, 2024

Copy link
Copy Markdown
Contributor Author

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

@sttk

sttk commented Mar 6, 2024

Copy link
Copy Markdown
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants