-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
8, 9
-
generic
-
generic
FULL PRODUCT VERSION :
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.15063]
A DESCRIPTION OF THE PROBLEM :
ConsoleHandler should write logs to the current System.err, but it always writes to the error stream at the time it was created.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. set System.err to write to s1
2. create anonymous logger and log message
3. set System.err to write to s2
4. use the same logger to log another message
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The first log should go to s1 and the second log should go to s2.
---------------------------------
s1: Sep 04, 2017 9:07:14 PM LoggerTest main
INFO: System.err is s1
s2:
Sep 04, 2017 9:07:14 PM LoggerTest main
INFO: System.err is s2
ACTUAL -
Both logs go to s1.
----------------------------
s1: Sep 04, 2017 9:07:14 PM LoggerTest main
INFO: System.err is s1
Sep 04, 2017 9:07:14 PM LoggerTest main
INFO: System.err is s2
s2:
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.*;
import java.util.*;
import java.util.logging.*;
public class LoggerTest {
public static void main(String[] args) throws UnsupportedEncodingException {
ByteArrayOutputStream s1 = new ByteArrayOutputStream();
ByteArrayOutputStream s2 = new ByteArrayOutputStream();
System.setErr(new PrintStream(s1));
Logger logger = Logger.getAnonymousLogger();
logger.info("System.err is s1");
System.setErr(new PrintStream(s2));
logger.info("System.err is s2");
System.out.println("s1: " + s1.toString("UTF-8"));
System.out.println("s2: " + s2.toString("UTF-8"));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Wrap System.err before creating the logger, which redirects output to the current System.err.
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.15063]
A DESCRIPTION OF THE PROBLEM :
ConsoleHandler should write logs to the current System.err, but it always writes to the error stream at the time it was created.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. set System.err to write to s1
2. create anonymous logger and log message
3. set System.err to write to s2
4. use the same logger to log another message
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The first log should go to s1 and the second log should go to s2.
---------------------------------
s1: Sep 04, 2017 9:07:14 PM LoggerTest main
INFO: System.err is s1
s2:
Sep 04, 2017 9:07:14 PM LoggerTest main
INFO: System.err is s2
ACTUAL -
Both logs go to s1.
----------------------------
s1: Sep 04, 2017 9:07:14 PM LoggerTest main
INFO: System.err is s1
Sep 04, 2017 9:07:14 PM LoggerTest main
INFO: System.err is s2
s2:
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.*;
import java.util.*;
import java.util.logging.*;
public class LoggerTest {
public static void main(String[] args) throws UnsupportedEncodingException {
ByteArrayOutputStream s1 = new ByteArrayOutputStream();
ByteArrayOutputStream s2 = new ByteArrayOutputStream();
System.setErr(new PrintStream(s1));
Logger logger = Logger.getAnonymousLogger();
logger.info("System.err is s1");
System.setErr(new PrintStream(s2));
logger.info("System.err is s2");
System.out.println("s1: " + s1.toString("UTF-8"));
System.out.println("s2: " + s2.toString("UTF-8"));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Wrap System.err before creating the logger, which redirects output to the current System.err.