Aakanksha
Aakanksha

Reputation: 11

Glassfish v2.1 starts fine but logs don't get displayed

I'm facing this problem everytime I start glassfish server. The server starts fine but due to this error my logger outputs don't get logged to the server.log file. This seems like a bug in glassfish version 2.1. I cant shift to a higher version as the application I'm running doesn't support higher versions. Most of the posts online report this error when glassfish is started from MyEclipse IDE and suggest stopping the server from IDE and then restarting it from command-line. I always start my server from the terminal still I get this error. I'm really confused and can't do much debugging without viewing my logs. Could anyone suggest a suitable workaround please?

Few of the things I tried were

  1. My log level was INFO initially, changed it to FINE and SEVERE but still it has no effect.
  2. I redirected my logs to a different loacation thinking that might help but No use.
  3. I even tried modifying /etc/java-6-openjdk/logging.properties as per the post -recursive call into SystemOutandErrhandler but that did not help either.

This is really annoying. Help would be really appreciated. Thanks in advance.

-client
-XX:+UnlockDiagnosticVMOptions
-XX:MaxPermSize=192m
-Xmx512m
-XX:NewRatio=2
-XX:+LogVMOutput
-XX:LogFile=/home/aakanksha/softwares/glassfish/domains/visionael/logs/jvm.log
-cp
/home/aakanksha/softwares/glassfish/lib/jhall.jar:/home/aakanksha/softwares/glassfish/lib/appserv-launch.jar
com.sun.enterprise.server.PELaunch
start
recursive call into SystemOutandErrhandler
java.lang.RuntimeException: recursivecall
    at com.sun.enterprise.server.logging.SystemOutandErrHandler$LoggingByteArrayOutputStream.flush(SystemOutandErrHandler.java:359)
    at java.io.PrintStream.write(PrintStream.java:449)
    at com.sun.enterprise.server.logging.SystemOutandErrHandler$LoggingPrintStream.write(SystemOutandErrHandler.java:293)
    at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:220)
    at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:281)
    at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:124)
    at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:134)
    at java.io.OutputStreamWriter.write(OutputStreamWriter.java:220)
    at java.io.Writer.write(Writer.java:157)
    at java.util.logging.StreamHandler.publish(StreamHandler.java:209)
    at java.util.logging.ConsoleHandler.publish(ConsoleHandler.java:105)
    at java.util.logging.Logger.log(Logger.java:573)
    at java.util.logging.Logger.doLog(Logger.java:598)
    at java.util.logging.Logger.log(Logger.java:621)
    at com.sun.enterprise.server.logging.SystemOutandErrHandler$LoggingByteArrayOutputStream.flush(SystemOutandErrHandler.java:368)
    at java.io.PrintStream.write(PrintStream.java:449)
    at com.sun.enterprise.server.logging.SystemOutandErrHandler$LoggingPrintStream.write(SystemOutandErrHandler.java:293)
    at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:220)
    at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:290)
    at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:294)
    at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:140)
    at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
    at java.util.logging.StreamHandler.flush(StreamHandler.java:242)
    at java.util.logging.ConsoleHandler.publish(ConsoleHandler.java:106)
    at java.util.logging.Logger.log(Logger.java:573)
    at java.util.logging.Logger.doLog(Logger.java:598)
    at java.util.logging.Logger.log(Logger.java:662)
    at com.sun.enterprise.server.ApplicationServer.printStartupInfo(ApplicationServer.java:618)
    at com.sun.enterprise.server.ApplicationServer.onInitialization(ApplicationServer.java:170)
    at com.sun.enterprise.server.ondemand.OnDemandServer.onInitialization(OnDemandServer.java:103)
    at com.sun.enterprise.server.PEMain.run(PEMain.java:399)
    at com.sun.enterprise.server.PEMain.main(PEMain.java:336)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:622)
    at com.sun.enterprise.server.PELaunch.main(PELaunch.java:415)

Upvotes: 1

Views: 1043

Answers (1)

jmehrens
jmehrens

Reputation: 11035

From GLASSFISH-6164 the workaround is listed as:

If I reset System.out and System.err to point to a temporary file before calling readConfiguration and don't reset them to point to the logger then everything works fine.

You might be able to create a custom LogManager that performs that workaround when readConfiguration is called. Then install the custom LogManager by using the java.util.logging.manager system property on startup.

public class ConsoleLogManager extends LogManager {

   @Override
   public void readConfiguration() throws IOException, SecurityException {
        final PrintStream out = System.out;
        final PrintStream err = System.err;
        System.setOut(off());
        try {
            System.setErr(off());
            try {
                super.readConfiguration();
            } finally {
                System.setErr(err);
            }
        } finally {
            System.setOut(out);
        }
    }

    @Override
    public void readConfiguration(InputStream ins) throws IOException, SecurityException {
       final PrintStream out = System.out;
       final PrintStream err = System.err;
       System.setOut(off());
       try {
            System.setErr(off());
            try {
                super.readConfiguration(ins);
            } finally {
                System.setErr(err);
            }
        } finally {
            System.setOut(out);
        }
    }

    @Override
    public void reset() throws SecurityException {
        final PrintStream out = System.out;
        final PrintStream err = System.err;
        System.setOut(off());
        try {
            System.setErr(off());
            try {
                super.reset();
            } finally {
                System.setErr(err);
            }
        } finally {
            System.setOut(out);
        }
    }

    private static PrintStream off() {
        return new PrintStream(new ByteArrayOutputStream());
    }
}

Another workaround would be to wrap the System.out and System.in print streams and do nothing when you detect reentrance. You can use the custom LogManager to get them installed.

Upvotes: 1

Related Questions