glassfish
  1. glassfish
  2. GLASSFISH-17314

System.out.printf split into multiple lines in server.log

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 4.0
    • Fix Version/s: 3.1.2_b07, 3.1.2_b17, 4.0
    • Component/s: logging
    • Labels:
      None

      Description

      I have the following lines in ejb class:

      System.out.printf("This is a printf in class %s%n", this);

      It shows up in server.log as 2 separate lines:

      [#|2011-09-17T21:03:30.437-0400|INFO|glassfish4.0|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=13;_ThreadName=Thread-2;|This is a printf in class |#]
      
      [#|2011-09-17T21:03:30.437-0400|INFO|glassfish4.0|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=13;_ThreadName=Thread-2;|com.sun.ejb.devtest.SlessBean@4ae54c6|#]
      

      I expect it to be 1 single line in server.log.

      out.println doesn't have this problem.

        Activity

        Hide
        naman_mehta added a comment -

        This issue is applicable to 3.1.2 also.

        Show
        naman_mehta added a comment - This issue is applicable to 3.1.2 also.
        Hide
        naman_mehta added a comment -
        • What is the impact on the customer of the bug (is it a regression? which of the criteria does it meet?)
          No. It's just formatting of string under server.log file.
        • How likely is it that a customer will see the bug?
          If they use system.out.printf then it's often.
        • How long will it take you to implement the fix?
          1 day
        • How risky is the fix?
          No risk
        • Do regression tests exist for this issue to verify the fix?
          Attaching the sample to verify the same
        • Which tests should QA (re)run to verify the fix did not destabilize GlassFish?
          No QA, but attaching the sample to verify the same
        • Which is the targeted build of 3.1.2 for this fix?
          3.1.2 b08

        As we have our own LoggingOutputStream but not overrided method printf exists there. So during the call off System.out.printf it's printing data in separate line.

        File diff for the same:
        Index: src/main/java/com/sun/common/util/logging/LoggingOutputStream.java
        ===================================================================
        — src/main/java/com/sun/common/util/logging/LoggingOutputStream.java (revision 50341)
        +++ src/main/java/com/sun/common/util/logging/LoggingOutputStream.java (working copy)
        @@ -43,6 +43,8 @@
        import java.io.ByteArrayOutputStream;
        import java.io.IOException;
        import java.io.PrintStream;
        +import java.util.Formatter;
        +import java.util.Locale;
        import java.util.logging.Level;
        import java.util.logging.LogManager;
        import java.util.logging.Logger;
        @@ -202,6 +204,15 @@
        }
        }

        +
        + public PrintStream printf(String str, Object... args)

        { + StringBuilder sb = new StringBuilder(); + Formatter formatter = new Formatter(sb, Locale.getDefault()); + formatter.format(str,args); + print(sb.toString()); + return null; + }

        +
        public void print(String x) {
        if (checkLocks())
        super.print;

        Show
        naman_mehta added a comment - What is the impact on the customer of the bug (is it a regression? which of the criteria does it meet?) No. It's just formatting of string under server.log file. How likely is it that a customer will see the bug? If they use system.out.printf then it's often. How long will it take you to implement the fix? 1 day How risky is the fix? No risk Do regression tests exist for this issue to verify the fix? Attaching the sample to verify the same Which tests should QA (re)run to verify the fix did not destabilize GlassFish? No QA, but attaching the sample to verify the same Which is the targeted build of 3.1.2 for this fix? 3.1.2 b08 As we have our own LoggingOutputStream but not overrided method printf exists there. So during the call off System.out.printf it's printing data in separate line. File diff for the same: Index: src/main/java/com/sun/common/util/logging/LoggingOutputStream.java =================================================================== — src/main/java/com/sun/common/util/logging/LoggingOutputStream.java (revision 50341) +++ src/main/java/com/sun/common/util/logging/LoggingOutputStream.java (working copy) @@ -43,6 +43,8 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.util.Formatter; +import java.util.Locale; import java.util.logging.Level; import java.util.logging.LogManager; import java.util.logging.Logger; @@ -202,6 +204,15 @@ } } + + public PrintStream printf(String str, Object... args) { + StringBuilder sb = new StringBuilder(); + Formatter formatter = new Formatter(sb, Locale.getDefault()); + formatter.format(str,args); + print(sb.toString()); + return null; + } + public void print(String x) { if (checkLocks()) super.print ;
        Hide
        naman_mehta added a comment -

        Fixed the same.

        svn:50419,50420

        Show
        naman_mehta added a comment - Fixed the same. svn:50419,50420
        Hide
        Cheng Fang added a comment -

        The following uses still suffer from the same problem:

        System.out.printf(Locale, message, args);
        
        System.out.format(message, args);
        
        System.out.format(Locale, message, args);
        

        Some logging output from the above statements:

        [#|2012-01-04T11:38:53.173-0500|INFO|44.0|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=17;_ThreadName=Thread-2;|### printf with locale in |#]
        
        [#|2012-01-04T11:38:53.173-0500|INFO|44.0|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=17;_ThreadName=Thread-2;|test.TestBean@565b6f28|#]
        
        [#|2012-01-04T11:38:53.173-0500|INFO|44.0|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=17;_ThreadName=Thread-2;|### format in |#]
        
        [#|2012-01-04T11:38:53.174-0500|INFO|44.0|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=17;_ThreadName=Thread-2;|test.TestBean@565b6f28|#]
        
        [#|2012-01-04T11:38:53.174-0500|INFO|44.0|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=17;_ThreadName=Thread-2;|### format with locale in |#]
        
        [#|2012-01-04T11:38:53.174-0500|INFO|44.0|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=17;_ThreadName=Thread-2;|test.TestBean@565b6f28|#]
        
        Show
        Cheng Fang added a comment - The following uses still suffer from the same problem: System .out.printf(Locale, message, args); System .out.format(message, args); System .out.format(Locale, message, args); Some logging output from the above statements: [#|2012-01-04T11:38:53.173-0500|INFO|44.0|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=17;_ThreadName=Thread-2;|### printf with locale in |#] [#|2012-01-04T11:38:53.173-0500|INFO|44.0|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=17;_ThreadName=Thread-2;|test.TestBean@565b6f28|#] [#|2012-01-04T11:38:53.173-0500|INFO|44.0|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=17;_ThreadName=Thread-2;|### format in |#] [#|2012-01-04T11:38:53.174-0500|INFO|44.0|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=17;_ThreadName=Thread-2;|test.TestBean@565b6f28|#] [#|2012-01-04T11:38:53.174-0500|INFO|44.0|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=17;_ThreadName=Thread-2;|### format with locale in |#] [#|2012-01-04T11:38:53.174-0500|INFO|44.0|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=17;_ThreadName=Thread-2;|test.TestBean@565b6f28|#]
        Hide
        naman_mehta added a comment - - edited
        • What is the impact on the customer of the bug?
          This bug shows log messages in different lines.
        • How likely is it that a customer will see the bug and how serious is the bug?
          Not much.
        • Is it a regression? Does it meet other bug fix criteria (security, performance, etc.)?
          No
        • What is the cost/risk of fixing the bug?
          Need to override methods in LoggingOutputStream. Attached file diff for the same.
        • How risky is the fix? How much work is the fix? Is the fix complicated?
          No impact on other modules.
        • Is there an impact on documentation or message strings?
          No
        • Which tests should QA (re)run to verify the fix did not destabilize GlassFish?
          It's not functionality issue just displaying message in server.log file so no need of specific test.
          String testing = "naman mehta";

        System.out.printf("This is a printf in class %s%n 1.", testing);

        System.out.printf(Locale.ENGLISH, "This is a printf in class %s%n 2.", testing);

        System.out.format("This is a printf in class %s%n 3.", testing);

        System.out.format(Locale.ENGLISH, "This is a printf in class %s%n 4.", testing);

        • Which is the targeted build of 3.1.2 for this fix?
          3.1.2 b17

        Index: src/main/java/com/sun/common/util/logging/LoggingOutputStream.java
        ===================================================================
        — src/main/java/com/sun/common/util/logging/LoggingOutputStream.java (revision 51897)
        +++ src/main/java/com/sun/common/util/logging/LoggingOutputStream.java (working copy)
        @@ -213,6 +213,30 @@
        return null;
        }

        + public PrintStream printf(Locale locale, String str, Object... args)

        { + StringBuilder sb = new StringBuilder(); + Formatter formatter = new Formatter(sb, locale); + formatter.format(str,args); + print(sb.toString()); + return null; + }

        +
        + public PrintStream format(String format, Object... args)

        { + StringBuilder sb = new StringBuilder(); + Formatter formatter = new Formatter(sb, Locale.getDefault()); + formatter.format(Locale.getDefault(), format, args); + print(sb.toString()); + return null; + }

        +
        + public PrintStream format(Locale locale,String format, Object... args)

        { + StringBuilder sb = new StringBuilder(); + Formatter formatter = new Formatter(sb, locale); + formatter.format(locale, format, args); + print(sb.toString()); + return null; + }

        +
        public void print(String x) {

        Show
        naman_mehta added a comment - - edited What is the impact on the customer of the bug? This bug shows log messages in different lines. How likely is it that a customer will see the bug and how serious is the bug? Not much. Is it a regression? Does it meet other bug fix criteria (security, performance, etc.)? No What is the cost/risk of fixing the bug? Need to override methods in LoggingOutputStream. Attached file diff for the same. How risky is the fix? How much work is the fix? Is the fix complicated? No impact on other modules. Is there an impact on documentation or message strings? No Which tests should QA (re)run to verify the fix did not destabilize GlassFish? It's not functionality issue just displaying message in server.log file so no need of specific test. String testing = "naman mehta"; System.out.printf("This is a printf in class %s%n 1.", testing); System.out.printf(Locale.ENGLISH, "This is a printf in class %s%n 2.", testing); System.out.format("This is a printf in class %s%n 3.", testing); System.out.format(Locale.ENGLISH, "This is a printf in class %s%n 4.", testing); Which is the targeted build of 3.1.2 for this fix? 3.1.2 b17 Index: src/main/java/com/sun/common/util/logging/LoggingOutputStream.java =================================================================== — src/main/java/com/sun/common/util/logging/LoggingOutputStream.java (revision 51897) +++ src/main/java/com/sun/common/util/logging/LoggingOutputStream.java (working copy) @@ -213,6 +213,30 @@ return null; } + public PrintStream printf(Locale locale, String str, Object... args) { + StringBuilder sb = new StringBuilder(); + Formatter formatter = new Formatter(sb, locale); + formatter.format(str,args); + print(sb.toString()); + return null; + } + + public PrintStream format(String format, Object... args) { + StringBuilder sb = new StringBuilder(); + Formatter formatter = new Formatter(sb, Locale.getDefault()); + formatter.format(Locale.getDefault(), format, args); + print(sb.toString()); + return null; + } + + public PrintStream format(Locale locale,String format, Object... args) { + StringBuilder sb = new StringBuilder(); + Formatter formatter = new Formatter(sb, locale); + formatter.format(locale, format, args); + print(sb.toString()); + return null; + } + public void print(String x) {
        Hide
        naman_mehta added a comment -

        Made required changes and fixed for 3.1.2 & 4.0.

        Show
        naman_mehta added a comment - Made required changes and fixed for 3.1.2 & 4.0.

          People

          • Assignee:
            naman_mehta
            Reporter:
            Cheng Fang
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: