Skip to content

Commit

Permalink
Fixed asadmin logging - ignored exceptions
Browse files Browse the repository at this point in the history
Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Dec 7, 2022
1 parent d5e0282 commit f7922fb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,13 @@ public class AdminMain {
throw new IllegalStateException("GlassFishLogManager is not set as the default LogManager!");
}
}

private String classPath;
private String className;
private String command;
private ProgramOptions po;
private CLIContainer cliContainer;
private final Environment env = new Environment();
private Logger logger;
private final static int SUCCESS = 0;
private final static int ERROR = 1;
private final static int CONNECTION_ERROR = 2;
private final static int INVALID_COMMAND_ERROR = 3;
private final static int WARNING = 4;
private final static String ADMIN_CLI_LOGGER = "com.sun.enterprise.admin.cli";
private static final Environment env = new Environment();
private static final int SUCCESS = 0;
private static final int ERROR = 1;
private static final int CONNECTION_ERROR = 2;
private static final int INVALID_COMMAND_ERROR = 3;
private static final int WARNING = 4;
private static final String ADMIN_CLI_LOGGER = "com.sun.enterprise.admin.cli";

private static final String[] SYS_PROPERTIES_TO_SET_FROM_ASENV = {
SystemPropertyConstants.INSTALL_ROOT_PROPERTY,
Expand All @@ -108,6 +101,13 @@ public class AdminMain {
}
}

private String classPath;
private String className;
private String command;
private ProgramOptions po;
private CLIContainer cliContainer;
private Logger logger;

/**
* Get the class loader that is used to load local commands.
*
Expand Down Expand Up @@ -173,6 +173,7 @@ public void publish(LogRecord logRecord) {
if (!isLoggable(logRecord)) {
return;
}
@SuppressWarnings("resource")
final PrintStream ps = logRecord.getLevel() == SEVERE ? System.err : System.out;
ps.print(getFormatter().format(logRecord));
ps.flush();
Expand All @@ -181,11 +182,29 @@ public void publish(LogRecord logRecord) {


private static class CLILoggerFormatter extends SimpleFormatter {
private static final boolean TRACE = env.trace();

@Override
public synchronized String format(LogRecord record) {
// this formatter adds blank lines between records
return formatMessage(record) + System.lineSeparator();
if (record.getThrown() == null) {
return formatMessage(record) + System.lineSeparator();
}
// Some messages use exception as a parameter.
// If we don't print stacktraces, the cause would be lost.
final Object[] parameters;
if (record.getParameters() == null) {
parameters = new Object[] {record.getThrown()};
} else {
parameters = new Object[record.getParameters().length + 1];
System.arraycopy(record.getParameters(), 0, parameters, 0, parameters.length - 1);
parameters[parameters.length - 1] = record.getThrown();
}
record.setParameters(parameters);
if (TRACE) {
return super.format(record) + System.lineSeparator();
}
return formatMessage(record) + " " + record.getThrown().getLocalizedMessage() + System.lineSeparator();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -27,17 +28,17 @@
* @author &#2325;&#2375;&#2342;&#2366;&#2352 (km@dev.java.net)
* @since GlassFish v3 Prelude
*/

final class ExceptionAnalyzer {

private final Exception exc;
private final List<Throwable> chain;

ExceptionAnalyzer(Exception e) {
if (e == null)
if (e == null) {
throw new IllegalArgumentException("null arg");
}
this.exc = e;
this.chain = new ArrayList<Throwable>();
this.chain = new ArrayList<>();
chain.add(exc);
build();
}
Expand Down

0 comments on commit f7922fb

Please sign in to comment.