asciidoctor / asciidoctor-gradle-plugin

A Gradle plugin that uses Asciidoctor via JRuby to process AsciiDoc source files within the project.
https://asciidoctor.github.io/asciidoctor-gradle-plugin/
Apache License 2.0
283 stars 120 forks source link

Silencing AsciiDoctor log warnings #631

Open perlun opened 2 years ago

perlun commented 2 years ago

Hi,

When executing a Gradle task using this plugin, we currently get quite a significant amount of log info/warning messages (see below) These tend to pollute the overall Gradle output (especially when executed in CI jobs), so I'm looking for a way to silence these.

The way we currently run the plugin is like this (simplified example):

apply plugin: "org.asciidoctor.jvm.convert"

asciidoctor {
    dependsOn 'asciidoctorSubfolders'

    sourceDir project.file( 'docs/asciidoc' )
    sources {
        include 'index.adoc'
        include 'xrtv/index.adoc'
    }
    baseDirFollowsSourceFile()

    resources {
        from( sourceDir ) {
            include 'images/**'
        }
        from( sourceDir ) {
            include 'images/**'
            into 'xrtv/'
        }
    }

    outputDir "${buildDir}/asciidoc"
    outputOptions {
        separateOutputDirs = true
        backends = ['html5','docbook']
    }
    options doctype: 'book', eruby: 'erubis'
    attributes 'source-highlighter': 'coderay',
               'api-version': 'A',
               'copy-year': (new Date()).year + 1900,
               'snippets': snippetsDir,
               'schemas': schemasDir,
               'docinfo': '',
               'stylesheet': 'styles/base.css'
}

I attempted to fix this by adding quiet: 'true to the options above, but it didn't make any change. This seems to be the way to do it with the asciidoctor CLI, but perhaps the syntax is slightly different with the Gradle plugin? :thinking:

$ asciidoctor -h
Usage: asciidoctor [OPTION]... FILE...
Convert the AsciiDoc input FILE(s) to the backend output format (e.g., HTML 5, DocBook 5, etc.)
Unless specified otherwise, the output is written to a file whose name is derived from the input file.
Application log messages are printed to STDERR.
Example: asciidoctor input.adoc

    -b, --backend BACKEND            set backend output format: [html5, xhtml5, docbook5, manpage] (default: html5)
                                     additional backends are supported via extended converters (e.g., pdf, epub3)
    -d, --doctype DOCTYPE            document type to use when converting document: [article, book, manpage, inline] (default: article)

    [...]

    -q, --quiet                      silence application log messages and script warnings (default: false)
        --trace                      include backtrace information when reporting errors (default: false)

    [...]

Example of log messages that should be silenced

$ gw webapps-hbx:asciidoctor

> Task :webapps-hbx:asciidoctor
Nov 18, 2021 10:45:50 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/substitutors.rb sub_macros
INFO: possible invalid reference: HTTPS
Nov 18, 2021 10:45:50 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/substitutors.rb sub_macros
INFO: possible invalid reference: JSON
Nov 18, 2021 10:45:50 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/substitutors.rb sub_macros
INFO: possible invalid reference: xrtv_media-types
Nov 18, 2021 10:45:51 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb convert_section
INFO: possible invalid reference: create-form
Nov 18, 2021 10:45:51 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb convert_section
INFO: possible invalid reference: create-form
Nov 18, 2021 10:45:51 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb convert_section
INFO: possible invalid reference: create-form
Nov 18, 2021 10:45:51 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb convert_section
INFO: possible invalid reference: HTTP
Nov 18, 2021 10:45:51 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/parser.rb next_block
WARNING: guides-provisioning-verimatrix4.adoc: line 50: no callout found for <1>
Nov 18, 2021 10:45:51 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/parser.rb next_block
WARNING: guides-provisioning-verimatrix4.adoc: line 52: no callout found for <2>
Nov 18, 2021 10:45:51 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/parser.rb next_block
WARNING: guides-provisioning-verimatrix4.adoc: line 56: no callout found for <3>
Nov 18, 2021 10:45:51 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/parser.rb next_block
WARNING: guides-provisioning-verimatrix4.adoc: line 123: no callout found for <1>
Nov 18, 2021 10:45:51 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/parser.rb next_block
WARNING: guides-provisioning-verimatrix4.adoc: line 129: no callout found for <2>
Nov 18, 2021 10:45:51 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/parser.rb next_block
WARNING: guides-provisioning-verimatrix4.adoc: line 134: no callout found for <3>
Nov 18, 2021 10:45:51 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/parser.rb next_block
WARNING: guides-provisioning-verimatrix4.adoc: line 137: no callout found for <4>
Nov 18, 2021 10:45:51 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/parser.rb next_block
WARNING: guides-provisioning-verimatrix4.adoc: line 140: no callout found for <5>
Nov 18, 2021 10:45:51 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/parser.rb next_block
WARNING: guides-provisioning-verimatrix4.adoc: line 144: no callout found for <6>
Nov 18, 2021 10:45:52 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb convert_open
INFO: possible invalid reference: HTTPS
Nov 18, 2021 10:45:52 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb convert_section
INFO: possible invalid reference: JSON
Nov 18, 2021 10:45:52 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb convert_section
INFO: possible invalid reference: xrtv_guides_playback
Nov 18, 2021 10:45:52 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/abstract_block.rb content
INFO: possible invalid reference: HTTP
Nov 18, 2021 10:45:52 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/abstract_block.rb content
INFO: possible invalid reference: HTTP
Nov 18, 2021 10:45:52 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/document.rb content
INFO: possible invalid reference: HTTPS
Nov 18, 2021 10:45:52 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb convert_document
INFO: possible invalid reference: JSON
Nov 18, 2021 10:45:52 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb convert_document
INFO: possible invalid reference: xrtv_media-types
Nov 18, 2021 10:45:52 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb convert_document
INFO: possible invalid reference: index
Nov 18, 2021 10:45:52 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb convert_document
INFO: possible invalid reference: JSON
Nov 18, 2021 10:45:53 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb convert_document
INFO: possible invalid reference: ProblemDetails
Nov 18, 2021 10:45:53 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter.rb convert
INFO: possible invalid reference: HTTPS
Nov 18, 2021 10:45:53 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/docbook5.rb convert_section
INFO: possible invalid reference: JSON
Nov 18, 2021 10:45:53 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/docbook5.rb convert_section
INFO: possible invalid reference: xrtv_media-types
Nov 18, 2021 10:45:53 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/docbook5.rb convert_section
INFO: possible invalid reference: create-form
Nov 18, 2021 10:45:53 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/docbook5.rb convert_section
INFO: possible invalid reference: create-form
Nov 18, 2021 10:45:53 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/docbook5.rb convert_section
INFO: possible invalid reference: create-form
Nov 18, 2021 10:45:53 AM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/docbook5.rb convert_section
INFO: possible invalid reference: HTTP
mojavelinux commented 2 years ago

You're getting these INFO messages because the Gradle plugin is running AsciidoctorJ in verbose mode. This should not be the default. There is a reason the messages says "possible". It's because it's a diagnostic message. So I think the Gradle plugin should be changed to only enable verbose mode upon request.

(Once these INFO messages are turned off, you should not be ignoring the remaining warnings and errors from Asciidoctor).

mojavelinux commented 2 years ago

The log level is controlled by the logLevel property on the AsciidoctorJ base plugin. See https://asciidoctor.github.io/asciidoctor-gradle-plugin/development-3.x/user-guide/#_asciidoctorj_base_plugin. It seems like it is tied to the Gradle log level by default, which must be "info". I stand behind my statement that this is not the right default. It should be "warn". But you can change it by using this property.

perlun commented 2 years ago

Thanks for a fast reply. :bow: project.logger.level as referred to in those docs doesn't seem to exist for me (Gradle 7.2) but project.logger.context.level is set to LIFECYCLE - right between INFO and WARN in the enum definition:

package org.gradle.api.logging;

public enum LogLevel {
    DEBUG,
    INFO,
    LIFECYCLE,
    WARN,
    QUIET,
    ERROR;

    private LogLevel() {
    }
}

Anyway: I tried this approach now with no apparent success:

asciidoctorj {
    modules {
       diagram.use()
       diagram.version "${asciidoctorJDiagramVersion}"
    }

    // Tested with both WARN and QUIET
    logLevel LogLevel.WARN
}

(I tried to also set it to info and warn as strings at first, and it didn't give me any errors but just seemed to silently ignore the setting.)

Here's the exact JVM command line for the Asciidoctor invocation which Gradle prints if I give it the --info flag, if it is of any help:

> Task :webapps-hbx:asciidoctor
Caching disabled for task ':webapps-hbx:asciidoctor' because:
  Build cache is disabled
Task ':webapps-hbx:asciidoctor' is not up-to-date because:
  Executed with '--rerun-tasks'.
Watching 186 directories to track changes
Watching 163 directories to track changes
Copy resources for 'html5' to /home/per/git/hiboxcentre/webapps/hbx/build/asciidoc/html5
Copy resources for 'docbook' to /home/per/git/hiboxcentre/webapps/hbx/build/asciidoc/docbook
Running AsciidoctorJ instance with classpath [/home/per/.gradle/caches/jars-9/6308bf1b67c311e6d7d1696431d58334/asciidoctor-gradle-jvm-3.3.2.jar, /home/per/.gradle/wrapper/dists/gradle-7.2-bin/2dnblmf4td7x66yl1d74lt32g/gradle-7.2/lib/groovy-3.0.8.jar, /home/per/.gradle/caches/modules-2/files-2.1/org.asciidoctor/asciidoctorj/2.4.1/37e4d975e2479bd03a348e3d9c77a89fa510f0bb/asciidoctorj-2.4.1.jar, /home/per/.gradle/caches/modules-2/files-2.1/org.asciidoctor/asciidoctorj-diagram/2.0.1/fcc21a110fb0dbbed7baf46fce71cef3c5e9b17b/asciidoctorj-diagram-2.0.1.jar, /home/per/.gradle/caches/modules-2/files-2.1/org.jruby/jruby-complete/9.2.13.0/1e6de00e7bea5ff3c9d6086fd9e2610258c051ce/jruby-complete-9.2.13.0.jar, /home/per/.gradle/caches/modules-2/files-2.1/org.asciidoctor/asciidoctorj-api/2.4.1/6cd3abc3bff2d32a7ede570ddb950b42c404465e/asciidoctorj-api-2.4.1.jar, /home/per/.gradle/caches/modules-2/files-2.1/com.beust/jcommander/1.72/6375e521c1e11d6563d4f25a07ce124ccf8cd171/jcommander-1.72.jar, /home/per/.gradle/wrapper/dists/gradle-7.2-bin/2dnblmf4td7x66yl1d74lt32g/gradle-7.2/lib/guava-30.1.1-jre.jar]
Starting process 'command '/usr/lib/jvm/adoptopenjdk-11-hotspot-amd64/bin/java''. Working directory: /home/per/git/hiboxcentre/webapps/hbx Command: /usr/lib/jvm/adoptopenjdk-11-hotspot-amd64/bin/java -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -cp /home/per/.gradle/caches/jars-9/6308bf1b67c311e6d7d1696431d58334/asciidoctor-gradle-jvm-3.3.2.jar:/home/per/.gradle/wrapper/dists/gradle-7.2-bin/2dnblmf4td7x66yl1d74lt32g/gradle-7.2/lib/groovy-3.0.8.jar:/home/per/.gradle/caches/modules-2/files-2.1/org.asciidoctor/asciidoctorj/2.4.1/37e4d975e2479bd03a348e3d9c77a89fa510f0bb/asciidoctorj-2.4.1.jar:/home/per/.gradle/caches/modules-2/files-2.1/org.asciidoctor/asciidoctorj-diagram/2.0.1/fcc21a110fb0dbbed7baf46fce71cef3c5e9b17b/asciidoctorj-diagram-2.0.1.jar:/home/per/.gradle/caches/modules-2/files-2.1/org.jruby/jruby-complete/9.2.13.0/1e6de00e7bea5ff3c9d6086fd9e2610258c051ce/jruby-complete-9.2.13.0.jar:/home/per/.gradle/caches/modules-2/files-2.1/org.asciidoctor/asciidoctorj-api/2.4.1/6cd3abc3bff2d32a7ede570ddb950b42c404465e/asciidoctorj-api-2.4.1.jar:/home/per/.gradle/caches/modules-2/files-2.1/com.beust/jcommander/1.72/6375e521c1e11d6563d4f25a07ce124ccf8cd171/jcommander-1.72.jar:/home/per/.gradle/wrapper/dists/gradle-7.2-bin/2dnblmf4td7x66yl1d74lt32g/gradle-7.2/lib/guava-30.1.1-jre.jar org.asciidoctor.gradle.remote.AsciidoctorJavaExec /home/per/git/hiboxcentre/webapps/hbx/build/tmp/asciidoctor.javaexec-data
Successfully started process 'command '/usr/lib/jvm/adoptopenjdk-11-hotspot-amd64/bin/java''
Nov 18, 2021 5:14:45 PM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/substitutors.rb sub_macros
INFO: possible invalid reference: HTTPS
Nov 18, 2021 5:14:45 PM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/substitutors.rb sub_macros
INFO: possible invalid reference: JSON
Nov 18, 2021 5:14:45 PM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/substitutors.rb sub_macros
INFO: possible invalid reference: xrtv_media-types
Nov 18, 2021 5:14:45 PM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb convert_section
INFO: possible invalid reference: create-form
Nov 18, 2021 5:14:45 PM uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/converter/html5.rb convert_section
[...]
perlun commented 2 years ago

@mojavelinux Any ideas why the above doesn't work in my use case? :thinking:

mojavelinux commented 2 years ago

I can only comment on how Asciidoctor works. You'll have to direct your question to the plugin's maintainers for how it works in the plugin's environment.

perlun commented 2 years ago

Thanks. :+1: @ysb33r @aalmiray any ideas?

cgoguyer commented 1 year ago

I get the same issue. Any news on how to fix that ?

ysb33r commented 1 year ago

There is a PR in progress. Will be released as part of 4.0.

⁣Get BlueMail for Android ​

On 10 Aug 2022, 15:45, at 15:45, Christophe @.***> wrote:

I get the same issue. Any news on how to fix that ?

-- Reply to this email directly or view it on GitHub: https://github.com/asciidoctor/asciidoctor-gradle-plugin/issues/631#issuecomment-1210697360 You are receiving this because you were mentioned.

Message ID: @.***>

cgoguyer commented 1 year ago

Good news, is there a planned date for this release ?

ysb33r commented 1 year ago

As soon as I can get one bug sorted, we'll roll a release. September time-frame, before Gradle 8.0 goes out of the door.

ysb33r commented 1 year ago

Please try 4.0.0-alpha.1 and tell me if the problem still exists