[jira] [Resolved] (TORQUE-337) Add ability to easily configure logging for the generator

"Georg Kallidis (Jira)" <[email protected]>
Newsgroups gmane.comp.jakarta.turbine.torque.devel
Message-ID <[email protected]>
     [ https://issues.apache.org/jira/browse/TORQUE-337?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Georg Kallidis resolved TORQUE-337.
-----------------------------------
    Fix Version/s: 4.1
         Assignee: Georg Kallidis
       Resolution: Fixed

- Upgraded to Log4j2, which auto-configures itself, (in rev 1855923), swapped commons logging e.g. in rev 1870542.

> 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
>            Assignee: Georg Kallidis
>            Priority: Major
>             Fix For: 4.1
>
>
> 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
(v8.3.4#803005)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.