Skip to content

Commit

Permalink
Move log4j2 config util to shared lib package
Browse files Browse the repository at this point in the history
  • Loading branch information
jiridanek committed Nov 3, 2022
1 parent 51be597 commit 8616bbb
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 7 deletions.
5 changes: 5 additions & 0 deletions cli-activemq-jmx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
<artifactId>commons-cli</artifactId>
<version>${commons-cli.version}</version>
</dependency>

<dependency>
<groupId>com.redhat.cli-java</groupId>
<artifactId>lib</artifactId>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.redhat.amqx.main.actions;

import com.redhat.amqx.main.LogConfigurator;
import com.redhat.mqe.lib.LogConfigurator;
import com.redhat.amqx.management.Credentials;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.HelpFormatter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class CliProtonJ2Connector extends CliProtonJ2SenderReceiverConnector implements

@Override
public Integer call() throws Exception {
configureLogging();

String prefix = "";
if (!broker.startsWith("amqp://") && !broker.startsWith("amqps://")) {
prefix = "amqp://";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public CliProtonJ2Receiver(ProtonJ2MessageFormatter messageFormatter) {
*/
@Override
public Integer call() throws Exception {
configureLogging();

duration *= 1000; // convert to milliseconds

String prefix = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ public class CliProtonJ2Sender extends CliProtonJ2SenderReceiver implements Call
@CommandLine.Option(names = {"--sync-mode"})
private SyncMode syncMode;

@CommandLine.Option(names = {"--log-lib"})
private LogLib logLib;

@CommandLine.Option(names = {"--duration-mode"})
private DurationModeSender durationMode = DurationModeSender.afterSend;

Expand All @@ -156,7 +153,9 @@ public CliProtonJ2Sender(ProtonJ2MessageFormatter messageFormatter) {
* This is the main function of the client, as called by the cli options handling library.
*/
@Override
public Integer call() throws Exception { // your business logic goes here...
public Integer call() throws Exception {
configureLogging();

duration *= 1000; // convert to milliseconds

String prefix = "";
Expand Down
2 changes: 1 addition & 1 deletion cli-protonj2/src/main/java/com/redhat/mqe/LogLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
package com.redhat.mqe;

public enum LogLib {
off,
off, trace
}
13 changes: 13 additions & 0 deletions cli-protonj2/src/main/java/com/redhat/mqe/Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.redhat.mqe;

import com.redhat.mqe.lib.LogConfigurator;
import org.apache.qpid.protonj2.client.ConnectionOptions;
import org.apache.qpid.protonj2.client.Message;
import org.apache.qpid.protonj2.client.exceptions.ClientException;
Expand Down Expand Up @@ -41,6 +42,8 @@ public static void main(String... args) {
}

class CliProtonJ2SenderReceiverConnector {
@CommandLine.Option(names = {"--log-lib"})
private LogLib logLib = LogLib.off;
@CommandLine.Option(names = {"--conn-username"}, description = "")
private String connUsername = "MD5";
@CommandLine.Option(names = {"--conn-password"}, description = "")
Expand Down Expand Up @@ -99,6 +102,16 @@ protected ConnectionOptions getConnectionOptions() {
// );
return options;
}

protected void configureLogging() {
switch (logLib) {
case trace:
LogConfigurator.trace();
break;
case off:
break;
}
}
}

class CliProtonJ2SenderReceiver extends CliProtonJ2SenderReceiverConnector {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
package com.redhat.amqx.main;
/*
* Copyright (c) 2022 Red Hat, Inc.
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.redhat.mqe.lib;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.LoggerContext;
Expand Down

0 comments on commit 8616bbb

Please sign in to comment.