[
https://issues.apache.org/jira/browse/HDFS-9130?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14905914#comment-14905914
]
Haohui Mai commented on HDFS-9130:
----------------------------------
+1. I'll commit it shortly.
> Use GenericTestUtils#setLogLevel to set log4j or slf4j logger's level in unit
> tests
> -----------------------------------------------------------------------------------
>
> Key: HDFS-9130
> URL: https://issues.apache.org/jira/browse/HDFS-9130
> Project: Hadoop HDFS
> Issue Type: Task
> Reporter: Mingliang Liu
> Assignee: Mingliang Liu
> Attachments: HDFS-9130.000.patch
>
>
> Currently we use both commons-logging and slf4j in {{hadoop-hdfs}}. To change
> the logger level for dumping verbose debug information, there are many unit
> tests that just cast the LOG object to a {{Log4JLogger}} and call
> {{setLevel}} on that. e.g. in {{org.apache.hadoop.fs.TestFcHdfsSetUMask}},
> code sample as
> {code}
> ((Log4JLogger)FileSystem.LOG).getLogger().setLevel(Level.DEBUG);
> {code}
> One problem of this hard-coded approach is that we need to update the casting
> code in test if we replace the log4j logger with slf4j. For example, as we're
> creating a separate jar for hdfs-client (see [HDFS-6200]) which uses only
> slf4j, we need to replace the log4j logger with slf4j logger, and to update
> the casting for changing logger's level in unit tests as well.
> Instead, we can use the {{GenericTestUtils#setLogLevel}} (brought in
> [HADOOP-11430]) method for both types of logger. This method internally
> figures out the right thing to do based on the log / logger type. e.g.
> {code}
> GenericTestUtils.setLogLevel(FileSystem.LOG, Level.DEBUG);
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)