mirror of https://github.com/hyperledger/besu
Add errorprone to prevent Log4j direct usage (#3759)
* Replace Log4j2 API with SLF4j API * Replace explicit Log4J2 with util call * Replace ThreadContext with Slf4J's MDC in test * Inspect raw request parameter for admin_changeLogLevel * Add errorprone rule to prevent the creation Log4j2 loggers Signed-off-by: Diego López León <dieguitoll@gmail.com> Co-authored-by: Sally MacFarlane <sally.macfarlane@consensys.net>pull/3754/merge
parent
0fb2e4b606
commit
a154034531
@ -0,0 +1,60 @@ |
||||
/* |
||||
* Copyright contributors to Hyperledger Besu. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.cli.options.stable; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS; |
||||
|
||||
import java.util.Arrays; |
||||
|
||||
import org.apache.logging.log4j.Level; |
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
import org.mockito.Mockito; |
||||
import picocli.CommandLine.Model.CommandSpec; |
||||
import picocli.CommandLine.ParameterException; |
||||
|
||||
public class LoggingLevelOptionTest { |
||||
|
||||
private LoggingLevelOption levelOption; |
||||
|
||||
@Before |
||||
public void setUp() { |
||||
levelOption = new LoggingLevelOption(); |
||||
} |
||||
|
||||
@Test |
||||
public void fatalLevelEqualsToError() { |
||||
levelOption.setLogLevel("fatal"); |
||||
assertThat(levelOption.getLogLevel()).isEqualTo(Level.ERROR); |
||||
} |
||||
|
||||
@Test |
||||
public void setsExpectedLevels() { |
||||
Arrays.stream(Level.values()) |
||||
.filter(level -> !Level.FATAL.equals(level)) |
||||
.forEach( |
||||
level -> { |
||||
levelOption.setLogLevel(level.name()); |
||||
assertThat(levelOption.getLogLevel()).isEqualTo(level); |
||||
}); |
||||
} |
||||
|
||||
@Test(expected = ParameterException.class) |
||||
public void failsOnUnknownLevel() { |
||||
levelOption.spec = Mockito.mock(CommandSpec.class, RETURNS_DEEP_STUBS); |
||||
levelOption.setLogLevel("unknown"); |
||||
} |
||||
} |
Loading…
Reference in new issue