org.apache.commons.logging.impl.Log4JLogger Java Examples

The following examples show how to use org.apache.commons.logging.impl.Log4JLogger. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestAuditLogs.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private void configureAuditLogs() throws IOException {
  // Shutdown the LogManager to release all logger open file handles.
  // Unfortunately, Apache commons logging library does not provide
  // means to release underlying loggers. For additional info look up
  // commons library FAQ.
  LogManager.shutdown();

  File file = new File(auditLogFile);
  if (file.exists()) {
    assertTrue(file.delete());
  }
  Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
  // disable logging while the cluster startup preps files
  logger.setLevel(Level.OFF);
  PatternLayout layout = new PatternLayout("%m%n");
  RollingFileAppender appender = new RollingFileAppender(layout, auditLogFile);
  logger.addAppender(appender);
}
 
Example #2
Source File: TestAuditLogs.java    From big-c with Apache License 2.0 6 votes vote down vote up
private void configureAuditLogs() throws IOException {
  // Shutdown the LogManager to release all logger open file handles.
  // Unfortunately, Apache commons logging library does not provide
  // means to release underlying loggers. For additional info look up
  // commons library FAQ.
  LogManager.shutdown();

  File file = new File(auditLogFile);
  if (file.exists()) {
    assertTrue(file.delete());
  }
  Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
  // disable logging while the cluster startup preps files
  logger.setLevel(Level.OFF);
  PatternLayout layout = new PatternLayout("%m%n");
  RollingFileAppender appender = new RollingFileAppender(layout, auditLogFile);
  logger.addAppender(appender);
}
 
Example #3
Source File: TestExprLookup.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
@Test
public void testLookup() throws Exception
{
    final ConsoleAppender app = new ConsoleAppender(new SimpleLayout());
    final Log log = LogFactory.getLog("TestLogger");
    final Logger logger = ((Log4JLogger)log).getLogger();
    logger.addAppender(app);
    logger.setLevel(Level.DEBUG);
    logger.setAdditivity(false);
    final ExprLookup.Variables vars = new ExprLookup.Variables();
    vars.add(new ExprLookup.Variable("String", org.apache.commons.lang3.StringUtils.class));
    vars.add(new ExprLookup.Variable("Util", new Utility("Hello")));
    vars.add(new ExprLookup.Variable("System", "Class:java.lang.System"));
    final XMLConfiguration config = loadConfig();
    final ConfigurationLogger testLogger = new ConfigurationLogger("TestLogger");
    config.setLogger(testLogger);
    final ExprLookup lookup = new ExprLookup(vars);
    lookup.setInterpolator(config.getInterpolator());
    lookup.setLogger(testLogger);
    String str = lookup.lookup(PATTERN1);
    assertTrue(str.startsWith("Goodbye"));
    str = lookup.lookup(PATTERN2);
    assertTrue("Incorrect value: " + str, str.equals("value Some text"));
    logger.removeAppender(app);
}
 
Example #4
Source File: TestHftpFileSystem.java    From RDFS with Apache License 2.0 6 votes vote down vote up
/**
 * Setup hadoop mini-cluster for test.
 */
private static void oneTimeSetUp() throws IOException {
  ((Log4JLogger)HftpFileSystem.LOG).getLogger().setLevel(Level.ALL);

  final long seed = RAN.nextLong();
  System.out.println("seed=" + seed);
  RAN.setSeed(seed);

  config = new Configuration();
  config.set("slave.host.name", "localhost");

  cluster = new MiniDFSCluster(config, 2, true, null);
  hdfs = cluster.getFileSystem();
  final String hftpuri = "hftp://" + config.get("dfs.http.address");
  System.out.println("hftpuri=" + hftpuri);
  hftpFs = (HftpFileSystem) new Path(hftpuri).getFileSystem(config);
}
 
Example #5
Source File: TestFsck.java    From RDFS with Apache License 2.0 5 votes vote down vote up
static String runFsck(Configuration conf, int expectedErrCode,
                      boolean checkErrorCode, String... path)
  throws Exception {
  ByteArrayOutputStream bStream = new ByteArrayOutputStream();
  PrintStream out = new PrintStream(bStream, true);
  ((Log4JLogger) FSPermissionChecker.LOG).getLogger().setLevel(Level.ALL);
  int errCode = ToolRunner.run(new DFSck(conf, out), path);
  if (checkErrorCode) {
    assertEquals(expectedErrCode, errCode);
  }
  ((Log4JLogger) FSPermissionChecker.LOG).getLogger().setLevel(Level.INFO);
  return bStream.toString();
}
 
Example #6
Source File: TestPread.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testPreadDFSNoChecksum() throws IOException {
  Configuration conf = new Configuration();
  ((Log4JLogger)DataTransferProtocol.LOG).getLogger().setLevel(Level.ALL);
  dfsPreadTest(conf, false, false);
  dfsPreadTest(conf, true, false);
}
 
Example #7
Source File: TestFiPipelines.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static void initLoggers() {
  ((Log4JLogger) NameNode.stateChangeLog).getLogger().setLevel(Level.ALL);
  ((Log4JLogger) LogFactory.getLog(FSNamesystem.class)).getLogger().setLevel(Level.ALL);
  ((Log4JLogger) DataNode.LOG).getLogger().setLevel(Level.ALL);
  ((Log4JLogger) TestFiPipelines.LOG).getLogger().setLevel(Level.ALL);
  ((Log4JLogger) DFSClient.LOG).getLogger().setLevel(Level.ALL);
  ((Log4JLogger) FiTestUtil.LOG).getLogger().setLevel(Level.ALL);
  ((Log4JLogger) BlockReceiverAspects.LOG).getLogger().setLevel(Level.ALL);
  ((Log4JLogger) DFSClientAspects.LOG).getLogger().setLevel(Level.ALL);
}
 
Example #8
Source File: TestFsck.java    From big-c with Apache License 2.0 5 votes vote down vote up
/** Sets up log4j logger for auditlogs */
private void setupAuditLogs() throws IOException {
  File file = new File(auditLogFile);
  if (file.exists()) {
    file.delete();
  }
  Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
  logger.setLevel(Level.INFO);
  PatternLayout layout = new PatternLayout("%m%n");
  RollingFileAppender appender = new RollingFileAppender(layout, auditLogFile);
  logger.addAppender(appender);
}
 
Example #9
Source File: TestFsck.java    From big-c with Apache License 2.0 5 votes vote down vote up
static String runFsck(Configuration conf, int expectedErrCode, 
                      boolean checkErrorCode,String... path)
                      throws Exception {
  ByteArrayOutputStream bStream = new ByteArrayOutputStream();
  PrintStream out = new PrintStream(bStream, true);
  ((Log4JLogger)FSPermissionChecker.LOG).getLogger().setLevel(Level.ALL);
  int errCode = ToolRunner.run(new DFSck(conf, out), path);
  if (checkErrorCode) {
    assertEquals(expectedErrCode, errCode);
  }
  ((Log4JLogger)FSPermissionChecker.LOG).getLogger().setLevel(Level.INFO);
  FSImage.LOG.error("OUTPUT = " + bStream.toString());
  return bStream.toString();
}
 
Example #10
Source File: TestAuditLogs.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void verifyAuditLogsCheckPattern(boolean expectSuccess, int ndupe, Pattern pattern)
    throws IOException {
  // Turn off the logs
  Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
  logger.setLevel(Level.OFF);

  // Close the appenders and force all logs to be flushed
  Enumeration<?> appenders = logger.getAllAppenders();
  while (appenders.hasMoreElements()) {
    Appender appender = (Appender)appenders.nextElement();
    appender.close();
  }

  BufferedReader reader = new BufferedReader(new FileReader(auditLogFile));
  String line = null;
  boolean ret = true;
  boolean patternMatches = false;

  try {
      for (int i = 0; i < ndupe; i++) {
        line = reader.readLine();
        assertNotNull(line);
        patternMatches |= pattern.matcher(line).matches();
        ret &= successPattern.matcher(line).matches();
      }
      assertNull("Unexpected event in audit log", reader.readLine());
      assertTrue("Expected audit event not found in audit log", patternMatches);
      assertTrue("Expected success=" + expectSuccess, ret == expectSuccess);
    } finally {
      reader.close();
    }
}
 
Example #11
Source File: TestAuditLogs.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void verifyAuditLogsRepeat(boolean expectSuccess, int ndupe)
    throws IOException {
  // Turn off the logs
  Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
  logger.setLevel(Level.OFF);

  // Close the appenders and force all logs to be flushed
  Enumeration<?> appenders = logger.getAllAppenders();
  while (appenders.hasMoreElements()) {
    Appender appender = (Appender)appenders.nextElement();
    appender.close();
  }

  BufferedReader reader = new BufferedReader(new FileReader(auditLogFile));
  String line = null;
  boolean ret = true;

  try {
    for (int i = 0; i < ndupe; i++) {
      line = reader.readLine();
      assertNotNull(line);
      assertTrue("Expected audit event not found in audit log",
          auditPattern.matcher(line).matches());
      ret &= successPattern.matcher(line).matches();
    }
    assertNull("Unexpected event in audit log", reader.readLine());
    assertTrue("Expected success=" + expectSuccess, ret == expectSuccess);
  } finally {
    reader.close();
  }
}
 
Example #12
Source File: TestAuditLogs.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Before
 public void setupCluster() throws Exception {
   // must configure prior to instantiating the namesystem because it
   // will reconfigure the logger if async is enabled
   configureAuditLogs();
   conf = new HdfsConfiguration();
   final long precision = 1L;
   conf.setLong(DFSConfigKeys.DFS_NAMENODE_ACCESSTIME_PRECISION_KEY, precision);
   conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 10000L);
   conf.setBoolean(DFSConfigKeys.DFS_WEBHDFS_ENABLED_KEY, true);
   conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_KEY, useAsyncLog);
   util = new DFSTestUtil.Builder().setName("TestAuditAllowed").
       setNumFiles(20).build();
   cluster = new MiniDFSCluster.Builder(conf).numDataNodes(4).build();
   fs = cluster.getFileSystem();
   util.createFiles(fs, fileName);

   // make sure the appender is what it's supposed to be
   Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
   @SuppressWarnings("unchecked")
   List<Appender> appenders = Collections.list(logger.getAllAppenders());
   assertEquals(1, appenders.size());
   assertEquals(useAsyncLog, appenders.get(0) instanceof AsyncAppender);
   
   fnames = util.getFileNames(fileName);
   util.waitReplication(fs, fileName, (short)3);
   userGroupInfo = UserGroupInformation.createUserForTesting(username, groups);
}
 
Example #13
Source File: TestDelegationToken.java    From big-c with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Test
public void testDelegationTokenWebHdfsApi() throws Exception {
  ((Log4JLogger)NamenodeWebHdfsMethods.LOG).getLogger().setLevel(Level.ALL);
  final String uri = WebHdfsFileSystem.SCHEME  + "://"
      + config.get(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY);
  //get file system as JobTracker
  final UserGroupInformation ugi = UserGroupInformation.createUserForTesting(
      "JobTracker", new String[]{"user"});
  final WebHdfsFileSystem webhdfs = ugi.doAs(
      new PrivilegedExceptionAction<WebHdfsFileSystem>() {
    @Override
    public WebHdfsFileSystem run() throws Exception {
      return (WebHdfsFileSystem)FileSystem.get(new URI(uri), config);
    }
  });

  { //test addDelegationTokens(..)
    Credentials creds = new Credentials();
    final Token<?> tokens[] = webhdfs.addDelegationTokens("JobTracker", creds);
    Assert.assertEquals(1, tokens.length);
    Assert.assertEquals(1, creds.numberOfTokens());
    Assert.assertSame(tokens[0], creds.getAllTokens().iterator().next());
    checkTokenIdentifier(ugi, tokens[0]);
    final Token<?> tokens2[] = webhdfs.addDelegationTokens("JobTracker", creds);
    Assert.assertEquals(0, tokens2.length);
  }
}
 
Example #14
Source File: TestWebHDFS.java    From big-c with Apache License 2.0 5 votes vote down vote up
/** Test client retry with namenode restarting. */
@Test(timeout=300000)
public void testNamenodeRestart() throws Exception {
  ((Log4JLogger)NamenodeWebHdfsMethods.LOG).getLogger().setLevel(Level.ALL);
  final Configuration conf = WebHdfsTestUtil.createConf();
  TestDFSClientRetries.namenodeRestartTest(conf, true);
}
 
Example #15
Source File: NNThroughputBenchmark.java    From RDFS with Apache License 2.0 5 votes vote down vote up
static void turnOffNameNodeLogging() {
  // change log level to ERROR: NameNode.LOG & NameNode.stateChangeLog
  ((Log4JLogger)NameNode.LOG).getLogger().setLevel(Level.ERROR);
  ((Log4JLogger)NameNode.stateChangeLog).getLogger().setLevel(Level.ERROR);
  ((Log4JLogger)NetworkTopology.LOG).getLogger().setLevel(Level.ERROR);
  ((Log4JLogger)FSNamesystem.LOG).getLogger().setLevel(Level.ERROR);
  ((Log4JLogger)FSNamesystem.auditLog).getLogger().setLevel(Level.ERROR);
  ((Log4JLogger)LeaseManager.LOG).getLogger().setLevel(Level.ERROR);
}
 
Example #16
Source File: TestFiPipelines.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private static void initLoggers() {
  ((Log4JLogger) NameNode.stateChangeLog).getLogger().setLevel(Level.ALL);
  ((Log4JLogger) LogFactory.getLog(FSNamesystem.class)).getLogger().setLevel(Level.ALL);
  ((Log4JLogger) DataNode.LOG).getLogger().setLevel(Level.ALL);
  ((Log4JLogger) TestFiPipelines.LOG).getLogger().setLevel(Level.ALL);
  ((Log4JLogger) DFSClient.LOG).getLogger().setLevel(Level.ALL);
  ((Log4JLogger) FiTestUtil.LOG).getLogger().setLevel(Level.ALL);
  ((Log4JLogger) BlockReceiverAspects.LOG).getLogger().setLevel(Level.ALL);
  ((Log4JLogger) DFSClientAspects.LOG).getLogger().setLevel(Level.ALL);
}
 
Example #17
Source File: TestPread.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testPreadDFSNoChecksum() throws IOException {
  Configuration conf = new Configuration();
  ((Log4JLogger)DataTransferProtocol.LOG).getLogger().setLevel(Level.ALL);
  dfsPreadTest(conf, false, false);
  dfsPreadTest(conf, true, false);
}
 
Example #18
Source File: NNThroughputBenchmark.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
static void turnOffNameNodeLogging() {
  // change log level to ERROR: NameNode.LOG & NameNode.stateChangeLog
  ((Log4JLogger)NameNode.LOG).getLogger().setLevel(Level.ERROR);
  ((Log4JLogger)NameNode.stateChangeLog).getLogger().setLevel(Level.ERROR);
  ((Log4JLogger)NetworkTopology.LOG).getLogger().setLevel(Level.ERROR);
  ((Log4JLogger)FSNamesystem.LOG).getLogger().setLevel(Level.ERROR);
  ((Log4JLogger)FSNamesystem.auditLog).getLogger().setLevel(Level.ERROR);
  ((Log4JLogger)LeaseManager.LOG).getLogger().setLevel(Level.ERROR);
}
 
Example #19
Source File: NNThroughputBenchmark.java    From RDFS with Apache License 2.0 5 votes vote down vote up
static void turnOffNameNodeLogging() {
	// change log level to ERROR: NameNode.LOG & NameNode.stateChangeLog
	((Log4JLogger) NameNode.LOG).getLogger().setLevel(Level.ERROR);
	((Log4JLogger) NameNode.stateChangeLog).getLogger().setLevel(
			Level.ERROR);
	((Log4JLogger) NetworkTopology.LOG).getLogger().setLevel(Level.ERROR);
	((Log4JLogger) FSNamesystem.LOG).getLogger().setLevel(Level.ERROR);
	((Log4JLogger) FSNamesystem.auditLog).getLogger().setLevel(Level.ERROR);
	((Log4JLogger) LeaseManager.LOG).getLogger().setLevel(Level.ERROR);
}
 
Example #20
Source File: TestWebHDFS.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/** Test client retry with namenode restarting. */
@Test(timeout=300000)
public void testNamenodeRestart() throws Exception {
  ((Log4JLogger)NamenodeWebHdfsMethods.LOG).getLogger().setLevel(Level.ALL);
  final Configuration conf = WebHdfsTestUtil.createConf();
  TestDFSClientRetries.namenodeRestartTest(conf, true);
}
 
Example #21
Source File: TestDelegationToken.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Test
public void testDelegationTokenWebHdfsApi() throws Exception {
  ((Log4JLogger)NamenodeWebHdfsMethods.LOG).getLogger().setLevel(Level.ALL);
  final String uri = WebHdfsFileSystem.SCHEME  + "://"
      + config.get(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY);
  //get file system as JobTracker
  final UserGroupInformation ugi = UserGroupInformation.createUserForTesting(
      "JobTracker", new String[]{"user"});
  final WebHdfsFileSystem webhdfs = ugi.doAs(
      new PrivilegedExceptionAction<WebHdfsFileSystem>() {
    @Override
    public WebHdfsFileSystem run() throws Exception {
      return (WebHdfsFileSystem)FileSystem.get(new URI(uri), config);
    }
  });

  { //test addDelegationTokens(..)
    Credentials creds = new Credentials();
    final Token<?> tokens[] = webhdfs.addDelegationTokens("JobTracker", creds);
    Assert.assertEquals(1, tokens.length);
    Assert.assertEquals(1, creds.numberOfTokens());
    Assert.assertSame(tokens[0], creds.getAllTokens().iterator().next());
    checkTokenIdentifier(ugi, tokens[0]);
    final Token<?> tokens2[] = webhdfs.addDelegationTokens("JobTracker", creds);
    Assert.assertEquals(0, tokens2.length);
  }
}
 
Example #22
Source File: TestAuditLogs.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Before
 public void setupCluster() throws Exception {
   // must configure prior to instantiating the namesystem because it
   // will reconfigure the logger if async is enabled
   configureAuditLogs();
   conf = new HdfsConfiguration();
   final long precision = 1L;
   conf.setLong(DFSConfigKeys.DFS_NAMENODE_ACCESSTIME_PRECISION_KEY, precision);
   conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 10000L);
   conf.setBoolean(DFSConfigKeys.DFS_WEBHDFS_ENABLED_KEY, true);
   conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_KEY, useAsyncLog);
   util = new DFSTestUtil.Builder().setName("TestAuditAllowed").
       setNumFiles(20).build();
   cluster = new MiniDFSCluster.Builder(conf).numDataNodes(4).build();
   fs = cluster.getFileSystem();
   util.createFiles(fs, fileName);

   // make sure the appender is what it's supposed to be
   Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
   @SuppressWarnings("unchecked")
   List<Appender> appenders = Collections.list(logger.getAllAppenders());
   assertEquals(1, appenders.size());
   assertEquals(useAsyncLog, appenders.get(0) instanceof AsyncAppender);
   
   fnames = util.getFileNames(fileName);
   util.waitReplication(fs, fileName, (short)3);
   userGroupInfo = UserGroupInformation.createUserForTesting(username, groups);
}
 
Example #23
Source File: TestFsck.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
static String runFsck(Configuration conf, int expectedErrCode, 
                      boolean checkErrorCode,String... path) 
                      throws Exception {
  PrintStream oldOut = System.out;
  ByteArrayOutputStream bStream = new ByteArrayOutputStream();
  PrintStream newOut = new PrintStream(bStream, true);
  System.setOut(newOut);
  ((Log4JLogger)PermissionChecker.LOG).getLogger().setLevel(Level.ALL);
  int errCode = ToolRunner.run(new DFSck(conf), path);
  if (checkErrorCode)
    assertEquals(expectedErrCode, errCode);
  ((Log4JLogger)PermissionChecker.LOG).getLogger().setLevel(Level.INFO);
  System.setOut(oldOut);
  return bStream.toString();
}
 
Example #24
Source File: TestFsck.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/** Sets up log4j logger for auditlogs */
private void setupAuditLogs() throws IOException {
  File file = new File(auditLogFile);
  if (file.exists()) {
    file.delete();
  }
  Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
  logger.setLevel(Level.INFO);
  PatternLayout layout = new PatternLayout("%m%n");
  RollingFileAppender appender = new RollingFileAppender(layout, auditLogFile);
  logger.addAppender(appender);
}
 
Example #25
Source File: TestFsck.java    From hadoop with Apache License 2.0 5 votes vote down vote up
static String runFsck(Configuration conf, int expectedErrCode, 
                      boolean checkErrorCode,String... path)
                      throws Exception {
  ByteArrayOutputStream bStream = new ByteArrayOutputStream();
  PrintStream out = new PrintStream(bStream, true);
  ((Log4JLogger)FSPermissionChecker.LOG).getLogger().setLevel(Level.ALL);
  int errCode = ToolRunner.run(new DFSck(conf, out), path);
  if (checkErrorCode) {
    assertEquals(expectedErrCode, errCode);
  }
  ((Log4JLogger)FSPermissionChecker.LOG).getLogger().setLevel(Level.INFO);
  FSImage.LOG.error("OUTPUT = " + bStream.toString());
  return bStream.toString();
}
 
Example #26
Source File: TestAuditLogs.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void verifyAuditLogsCheckPattern(boolean expectSuccess, int ndupe, Pattern pattern)
    throws IOException {
  // Turn off the logs
  Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
  logger.setLevel(Level.OFF);

  // Close the appenders and force all logs to be flushed
  Enumeration<?> appenders = logger.getAllAppenders();
  while (appenders.hasMoreElements()) {
    Appender appender = (Appender)appenders.nextElement();
    appender.close();
  }

  BufferedReader reader = new BufferedReader(new FileReader(auditLogFile));
  String line = null;
  boolean ret = true;
  boolean patternMatches = false;

  try {
      for (int i = 0; i < ndupe; i++) {
        line = reader.readLine();
        assertNotNull(line);
        patternMatches |= pattern.matcher(line).matches();
        ret &= successPattern.matcher(line).matches();
      }
      assertNull("Unexpected event in audit log", reader.readLine());
      assertTrue("Expected audit event not found in audit log", patternMatches);
      assertTrue("Expected success=" + expectSuccess, ret == expectSuccess);
    } finally {
      reader.close();
    }
}
 
Example #27
Source File: TestAuditLogs.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void verifyAuditLogsRepeat(boolean expectSuccess, int ndupe)
    throws IOException {
  // Turn off the logs
  Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
  logger.setLevel(Level.OFF);

  // Close the appenders and force all logs to be flushed
  Enumeration<?> appenders = logger.getAllAppenders();
  while (appenders.hasMoreElements()) {
    Appender appender = (Appender)appenders.nextElement();
    appender.close();
  }

  BufferedReader reader = new BufferedReader(new FileReader(auditLogFile));
  String line = null;
  boolean ret = true;

  try {
    for (int i = 0; i < ndupe; i++) {
      line = reader.readLine();
      assertNotNull(line);
      assertTrue("Expected audit event not found in audit log",
          auditPattern.matcher(line).matches());
      ret &= successPattern.matcher(line).matches();
    }
    assertNull("Unexpected event in audit log", reader.readLine());
    assertTrue("Expected success=" + expectSuccess, ret == expectSuccess);
  } finally {
    reader.close();
  }
}
 
Example #28
Source File: GenericTestUtils.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
public static LogCapturer captureLogs(Log l) {
  Logger logger = ((Log4JLogger) l).getLogger();
  return new LogCapturer(logger);
}
 
Example #29
Source File: HttpRequestLog.java    From big-c with Apache License 2.0 4 votes vote down vote up
public static RequestLog getRequestLog(String name) {

    String lookup = serverToComponent.get(name);
    if (lookup != null) {
      name = lookup;
    }
    String loggerName = "http.requests." + name;
    String appenderName = name + "requestlog";
    Log logger = LogFactory.getLog(loggerName);

    boolean isLog4JLogger;;
    try {
      isLog4JLogger = logger instanceof Log4JLogger;
    } catch (NoClassDefFoundError err) {
      // In some dependent projects, log4j may not even be on the classpath at
      // runtime, in which case the above instanceof check will throw
      // NoClassDefFoundError.
      LOG.debug("Could not load Log4JLogger class", err);
      isLog4JLogger = false;
    }
    if (isLog4JLogger) {
      Log4JLogger httpLog4JLog = (Log4JLogger)logger;
      Logger httpLogger = httpLog4JLog.getLogger();
      Appender appender = null;

      try {
        appender = httpLogger.getAppender(appenderName);
      } catch (LogConfigurationException e) {
        LOG.warn("Http request log for " + loggerName
            + " could not be created");
        throw e;
      }

      if (appender == null) {
        LOG.info("Http request log for " + loggerName
            + " is not defined");
        return null;
      }

      if (appender instanceof HttpRequestLogAppender) {
        HttpRequestLogAppender requestLogAppender
          = (HttpRequestLogAppender)appender;
        NCSARequestLog requestLog = new NCSARequestLog();
        requestLog.setFilename(requestLogAppender.getFilename());
        requestLog.setRetainDays(requestLogAppender.getRetainDays());
        return requestLog;
      }
      else {
        LOG.warn("Jetty request log for " + loggerName
            + " was of the wrong class");
        return null;
      }
    }
    else {
      LOG.warn("Jetty request log can only be enabled using Log4j");
      return null;
    }
  }
 
Example #30
Source File: GenericTestUtils.java    From big-c with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static void disableLog(Log log) {
  // We expect that commons-logging is a wrapper around Log4j.
  disableLog((Log4JLogger) log);
}