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 the Asciidoctor logger from a Java Extension #737

Closed
jmini opened this issue Nov 26, 2018 · 7 comments · Fixed by #755
Closed

Use the Asciidoctor logger from a Java Extension #737

jmini opened this issue Nov 26, 2018 · 7 comments · Fixed by #755

Comments

@jmini
Copy link
Contributor

jmini commented Nov 26, 2018

With asciidoctor/asciidoctor#44 a proper logger infrastructure has been added to Asciidoctor (ruby).

The logs can be accessed in AsciidoctorJ:
https://github.com/asciidoctor/asciidoctorj#logs-handling-api

AciidoctorJ (v1.5.7+) offers the possibility to capture messages generated during document rendering

I was wondering if the AsciidoctorJ extension I am writing can access the Logger and add an entry.

Quoting @robertpanzer:

While it's possible to receive the log entries that Asciidoctor logs, it's not possible yet for an extension to log using the same Logger that Asciidoctor is using.
I agree that it would make sense to expose this to extensions as well.

@abelsromero
Copy link
Member

I am curios about the use case, to see how best approach this.

@mojavelinux
Copy link
Member

From the Ruby side, the design is to simply include the Asciidoctor::Logging module into any class. For example, here's how it's done in Asciidoctor PDF (ignore the shim logic).

https://github.com/asciidoctor/asciidoctor-pdf/blob/db8d3bf3a58103d178901de4fac6977fa50aa1d2/lib/asciidoctor-pdf/converter.rb#L33

I'm not sure what the equivalent would be in Java.

@robertpanzer
Copy link
Member

I am curios about the use case, to see how best approach this.

If logged warnings let the build fail in the asciidoctor-maven-plugin it would be just logical for me that an extension should also be able to emit such warnings.
Besides extensions converters should be able to log too.
Just like Ruby code, Java code should be able to do the same.

@abelsromero
Copy link
Member

But the maven plugin captures logs messages. Here we are talking about publishing, I see this as a different thing.
Publishing totally makes sense, but either we have a 'getLogger()' in the extensions API or a static 'AsciidoctorLogger.gerLogger()'. At least that keeps things independent, which is aligned with the current efforts.

@robertpanzer
Copy link
Member

Yes, that’s exactly what I meant.
Offer sth like a getLogger() method in the extension (and converter) API.

I wonder if there’s a use case to pipe the log records through the ruby runtime or if these could just directly enter the java part.

@jmini
Copy link
Contributor Author

jmini commented Nov 26, 2018

getLogger() is exactly something I would expect.

Personally I do not care if I get the same logger than the ruby one or if this is a pure Java implementation.

As long as the warning I log in my extension go in the same list as the Ruby one, this is OK for me.

robertpanzer added a commit to robertpanzer/asciidoctorj that referenced this issue Jan 12, 2019
robertpanzer added a commit to robertpanzer/asciidoctorj that referenced this issue Jan 12, 2019
robertpanzer added a commit to robertpanzer/asciidoctorj that referenced this issue Jan 12, 2019
robertpanzer added a commit to robertpanzer/asciidoctorj that referenced this issue Jan 26, 2019
robertpanzer added a commit that referenced this issue Jan 26, 2019
@jmini
Copy link
Contributor Author

jmini commented May 31, 2019

I am trying the feature from an InlineMacroProcessor:

String warningMessage;
//... set value of warningMessage
log(new LogRecord(Severity.WARN, warningMessage));

I am wondering if there is a possibility to get access to the Cursor in order to use an other LogRecord constructor.
What did I miss?

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 a pull request may close this issue.

4 participants