[ https://issues.apache.org/jira/browse/TORQUE-337?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14955181#comment-14955181 ]
Helge Weissig commented on TORQUE-337: -------------------------------------- It simply requires a logger to be defined for the generator’s package. What you name it, is up to you. Even just having a logger defined for the entire ‘org’ hierarchy will trigger the conditional. That would work as well, of course. That’s the first place I looked for any logging configuration settings. Instead of specifying a different log4j file, you could have the settings right there too. OR, simply move all the log settings to an external file, including the log level. cheers, h. > Add ability to easily configure logging for the generator > --------------------------------------------------------- > > Key: TORQUE-337 > URL: https://issues.apache.org/jira/browse/TORQUE-337 > Project: Torque > Issue Type: Improvement > Components: Generator > Affects Versions: 4.1 > Reporter: Helge Weissig > > The patch below allows for the easy configuration of logging for the > generator. For example, using maven, the internal log4j.properties shipped > with the torque-generator artifact can be overridden by including the command > line flag '-Dlog4j.properties=file:/<path to file>'. > patch: > {code} > Index: > torque-generator/src/main/java/org/apache/torque/generator/control/Controller.java > =================================================================== > --- > torque-generator/src/main/java/org/apache/torque/generator/control/Controller.java > (revision 1689921) > +++ > torque-generator/src/main/java/org/apache/torque/generator/control/Controller.java > (working copy) > @@ -35,6 +35,8 @@ > > import org.apache.commons.logging.Log; > import org.apache.commons.logging.LogFactory; > +import org.apache.log4j.LogManager; > +import org.apache.log4j.Logger; > import org.apache.log4j.PropertyConfigurator; > import org.apache.torque.generator.GeneratorException; > import org.apache.torque.generator.configuration.Configuration; > @@ -152,19 +154,29 @@ > */ > protected void initLogging() > { > - final InputStream log4jStream > - = Controller.class.getClassLoader().getResourceAsStream( > - "org/apache/torque/generator/log4j.properties"); > - final Properties log4jProperties = new Properties(); > - try > + Logger logger = LogManager.exists("org.apache.torque.generator"); > + if (logger == null) > { > - log4jProperties.load(log4jStream); > + log.info("Configuring logging from internal log4j.properties"); > + final InputStream log4jStream = > + Controller.class.getClassLoader().getResourceAsStream( > + "org/apache/torque/generator/log4j.properties"); > + final Properties log4jProperties = new Properties(); > + > + try > + { > + log4jProperties.load(log4jStream); > + } > + catch (final IOException e) { > + throw new RuntimeException(e); > + } > + > + PropertyConfigurator.configure(log4jProperties); > } > - catch (final IOException e) > + else > { > - throw new RuntimeException(e); > + log.warn("Using external logging configuration"); > } > - PropertyConfigurator.configure(log4jProperties); > } > > /** > {code} > example log4j.properties: > {code} > ## modify logging for the chatty Torque generator > log4j.logger.org.apache.torque.generator = INFO, generator, console > log4j.appender.generator = org.apache.log4j.FileAppender > log4j.appender.generator.file = target/torque-gen/log/torque-gen.log > log4j.appender.generator.append = true > log4j.appender.generator.layout = org.apache.log4j.PatternLayout > log4j.appender.generator.layout.conversionPattern = %d [%t] %-5p %c - %m%n > log4j.appender.console = org.apache.log4j.ConsoleAppender > log4j.appender.console.layout = org.apache.log4j.PatternLayout > log4j.appender.console.layout.conversionPattern = %-5p %c - %m%n > log4j.appender.console.threshold = WARN > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: torque-dev-unsubscr...@db.apache.org For additional commands, e-mail: torque-dev-h...@db.apache.org