jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From FSchumacher <...@git.apache.org>
Subject [GitHub] jmeter pull request #254: Feature/bz60589-1 PR for review (logkit to slf4j /...
Date Sun, 05 Feb 2017 12:55:15 GMT
Github user FSchumacher commented on a diff in the pull request:

    https://github.com/apache/jmeter/pull/254#discussion_r99488610
  
    --- Diff: src/protocol/http/org/apache/jmeter/protocol/http/control/HttpMirrorServer.java
---
    @@ -159,14 +192,84 @@ public Exception getException(){
             return except;
         }
     
    -    public static void main(String[] args){
    +    public static void main(String[] args) {
    +        CLArgsParser parser = new CLArgsParser(args, options);
    +        String error = parser.getErrorString();
    +        if (error != null) {
    +            System.err.println("Error: " + error);//NOSONAR
    +            System.out.println("Usage");//NOSONAR
    +            System.out.println(CLUtil.describeOptions(options).toString());//NOSONAR
    +            // repeat the error so no need to scroll back past the usage to see it
    +            System.out.println("Error: " + error);//NOSONAR
    +            return;
    +        }
    +
    +        if (parser.getArgumentById(OPTIONS_OPT) != null) {
    +            System.out.println(CLUtil.describeOptions(options).toString());//NOSONAR
    +            return;
    +        }
    +
             int port = HttpMirrorControl.DEFAULT_PORT;
    -        if (args.length > 0){
    -            port = Integer.parseInt(args[0]);
    +
    +        if (parser.getArgumentById(PORT_OPT) != null) {
    +            CLOption option = parser.getArgumentById(PORT_OPT);
    +            String value = option.getArgument(0);
    +            try {
    +                port = Integer.parseInt(value);
    +            } catch (NumberFormatException ignored) {
    +            }
    +        } else if (args.length > 0) {
    +            try {
    +                port = Integer.parseInt(args[0]);
    +            } catch (NumberFormatException ignored) {
    +            }
    +        }
    +
    +        if (System.getProperty("log4j.configurationFile") == null) {// $NON-NLS-1$
    +            Configurator.setRootLevel(Level.INFO);
             }
    -        LoggingManager.setPriority("INFO"); // default level
    -        LoggingManager.setLoggingLevels(System.getProperties() ); // allow override by
system properties
    +
    +        List<CLOption> clOptions = parser.getArguments();
    +
    +        for (CLOption option : clOptions) {
    +            String name = option.getArgument(0);
    +            String value = option.getArgument(1);
    +
    +            switch (option.getDescriptor().getId()) {
    +            case LOGLEVEL_OPT:
    +                if (!value.isEmpty()) { // Set category
    +                    final Level logLevel = Level.getLevel(value);
    +                    if (logLevel != null) {
    +                        String loggerName = name;
    +                        if (name.startsWith("jmeter") || name.startsWith("jorphan"))
{
    +                            loggerName = "org.apache." + name;// $NON-NLS-1$
    +                        }
    +                        getLogger().info("Setting log level to " + value + " for " +
loggerName);// $NON-NLS-1$ // $NON-NLS-2$
    +                        Configurator.setAllLevels(loggerName, logLevel);
    +                    } else {
    +                        getLogger().warn("Invalid log level, '" + value + "' for '" +
name + "'.");// $NON-NLS-1$ // $NON-NLS-2$
    +                    }
    +                } else { // Set root level
    +                    final Level logLevel = Level.getLevel(name);
    +                    if (logLevel != null) {
    +                        getLogger().info("Setting root log level to " + name);// $NON-NLS-1$
    +                        Configurator.setRootLevel(logLevel);
    +                    } else {
    +                        getLogger().warn("Invalid log level, '" + name + "' for the root
logger.");// $NON-NLS-1$ // $NON-NLS-2$
    +                    }
    +                }
    +                break;
    +            }
    +        }
    +
             HttpMirrorServer serv = new HttpMirrorServer(port);
             serv.start();
         }
    +
    +    private static Logger getLogger() {
    --- End diff --
    
    Is `HttpMirrorServer` used from one thread, only?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message