org.apache.log4j.Level源码实例Demo

类org.apache.log4j.Level源码实例Demo

下面列出了org.apache.log4j.Level 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: MtgDesktopCompanion   文件: IndexerTests.java
@Before
public void createCards()
{
	
	MTGLogger.changeLevel(Level.TRACE);
	
	mc = new MagicCard();
	mc.setName("Black Lotus");
	mc.setLayout(MTGLayout.NORMAL);
	mc.setCost("{0}");
	mc.setCmc(0);
	mc.getTypes().add("Artifact");
	mc.setReserved(true);
	mc.setText("{T}, Sacrifice Black Lotus: Add three mana of any one color to your mana pool.");
	mc.setRarity(MTGRarity.RARE);
	mc.setArtist("Christopher Rush");
				 ed = new MagicEdition();
				 ed.setId("lea");
				 ed.setSet("Limited Edition Alpha");
				 ed.setBorder("Black");
				 ed.setRarity("Rare");
				 ed.setArtist("Christopher Rush");
				 ed.setMultiverseid("3");
	mc.getEditions().add(ed);
	mc.getCurrentSet().setNumber("232");
}
 
源代码2 项目: celos   文件: Util.java
public static void setupLogging(File logDir) {
    System.getProperties().setProperty("log4j.defaultInitOverride", "true");

    RollingFileAppender appender = new RollingFileAppender();
    appender.setFile(new File(logDir, "celos.log").getAbsolutePath());
    appender.setAppend(true);

    TimeBasedRollingPolicy rollingPolicy = new TimeBasedRollingPolicy();
    rollingPolicy.setFileNamePattern(new File(logDir, "celos-%d{yyyy-MM-dd}.log").getAbsolutePath());
    appender.setRollingPolicy(rollingPolicy);

    PatternLayout patternLayout = new PatternLayout();
    patternLayout.setConversionPattern("[%d{YYYY-MM-dd HH:mm:ss.SSS}] %-5p: %m%n");
    appender.setLayout(patternLayout);

    appender.activateOptions();
    Logger.getRootLogger().addAppender(appender);
    Logger.getRootLogger().setLevel(Level.INFO);
}
 
源代码3 项目: suro   文件: TestLog4jAppender.java
@Test
public void testFile() throws Exception {
    appender.setAsyncQueueType("file");
    appender.setAsyncFileQueuePath(tempDir.newFolder().getAbsolutePath());
    appender.setLoadBalancerType("static");
    appender.setLoadBalancerServer(TestConnectionPool.createConnectionString(servers));
    appender.activateOptions();

    LoggingEvent event = mock(LoggingEvent.class);
    when(event.getMessage()).thenReturn(createEventMap());
    when(event.getLevel()).thenReturn(Level.INFO);

    appender.append(event);

    // Make sure client has enough time to drain the intermediary message queue
    waitAndVerify(15000, new Runnable() {
        public void run() {
            assertEquals(appender.getSentMessageCount(), 1);
        }
    });


    appender.close();
}
 
源代码4 项目: swift-t   文件: Logging.java
private static void setupLoggingToFile(Logger stcLogger, String logfile,
    boolean trace) {
  Layout layout = new PatternLayout("%-5p %m%n");
  boolean append = false;
  try {
    FileAppender appender = new FileAppender(layout, logfile, append);
    Level threshold;
    if (trace) {
      threshold = Level.TRACE;
    } else {
      threshold = Level.DEBUG;
    }
    appender.setThreshold(threshold);
    stcLogger.addAppender(appender);
    stcLogger.setLevel(threshold);
  } catch (IOException e) {
    System.out.println(e.getMessage());
    System.exit(ExitCode.ERROR_IO.code());
  }
}
 
源代码5 项目: clust4j   文件: Log.java
public static void setLogLevel(int log_level) throws IllegalArgumentException {
	Level l;
	
	switch(log_level) {
		case 1: l = Level.TRACE; break;
		case 2: l = Level.DEBUG; break;
		case 3: l = Level.INFO;	 break;
		case 4: l = Level.WARN;  break;
		case 5: l = Level.ERROR; break;
		case 6: l = Level.FATAL; break;
		default:
			throw new IllegalArgumentException("Illegal log level: "+ log_level);
	}
	
	_logger.setLevel(l);
	String inf = "Set log level to " + l;
	System.out.println(inf);
	_logger.info(inf);
}
 
源代码6 项目: epcis   文件: MongoSubscriptionTask.java
private void updateInitialRecordTime(String subscriptionID, String initialRecordTime) {

		MongoCollection<BsonDocument> collection = Configuration.mongoDatabase.getCollection("Subscription",
				BsonDocument.class);

		BsonDocument subscription = collection.find(new BsonDocument("subscriptionID", new BsonString(subscriptionID)))
				.first();
		subscription.put("initialRecordTime", new BsonString(initialRecordTime));

		if (subscription != null) {
			collection.findOneAndReplace(new BsonDocument("subscriptionID", new BsonString(subscriptionID)),
					subscription);
		}
		Configuration.logger.log(Level.INFO,
				"InitialRecordTime of Subscription ID: " + subscriptionID + " is updated to DB. ");
	}
 
源代码7 项目: hazelcast-simulator   文件: MultiValueMapTest.java
@TimeStep(prob = -1)
public void query(ThreadState state, Probe probe, @StartNanos long startNanos) {
    int key = state.getRandomKey();
    Predicate predicate = Predicates.equal("payloadField[any]", key);
    Collection<Object> result = null;
    try {
        result = map.values(predicate);
    } finally {
        probe.done(startNanos);
    }

    if (throttlingLogger.requestLogSlot()) {
        throttlingLogger.logInSlot(Level.INFO,
                format("Query 'payloadField[any]= %d' returned %d results.", key, result.size()));
    }

    for (Object resultSillySequence : result) {
        state.assertValidSequence(resultSillySequence);
    }
}
 
源代码8 项目: ats-framework   文件: AutoLevel.java
/**
   Convert the string passed as argument to a level. If the
   conversion fails, then this method returns the value of
   <code>defaultLevel</code>.  
*/
public static Level toLevel(
                             String sArg,
                             Level defaultLevel ) {

    if (sArg == null)
        return defaultLevel;

    String s = sArg.toUpperCase();

    if ("SYSTEM".equals(s)) {
        return AutoLevel.SYSTEM;
    } else {
        return Level.toLevel(sArg, defaultLevel);
    }
}
 
源代码9 项目: ignite   文件: JavaIgniteDataFrameExample.java
/** */
public static void main(String args[]) {

    setupServerAndData();

    //Creating spark session.
    SparkSession spark = SparkSession
            .builder()
            .appName("JavaIgniteDataFrameExample")
            .master("local")
            .config("spark.executor.instances", "2")
            .getOrCreate();

    // Adjust the logger to exclude the logs of no interest.
    Logger.getRootLogger().setLevel(Level.ERROR);
    Logger.getLogger("org.apache.ignite").setLevel(Level.INFO);

    // Executing examples.

    sparkDSLExample(spark);

    nativeSparkSqlExample(spark);

    Ignition.stop(false);
}
 
源代码10 项目: spliceengine   文件: LogManager.java
@Override
public void setLoggerLevel(String loggerName, String levelName) {
    String prospectiveLevel = null;
    if (levelName != null) {
        prospectiveLevel = levelName.trim();
    }
    if (prospectiveLevel == null ||
            prospectiveLevel.isEmpty() ||
            ! LOG4JLEVELS.contains(prospectiveLevel.toUpperCase())) {
        throw new IllegalArgumentException("Log level \"" + levelName +
                "\" is not valid.");
    }
    Logger logger = Logger.getLogger(loggerName);
    if (logger == null) {
        throw new IllegalArgumentException("Logger \"" + loggerName +
                "\" does not exist");
    }
    Level newLevel = Level.toLevel(levelName);
    logger.setLevel(newLevel);
}
 
源代码11 项目: big-c   文件: TestGroupFallback.java
@Test
public void testNetgroupWithFallback() throws Exception {
  LOG.info("running 'mvn -Pnative -DTestGroupFallback clear test' will " +
      "test the normal path and 'mvn -DTestGroupFallback clear test' will" +
      " test the fall back functionality");
  Logger.getRootLogger().setLevel(Level.DEBUG);
  Configuration conf = new Configuration();
  conf.set(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING,
      "org.apache.hadoop.security.JniBasedUnixGroupsNetgroupMappingWithFallback");

  Groups groups = new Groups(conf);

  String username = System.getProperty("user.name");
  List<String> groupList = groups.getGroups(username);

  LOG.info(username + " has GROUPS: " + groupList.toString());
  assertTrue(groupList.size() > 0);
}
 
源代码12 项目: AndroidMvc   文件: BaseTest.java
@BeforeClass
public static void beforeClass() {
    ConsoleAppender console = new ConsoleAppender(); //create appender
    //configure the appender
    String PATTERN = "%d [%p] %C{1}: %m%n";
    console.setLayout(new PatternLayout(PATTERN));
    console.setThreshold(Level.DEBUG);
    console.activateOptions();
    //add appender to any Logger (here is root)
    Logger.getRootLogger().addAppender(console);
}
 
源代码13 项目: big-c   文件: TestBlockScanner.java
@Before
public void before() {
  BlockScanner.Conf.allowUnitTestSettings = true;
  GenericTestUtils.setLogLevel(BlockScanner.LOG, Level.ALL);
  GenericTestUtils.setLogLevel(VolumeScanner.LOG, Level.ALL);
  GenericTestUtils.setLogLevel(FsVolumeImpl.LOG, Level.ALL);
}
 
源代码14 项目: sailfish-core   文件: LoggingConfigurator.java
@Override
public void registerLogger(@NotNull Object obj, @NotNull ServiceName serviceName) {
    String loggerName = ILoggingConfigurator.getLoggerName(obj);

    Logger log = LogManager.exists(loggerName);

    if (log == null) {
        throw new EPSCommonException(String.format("Logger with name '%s' doesn`t exists", loggerName));
    }

    try {
        synchronized (lock) {
            DailyMaxRollingFileAppender appender;
            if (loggingConfiguration.isIndividualAppendersEnabled()) {
                appender = getOrCreateServiceAppender(serviceName);
            } else {
                appender = getOrCreateMainAppender();
            }

            log.addAppender(appender);
            serviceLoggers.put(serviceName, loggerName);
        }
    } catch (RuntimeException e) {
        if (logger.isEnabledFor(Level.ERROR)) {
            logger.error(String.format("Failed to register logger '%s' for service: %s", loggerName, serviceName), e);
        }
    }
}
 
源代码15 项目: open-Autoscaler   文件: OperationREST.java
@PUT
@Path("/log/{level}")
public Response setLogLevel( @PathParam("level") final String level, @QueryParam("package") final String packageName) {

	String targetLoggerName = "org.cloudfoundry.autoscaler";
	
	if (packageName != null &&  !packageName.isEmpty())
		targetLoggerName = packageName; 
	
	Logger targetLogger = LogManager.getLogger(targetLoggerName);
	
	if (level.equalsIgnoreCase("INFO"))
		targetLogger.setLevel(Level.INFO);
	else if (level.equalsIgnoreCase("DEBUG"))
		targetLogger.setLevel(Level.DEBUG);
	else if (level.equalsIgnoreCase("ERROR"))
		targetLogger.setLevel(Level.ERROR);
	else if (level.equalsIgnoreCase("WARN"))
		targetLogger.setLevel(Level.WARN);
	else if (level.equalsIgnoreCase("FATAL"))
		targetLogger.setLevel(Level.FATAL);
	else if (level.equalsIgnoreCase("TRACE"))
		targetLogger.setLevel(Level.TRACE);
	else if (level.equalsIgnoreCase("OFF"))
		targetLogger.setLevel(Level.OFF);
	else if (level.equalsIgnoreCase("ALL"))
		targetLogger.setLevel(Level.ALL);
	
	logger.info("Log level " + level.toUpperCase() + " is set");
	return RestApiResponseHandler.getResponseOk();        
    
}
 
源代码16 项目: Bats   文件: LogWriter.java
private void writeToLog(final String s) {
  if ((s == null) || s.isEmpty()) {
    return;
  }

  switch(level) {
  case Level.DEBUG_INT:
    logger.debug(s);
    break;

  case Level.ERROR_INT:
    logger.error(s);
    break;

  case Level.INFO_INT:
    logger.info(s);
    break;

  case Level.TRACE_INT:
    logger.trace(s);
    break;

  case Level.WARN_INT:
    logger.warn(s);
    break;

  default:
    throw new IllegalStateException();
  }
}
 
源代码17 项目: olat   文件: PackageTranslator.java
/**
*/
  @Override
  public String translate(String key, String[] args, Level missingTranslationLogLevel) {
      String val = translate(key, args, false);
      // if still null -> fallback to default locale (if not in debug mode)
      if (val == null) {
          if (Settings.isDebuging()) {
              val = getErrorMessage(key);
          } else {
              // try with fallBackToDefaultLocale
              val = translate(key, args, true);
          }
      }
      // else value got translated or there is at least an error message telling
      // which key was not found.
      // Note: val may be null if there is a localstrings file missing in the default language. use the online translation tool to double-check

      // Error: ! even in default language: missing translation key!
      if (val == null) {
          val = getErrorMessage(key);
          // TODO: 13.02.2009 Workaround to fix shibboleth-attribute WARN : 'no translation ... in org.olat.presentation.course.condition...'
          if (!packageName.startsWith("org.olat.presentation.course.condition")) {
              if (missingTranslationLogLevel != null && !missingTranslationLogLevel.equals(Level.OFF)) {
                  if (missingTranslationLogLevel.equals(Level.ERROR)) {
                      log.error(val, null);
                  } else if (missingTranslationLogLevel.equals(Level.WARN)) {
                      log.warn(val, null);
                  } else if (missingTranslationLogLevel.equals(Level.INFO)) {
                      log.info(val, null);
                  }
              }
          }
          // don't use error message in GUI for production, use key instead (OLAT-5896)
          if (!Settings.isDebuging()) {
              val = key;
          }
      }
      return val;
  }
 
源代码18 项目: dubbox   文件: LogUtil.java
public static int findMessage(Level expectedLevel, String expectedMessage) {
    int count = 0;
    List<Log> logList = DubboAppender.logList;
    for (int i = 0; i < logList.size(); i++) {
        Level logLevel = logList.get(i).getLogLevel();
        if (logLevel.equals(expectedLevel)) {
            String logMessage = logList.get(i).getLogMessage();
            if (logMessage.contains(expectedMessage)) count++;
        }
    }
    return count;
}
 
源代码19 项目: big-c   文件: NNThroughputBenchmark.java
static void setNameNodeLoggingLevel(Level logLevel) {
  LOG.fatal("Log level = " + logLevel.toString());
  // change log level to NameNode logs
  DFSTestUtil.setNameNodeLogLevel(logLevel);
  GenericTestUtils.setLogLevel(LogManager.getLogger(
          NetworkTopology.class.getName()), logLevel);
  GenericTestUtils.setLogLevel(LogManager.getLogger(
          Groups.class.getName()), logLevel);
}
 
源代码20 项目: datawave   文件: AbstractTableConfigHelperTest.java
@BeforeClass
public static void adjustLogLevels() {
    
    Level desiredLevel = Level.ALL;
    
    Logger log = Logger.getLogger(AbstractTableConfigHelperTest.class);
    AbstractTableConfigHelperTest.testDriverLevel = log.getLevel();
    log.setLevel(desiredLevel);
}
 
源代码21 项目: ratis   文件: LeaderElectionTests.java
@Test
public void testChangeLeader() throws Exception {
  RaftStorageTestUtils.setRaftLogWorkerLogLevel(Level.TRACE);
  LOG.info("Running testChangeLeader");
  final MiniRaftCluster cluster = newCluster(3);
  cluster.start();

  RaftPeerId leader = RaftTestUtil.waitForLeader(cluster).getId();
  for(int i = 0; i < 10; i++) {
    leader = RaftTestUtil.changeLeader(cluster, leader);
    ExitUtils.assertNotTerminated();
  }
  RaftStorageTestUtils.setRaftLogWorkerLogLevel(Level.INFO);
  cluster.shutdown();
}
 
源代码22 项目: kite   文件: TestLoadBalancingLog4jAppender.java
private void send(int numberOfMsgs) throws EventDeliveryException {
  for (int count = 0; count < numberOfMsgs; count++) {
    int level = count % 5;
    String msg = "This is log message number" + String.valueOf(count);
    fixture.log(Level.toLevel(level), msg);
  }
}
 
源代码23 项目: cloudstack   文件: KubernetesClusterStartWorker.java
private UserVm createKubernetesAdditionalMaster(final String joinIp, final int additionalMasterNodeInstance) throws ManagementServerException,
        ResourceUnavailableException, InsufficientCapacityException {
    UserVm additionalMasterVm = null;
    DataCenter zone = dataCenterDao.findById(kubernetesCluster.getZoneId());
    ServiceOffering serviceOffering = serviceOfferingDao.findById(kubernetesCluster.getServiceOfferingId());
    VirtualMachineTemplate template = templateDao.findById(kubernetesCluster.getTemplateId());
    List<Long> networkIds = new ArrayList<Long>();
    networkIds.add(kubernetesCluster.getNetworkId());
    Network.IpAddresses addrs = new Network.IpAddresses(null, null);
    long rootDiskSize = kubernetesCluster.getNodeRootDiskSize();
    Map<String, String> customParameterMap = new HashMap<String, String>();
    if (rootDiskSize > 0) {
        customParameterMap.put("rootdisksize", String.valueOf(rootDiskSize));
    }
    String hostName = getKubernetesClusterNodeAvailableName(String.format("%s-master-%d", kubernetesClusterNodeNamePrefix, additionalMasterNodeInstance + 1));
    String k8sMasterConfig = null;
    try {
        k8sMasterConfig = getKubernetesAdditionalMasterConfig(joinIp, Hypervisor.HypervisorType.VMware.equals(template.getHypervisorType()));
    } catch (IOException e) {
        logAndThrow(Level.ERROR, "Failed to read Kubernetes master configuration file", e);
    }
    String base64UserData = Base64.encodeBase64String(k8sMasterConfig.getBytes(StringUtils.getPreferredCharset()));
    additionalMasterVm = userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, networkIds, owner,
            hostName, hostName, null, null, null,
            null, BaseCmd.HTTPMethod.POST, base64UserData, kubernetesCluster.getKeyPair(),
            null, addrs, null, null, null, customParameterMap, null, null, null, null);
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info(String.format("Created master VM ID: %s, %s in the Kubernetes cluster ID: %s", additionalMasterVm.getUuid(), hostName, kubernetesCluster.getUuid()));
    }
    return additionalMasterVm;
}
 
源代码24 项目: big-c   文件: NNThroughputBenchmark.java
OperationStatsBase() {
  baseDir = BASE_DIR_NAME + "/" + getOpName();
  replication = (short) config.getInt(DFSConfigKeys.DFS_REPLICATION_KEY, 3);
  numOpsRequired = 10;
  numThreads = 3;
  logLevel = Level.ERROR;
  ugcRefreshCount = Integer.MAX_VALUE;
}
 
源代码25 项目: spacewalk   文件: SessionFilterDeadlockTest.java
public void testDeadlockFilter() throws Exception {
    // Make sure the chain blows up.
    chain = new MockFilterChain() {
        public void doFilter(ServletRequest req, ServletResponse resp)
        throws IOException, ServletException {
            throw new IOException("Test IOException");
        }
    };
    SessionFilter filter = new SessionFilter();
    HibernateFactory.getSession();
    int caughtCount = 0;

    Logger log = Logger.getLogger(SessionFilter.class);
    Level orig = log.getLevel();
    log.setLevel(Level.OFF);
    for (int i = 0; i < 5; i++) {
        try {
            filter.doFilter(request, response, chain);
        }
        catch (IOException ioe) {
            caughtCount++;
        }
    }
    log.setLevel(orig);
    assertTrue(caughtCount == 5);
    HibernateFactory.getSession();
    assertTrue(HibernateFactory.inTransaction());
}
 
源代码26 项目: big-c   文件: BlockReaderTestUtil.java
public static void enableBlockReaderFactoryTracing() {
  LogManager.getLogger(BlockReaderFactory.class.getName()).setLevel(
      Level.TRACE);
  LogManager.getLogger(ShortCircuitCache.class.getName()).setLevel(
      Level.TRACE);
  LogManager.getLogger(ShortCircuitReplica.class.getName()).setLevel(
      Level.TRACE);
  LogManager.getLogger(BlockReaderLocal.class.getName()).setLevel(
      Level.TRACE);
}
 
源代码27 项目: nbp   文件: Configuration.java
/**
 * Close DEBUG model
 * 
 * @throws StorageCommonException
 */
public void debugOff() {
	LOG.info("debug Off");
	Logger log = org.apache.log4j.Logger.getLogger(PACKAGE_NAME);
	if (log != null) {
		log.setLevel(Level.INFO);
	} else {

	}
}
 
源代码28 项目: JVoiceXML   文件: ExLog.java
public static void debug(String logcontent)
{
    StackTraceElement ste = new Throwable().getStackTrace()[1];
    String clsName=ste.getClassName();
    String pkage = clsName.substring(clsName.lastIndexOf(".",clsName.lastIndexOf(".")-1)+1, clsName.length());
    clsName=clsName.substring(clsName.lastIndexOf(".")+1, clsName.length());
    if(clsName.isEmpty()) return;
    //get a proper instance
    Logger subLog = Logger.getRootLogger();
    if(subLog==null) return;
    subLog.log(Level.DEBUG, " ("+pkage+","+ste.getLineNumber()+","+ste.getMethodName()+" )"+logcontent);
}
 
源代码29 项目: JTAF-XCore   文件: Section.java
/**
 * 
 * @param level
 */
private void tryRaiseLevel(Level level) {
	if (!this.getLevel().isGreaterOrEqual(level)) {
		this.level = level;
		if (this.getParent() != null) {
			this.getParent().tryRaiseLevel(level);
		}
	}
}
 
源代码30 项目: calcite   文件: SqlHintsConverterTest.java
void warns(String expectWarning) {
  MockAppender appender = new MockAppender();
  Logger logger = Logger.getRootLogger();
  logger.addAppender(appender);
  try {
    tester.convertSqlToRel(sql);
  } finally {
    logger.removeAppender(appender);
  }
  List<String> warnings = appender.loggingEvents.stream()
      .filter(e -> e.getLevel() == Level.WARN)
      .map(LoggingEvent::getRenderedMessage)
      .collect(Collectors.toList());
  assertThat(expectWarning, is(in(warnings)));
}
 
源代码评论
动弹
沙发等你来抢
 类所在包
 同包方法