db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Fox (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (TORQUE-337) Add ability to easily configure logging for the generator
Date Mon, 12 Oct 2015 01:43:05 GMT

    [ https://issues.apache.org/jira/browse/TORQUE-337?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14952537#comment-14952537
] 

Thomas Fox commented on TORQUE-337:
-----------------------------------

Though I can see the need for overriding the internal log configuration file, I am not convinced
by the solution above. This requires a logger with a special name in the log configuration
file, which is too much magic involved in my opinion.
I'd rather have a setting which tells the generator to use another log4j config file. My first
idea would be to add another attribute to the control tag in the control.xml file (as there's
already the loglevel attribute). What do you think?

> 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-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message