Logging Information

MyBatis Generator (MBG) reports logging information in several different ways:

  • MBG may generate and display warning messages every time it is run. These messages are meant to inform the user of significant events that may, or may not, require attention. Examples are files being overwritten, non-fatal configuration errors, etc. Warnings are always displayed - regardless of configuration or command line options.
  • MBG generates and may, or may not, display progress messages every time it is run. These messages are meant to inform to user of progress in code generation. These messages are not displayed by default, but may be enabled by specifying the -verbose command line argument. Or, if you are running MBG with the built-in Ant task, these messages may be enabled by setting the verbose attribute to true, and then running Ant in verbose mode.
  • Lastly, MBG will generate tracing (logging) messages for detailed debugging. This page explains how to enable these statements.

In general, MBG will not repeat messages. So if MBG generates a warning, that warning is typically not also logged. In some situations it may be useful to enable logging as well as asking MBG to be verbose with progress messages. This may generate a significant output, but it will also give a very complete picture of what's happening internally during the MBG run.

Internally, MBG uses commons logging which allows you to change the logging implementation. Information about configuring commons logging can be found here: https://commons.apache.org/proper/commons-logging/

Configuring SLF4J Logging

The following is a sample Logback configuration file (Logback is the default implementation of SLF4J):

<configuration>
  <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>
  <logger name="org.mybatis.generator" level="debug" />
  <root level="error">
    <appender-ref ref="Console" />
  </root>
</configuration>

This file will instruct SLF4J to write all MBG debug messages to the console. To use this file:

  1. Create a file called logback.xml in the root of your runtime classpath
  2. Copy the above entries into the new file
  3. Run MBG with Logback classic as a dependency in your POM.

You should see many log messages in the console.

You may also configure SLF4J in any of the other supported methods if you prefer.

You may also configure Java logging in any of the other supported methods if you prefer.