Skip to content

Use the logging package for dartdoc output #1518

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

Merged
merged 3 commits into from
Oct 31, 2017
Merged

Use the logging package for dartdoc output #1518

merged 3 commits into from
Oct 31, 2017

Conversation

kevmoo
Copy link
Member

@kevmoo kevmoo commented Oct 17, 2017

No description provided.

@kevmoo kevmoo requested a review from jcollins-g October 17, 2017 00:07
@googlebot googlebot added the cla: yes Google CLA check succeeded. label Oct 17, 2017
@kevmoo kevmoo force-pushed the logging branch 2 times, most recently from f5a92cb to e921101 Compare October 17, 2017 03:31
@kevmoo
Copy link
Member Author

kevmoo commented Oct 17, 2017

Explicitly not using pkg/logging so I can send non-Strings to the listener

@jcollins-g
Copy link
Contributor

@kevmoo
Copy link
Member Author

kevmoo commented Oct 17, 2017 via email

@jcollins-g
Copy link
Contributor

I'll need more of an explanation than that. Why do you need to be able to log non-string-convertible objects?

@kevmoo
Copy link
Member Author

kevmoo commented Oct 17, 2017

The idea: push the "text or JSON" decision to the listener. When a component logs it either sends a String and/or something JSON-able.

@kevmoo
Copy link
Member Author

kevmoo commented Oct 17, 2017

@jcollins-g – thoughts?

Copy link
Contributor

@jcollins-g jcollins-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I see where you're going, but the implementation is problematic as you're basically recreating a lot of the logging module inside Dartdoc. I would prefer if you extended the logging package's class through inheritance and override its 'log' method with one more suited to your needs, or alter the logging package if you can do that in a reasonably compatible manner. Both of these options are better for our ecosystem and since this isn't an urgent issue I'd prefer that.

Another alternative is to make use of the logging module's existing support for passing closures and when you want to pass something in, wrap it in a closure that knows what to do based on dartdoc's command line flags -- convert to JSON or use ordinary string logging. This could be done with a lightweight wrapper around the logging module. I'm guessing this would be more complex than the other options when implemented though.

I'm not familiar enough with the logging module to know for sure which of those alternatives look best when implemented, but I'm pretty sure one of them will work out better in the long run.

bin/dartdoc.dart Outdated

var readme = args['sdk-readme'];
var readme = args['sdk-readme'] as String;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer: String readme = args['sdk-readme']; (or leave original)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

@@ -1,6 +1,6 @@
name: dartdoc
# Also update the `version` field in lib/dartdoc.dart.
version: 0.14.1
version: 0.14.2-dev
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add entry to changelog if you like but I prefer to avoid updating the version number for non-breaking changes until release.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think this is poor CM practice but if it is standard for Dart package development, we can do this. A better way might be to put this in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see future -dev changes made in separate PRs to make reverts easier.

But if we're going to keep this one, the version number in lib/dartdoc.dart should also change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to do a rebase cleanup...if you have no other comments

@kevmoo
Copy link
Member Author

kevmoo commented Oct 18, 2017

I'd have to write more code to extends pkg/logging classes (both Logger and LogRecord). We'd also end up with a leaky abstraction, since I'd also have to introduce my own stream of events that's separate from Logger. Or I'd have to implement Logger – and then implement all of the members...

The todo here is to make pkg/logging more extensible. In the mean time, I think this is the cleanest solution.

@kevmoo
Copy link
Member Author

kevmoo commented Oct 19, 2017

@jcollins-g – further thoughts?

@jcollins-g
Copy link
Contributor

I still don't think this is urgent enough to develop an entirely new logging module here even as a stopgap -- and I don't see it taking "more code" to extend the logging module to enable JSON logging. Whether you have a json object or not, the warnings will get transformed to a string and written out, which is what the existing logging module does. If json objects do not have a "toString()" that does that it's easy enough to add as an extension to logger.

I see no reason to introduce a second stream of events or to reimplement Logger in its entirety.

@jcollins-g jcollins-g closed this Oct 20, 2017
@kevmoo
Copy link
Member Author

kevmoo commented Oct 23, 2017

@jcollins-g – I understand logging a bit better now.

Trying again – with the logging package. PTAL

@kevmoo kevmoo reopened this Oct 23, 2017
Copy link
Contributor

@jcollins-g jcollins-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much better, thanks! Only one question of note.

@@ -1,6 +1,6 @@
name: dartdoc
# Also update the `version` field in lib/dartdoc.dart.
version: 0.14.1
version: 0.14.2-dev
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think this is poor CM practice but if it is standard for Dart package development, we can do this. A better way might be to put this in a separate PR.

@@ -145,7 +145,7 @@ void main() {
final sep = '.'; // We don't care what the path separator character is
final firstUnfoundExample = new RegExp('warning: lib${sep}example.dart: '
'@example file not found.*test_package${sep}dog${sep}food.md');
if (!result.stderr.contains(firstUnfoundExample)) {
if (!result.stdout.contains(firstUnfoundExample)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know why this is now stdout? Warning prints should go to stderr.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disagree! if dartdoc has a error/crash that should go to stderr

See https://www.jstorimer.com/blogs/workingwithcode/7766119-when-to-use-stderr-instead-of-stdout

stderr should be for diagnostics.

If I pipe the output from dartdoc to a file, I want the hints and the warnings all together.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, this interpretation doesn't follow from the intended purpose of dartdoc, which is not to generate warnings, but documentation. Given that, the warnings are diagnostic information, and should remain on stderr.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


logging.Logger.root.onRecord.listen((record) {
if (record.level == progressLevel) {
if (showProgress && stopwatch.elapsed.inMilliseconds > 250) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely makes the progress ticker less annoying.

@kevmoo
Copy link
Member Author

kevmoo commented Oct 24, 2017

I still think this is poor CM practice but if it is standard for Dart package development, we can do this. A better way might be to put this in a separate PR.

It helps one understand if the package is in a "work in progress" state. -dev means between releases. I think it's super helpful.

@kevmoo
Copy link
Member Author

kevmoo commented Oct 24, 2017

@jcollins-g PTAL

@kevmoo
Copy link
Member Author

kevmoo commented Oct 24, 2017

Fixed travis oops – I think

@@ -145,7 +145,7 @@ void main() {
final sep = '.'; // We don't care what the path separator character is
final firstUnfoundExample = new RegExp('warning: lib${sep}example.dart: '
'@example file not found.*test_package${sep}dog${sep}food.md');
if (!result.stdout.contains(firstUnfoundExample)) {
if (!result.stderr.contains(firstUnfoundExample)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcollins-g – see here – that change got reverted...

@jcollins-g jcollins-g changed the title Logging Use the logging package for dartdoc output Oct 27, 2017
@kevmoo kevmoo force-pushed the logging branch 2 times, most recently from 19c7813 to 4404f47 Compare October 27, 2017 17:52
@kevmoo
Copy link
Member Author

kevmoo commented Oct 31, 2017

Look okay, @jcollins-g ?

@kevmoo kevmoo merged commit c79c23e into master Oct 31, 2017
@kevmoo kevmoo deleted the logging branch October 31, 2017 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Google CLA check succeeded.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants