下面列出了怎么用org.apache.log4j.varia.NullAppender的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Sets up the verbose and debug mode depending on mvn logging level, and
* sets up hyperjaxb logging.
*/
protected void setupLogging() {
super.setupLogging();
final Logger rootLogger = LogManager.getRootLogger();
rootLogger.addAppender(new NullAppender());
final Logger logger = LogManager.getLogger("org.jvnet.hyperjaxb3");
final Log log = getLog();
logger.addAppender(new Appender(getLog(), new PatternLayout(
"%m%n %c%n")));
if (this.getDebug()) {
log.debug("Logger level set to [debug].");
logger.setLevel(Level.DEBUG);
} else if (this.getVerbose())
logger.setLevel(Level.INFO);
else if (log.isWarnEnabled())
logger.setLevel(Level.WARN);
else
logger.setLevel(Level.ERROR);
}
/***/
@BeforeClass
public static void beforeClass() {
if (!DEBUG) {
getRootLogger().removeAllAppenders();
getRootLogger().addAppender(new NullAppender());
}
}
/** Test Class setup */
@BeforeClass
public static void init() {
SWTBotUtils.initialize();
/* set up for swtbot */
SWTBotPreferences.TIMEOUT = 50000; /* 50 second timeout */
fLogger.removeAllAppenders();
fLogger.addAppender(new NullAppender());
fBot = new SWTWorkbenchBot();
SWTBotUtils.switchToTracingPerspective();
/* finish waiting for eclipse to load */
WaitUtils.waitForJobs();
}
/**
* Setup before the test suite
*
* @throws IOException
* failed to load the file
*/
@BeforeClass
public static void beforeClass() throws IOException {
SWTBotUtils.initialize();
/* set up for swtbot */
SWTBotPreferences.TIMEOUT = 50000; /* 50 second timeout */
fLogger.removeAllAppenders();
fLogger.addAppender(new NullAppender());
File parentDir = FileUtils.toFile(FileLocator.toFileURL(CtfTestTrace.TRACE_EXPERIMENT.getTraceURL()));
File[] traceFiles = parentDir.listFiles();
ITmfTrace traceValidator = new CtfTmfTrace();
fBot = new SWTWorkbenchBot();
SWTBotUtils.createProject(PROJECT_NAME);
int openedTraces = 0;
for (File traceFile : traceFiles) {
String absolutePath = traceFile.getAbsolutePath();
if (traceValidator.validate(null, absolutePath).isOK()) {
SWTBotUtils.openTrace(PROJECT_NAME, absolutePath, TRACE_TYPE);
fBot.closeAllEditors();
openedTraces++;
if (openedTraces >= NUM_TRACES) {
break;
}
}
}
traceValidator.dispose();
/* finish waiting for eclipse to load */
WaitUtils.waitForJobs();
}
/** Test Class setup */
@BeforeClass
public static void init() {
SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
SWTBotUtils.initialize();
SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
fLogger.removeAllAppenders();
fLogger.addAppender(new NullAppender());
fBot = new SWTWorkbenchBot();
/* finish waiting for eclipse to load */
WaitUtils.waitForJobs();
importProfiles();
}
/** Test Class setup */
@BeforeClass
public static void beforeInit() {
SWTBotUtils.initialize();
/* set up for swtbot */
SWTBotPreferences.TIMEOUT = 50000; /* 50 second timeout */
fLogger.removeAllAppenders();
fLogger.addAppender(new NullAppender());
fBot = new SWTWorkbenchBot();
SWTBotUtils.closeView("welcome", fBot);
}
/**
* Class setup
*/
@BeforeClass
public static void init() {
SWTBotUtils.initialize();
fBot = new SWTWorkbenchBot();
fLogger.removeAllAppenders();
fLogger.addAppender(new NullAppender());
}
/** Test Class setup */
@BeforeClass
public static void init() {
SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
SWTBotUtils.initialize();
SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
fLogger.removeAllAppenders();
fLogger.addAppender(new NullAppender());
fBot = new SWTWorkbenchBot();
/* finish waiting for eclipse to load */
WaitUtils.waitForJobs();
}
/** Test Class setup */
@BeforeClass
public static void init() {
SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
SWTBotUtils.initialize();
SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
fLogger.removeAllAppenders();
fLogger.addAppender(new NullAppender());
fBot = new SWTWorkbenchBot();
/* finish waiting for eclipse to load */
WaitUtils.waitForJobs();
}
/**
* Constructor used for MySQL
*
* @param host
* @param port
* @param database
* @param username
* @param password
* @throws SQLException
*/
public DataSourceHandler(final String host, final String port, final String database, final String username, final String password) throws SQLException{
// Check database's informations and init connection
this.host = Preconditions.checkNotNull(host);
this.port = Preconditions.checkNotNull(port);
this.database = Preconditions.checkNotNull(database);
this.username = Preconditions.checkNotNull(username);
this.password = Preconditions.checkNotNull(password);
BAT.getInstance().getLogger().config("Initialization of HikariCP in progress ...");
BasicConfigurator.configure(new NullAppender());
ds = new HikariDataSource();
ds.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database +
"?useLegacyDatetimeCode=false&serverTimezone=" + TimeZone.getDefault().getID());
ds.setUsername(this.username);
ds.setPassword(this.password);
ds.addDataSourceProperty("cachePrepStmts", "true");
ds.setMaximumPoolSize(8);
try {
final Connection conn = ds.getConnection();
int intOffset = Calendar.getInstance().getTimeZone().getOffset(Calendar.getInstance().getTimeInMillis()) / 1000;
String offset = String.format("%02d:%02d", Math.abs(intOffset / 3600), Math.abs((intOffset / 60) % 60));
offset = (intOffset >= 0 ? "+" : "-") + offset;
conn.createStatement().executeQuery("SET time_zone='" + offset + "';");
conn.close();
BAT.getInstance().getLogger().config("BoneCP is loaded !");
} catch (final SQLException e) {
BAT.getInstance().getLogger().severe("BAT encounters a problem during the initialization of the database connection."
+ " Please check your logins and database configuration.");
if(e.getCause() instanceof CommunicationsException){
BAT.getInstance().getLogger().severe(e.getCause().getMessage());
}
if(BAT.getInstance().getConfiguration().isDebugMode()){
BAT.getInstance().getLogger().log(Level.SEVERE, e.getMessage(), e);
}
throw e;
}
sqlite = false;
}
@BeforeEach
public void setupAppender() {
appender = spy(new NullAppender());
logger.addAppender(appender);
}
@BeforeClass
public static void configureLogger() throws Exception {
BasicConfigurator.configure(new NullAppender());
}
@BeforeClass
public static void configureLog4J() {
BasicConfigurator.configure(new NullAppender());
}
@BeforeClass
public static void configureLog4J() {
BasicConfigurator.configure(new NullAppender());
}
private static boolean init() {
if (!Logger.getRootLogger().getAllAppenders().hasMoreElements())
Logger.getRootLogger().addAppender(new NullAppender());
return true;
}
/**
* Simply configure the primary log4j Loggers to send all output to the bit bucket.
*/
public static void configurePrimaryLoggerToSwallowLogs() {
org.apache.log4j.BasicConfigurator.configure(new NullAppender());
}