[
https://issues.apache.org/jira/browse/PARQUET-395?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15029013#comment-15029013
]
Henrik Baastrup edited comment on PARQUET-395 at 11/26/15 3:55 PM:
-------------------------------------------------------------------
h4. Workaround
The below code is noway beautiful but will work as workaround and should be
implemented before you call any API in the Parquet library.
{code}
import java.util.loggingLogger;
OffStreamHandler offH = new OffStreamHandler(new NullOutputStream(), new
SimpleFormatter());
Logger logger =
Logger.getLogger(org.apache.parquet.Log.class.getPackage().getName());
logger.addHandler(offH);
{code}
{code:title=OffStreamHandler|borderStyle=solid}
public class OffStreamHandler extends StreamHandler {
private Level myLevel = Level.OFF; // by default, put out off
/**
* The only method we really change to check whether the message
* is smaller than maxlevel.
*/
@Override
public synchronized void publish(LogRecord record) {
if (record.getLevel().intValue() > this.myLevel.intValue()) {
// do nothing if the level is above myLevel
} else {
// if we arrived here, do what we always do
super.publish(record);
super.flush();
}
}
@Override
public synchronized void close() throws SecurityException {
super.close();
}
public void setLevel(Level l) {
myLevel = l;
}
/** Constructor forwarding */
public OffStreamHandler(OutputStream out, Formatter formatter) {
super(out, formatter);
}
/** Constructor forwarding */
public OffStreamHandler() {
super();
}
}
{code}
was (Author: hbaastrup):
h4. Workaround
The below code is noway beautiful but will work as workaround and should be
implemented before you call any API in the Parquet library.
{code}
import java.util.loggingLogger;
OffStreamHandler offH = new OffStreamHandler(new NullOutputStream(), new
SimpleFormatter());
Logger logger =
Logger.getLogger(org.apache.parquet.Log.class.getPackage().getName());
logger.addHandler(offH);
{code}
{code:title=OffStreamHandler|borderStyle=solid}
public class OffStreamHandler extends StreamHandler {
private Level myLevel = Level.OFF; // by default, put out off
/**
* The only method we really change to check whether the message
* is smaller than maxlevel.
* We also flush here to make sure that the message is shown
immediately.
*/
@Override
public synchronized void publish(LogRecord record) {
if (record.getLevel().intValue() > this.myLevel.intValue()) {
// do nothing if the level is above myLevel
} else {
// if we arrived here, do what we always do
super.publish(record);
super.flush();
}
}
@Override
public synchronized void close() throws SecurityException {
super.close();
}
/** Constructor forwarding */
public OffStreamHandler(OutputStream out, Formatter formatter) {
super(out, formatter);
}
/** Constructor forwarding */
public OffStreamHandler() {
super();
}
}
{code}
> System.out is used as logger in org.apache.parquet.Log
> ------------------------------------------------------
>
> Key: PARQUET-395
> URL: https://issues.apache.org/jira/browse/PARQUET-395
> Project: Parquet
> Issue Type: Bug
> Affects Versions: 1.8.0
> Environment: parquet-common-1.8.1.jar
> Reporter: Henrik Baastrup
>
> The use of System.out in the StreamHandler at line 62 in the
> org.apache.parquet.Log provoke that the java.util.logging.LogManager will
> close System.out in case the reset method is called on the LogManager.
> This is special problematic when Shutdown Hooks are used in a project, as the
> LogManager set-up one, there call the reset method, and for this reason a
> race condition exist on System.out, if used in the project Shutdown Hook.
> Other scenarios might also exist where a program call the LogManager reset
> method.
> An eventual solution is to NOT use java.util.logging.Logger at all in the
> Parquet environment but use either log4j or slf4j as used in almost every
> other part in the Hadoop environment, this would also allow the user to
> control the logging much better than today.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)