## Logging Output of the Torque generator

The Torque generator uses logging to visualize the work it does. The log information is written to the console, plus it is written to the file target/torque-gen/log/torque-gen.log. The default log level is INFO. The log level can be changed in two places:

- The templates can define a default log level using the loglevel attribute of the control element in the control.xml configuration file.
- When executing the templates, another log level can be passed in, overriding the log level defined in the templates.

How to set the log level on template execution depends on the way the generator is started:

- Torque Maven Plugin: set the property loglevel on the goal generate to trace, debug, info, warn or error.
- Torque Ant Task: set the property loglevel to true on the Torque generator task to trace, debug, info, warn or error.
- Plain Java: use the setLoglevel method in the UnitDescriptor you pass in when starting the generator.

Note that the loglevel from the control.xml configuration file is applied after the configuration is read, so the log level before this point may be different.

In principle, one can also overwrite the logging behaviour by overwriting the logging configuration file in the class path. (the file used is org.apache.torque.generator.log4j2.xml). There are several (typically hacky) ways to do this, depending on your execution environment; one of them is simply exchanging the logging configuration file in the generator jar you use (or remove it from the jar and add it to the classpath by another means).

## Adding debug information to the output

You can add debug information to the currently generated output. This feature is typically switched off but can be switched on per generation run. How to set the flag depends on the way to start the generation:

- Torque Maven Plugin: set the property addDebuggingInfoToOutput to true on the goal generate.
- Torque Ant Task: set the property addDebuggingInfoToOutput to true on the Torque generator task.
- Plain Java: call setAddDebuggingInfoToOutput(true) on the UnitDescriptor used for the generation.

## Logging Implementation for the Torque generator

Note: This section is for people who want to change the underlying logging framework for the Torque generator. This is not needed when using the Torque Maven Plugin or Torque Ant tasks to start the generator.

The Torque generator uses commons-logging as logging abstraction, so in principle, it is logging-framework agnostic.

However, the loglevel of the Torque generator can be changed by its configuration. This is because it is typically a hassle to configure the logging framework in the build tools where the torque generator is normally running. The ability to set the loglevel is not provided by commons-logging, therefore an adapter (an implementation of `org.apache.torque.generator.configuration.controller.LoggingAdapter`) is used.

Natively, the Torque generator contains two implementations:

- A log4j adapter which reads and sets the current loglevel by reading and changing the level of log4j2's root logger (`org.apache.torque.generator.configuration.controller.Log4j2LoggingAdapter`).
- A dummy adapter which implements the LoggingAdapter interface but cannot read or change a log level (`org.apache.torque.generator.configuration.controller.DummyLoggingAdapter`).

The adapter can be changed at runtime by calling the static method `setLoggingAdapter(LoggingAdapter)` of the class `org.apache.torque.generator.configuration.controller.Loglevel`. By default, the `Log4jLoggingAdapter` is used in Torque 5.0 and `Log4j2LoggingAdapter` in Torque 5.1.