org.apache.log4j.Level#toLevel ( )源码实例Demo

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

源代码1 项目: 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);
}
 
源代码2 项目: cacheonix-core   文件: XLevel.java
public
static
Level toLevel(String sArg, Level defaultValue) {

  if(sArg == null) {
    return defaultValue;
  }
  String stringVal = sArg.toUpperCase();
  
  if(stringVal.equals(TRACE_STR)) {
    return XLevel.TRACE;
  } else if(stringVal.equals(LETHAL_STR)) {
    return XLevel.LETHAL;
  }
    
  return Level.toLevel(sArg, (Level) defaultValue);    
}
 
源代码3 项目: antsdb   文件: BetterCommandLine.java
protected void parseAndRun(String[] args) throws Exception {
    this.args = args;
    CommandLineParser parser = new DefaultParser();
    Options options = new Options();
    buildOptions(options);
    options.addOption("h", "help", false, "help");
    options.addOption(null, "log-level", true, "ALL, ERROR, WARN, INFO, DEBUG or TRACE. default is OFF");
    cmdline = parser.parse(options, args);
    if (cmdline.hasOption('h')) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(getCommandName(), options);
        System.exit(0);
    }
    if (cmdline.hasOption("log-level")) {
        Level level = Level.toLevel(cmdline.getOptionValue("log-level"));
        LogManager.getRootLogger().setLevel(level);
    }
    run();
}
 
源代码4 项目: datawave   文件: StatsHyperLogReducer.java
@Override
public void setup(Configuration conf) throws IOException, InterruptedException {
    super.setup(conf);
    
    // set log level if configured
    String logLevel = conf.get(STATS_REDUCER_LOG_LEVEL, StatsJob.DEFAULT_LOG_LEVEL.toString());
    Level level = Level.toLevel(logLevel, Level.INFO);
    log.info("log level set to " + level.toString());
    
    this.valueInterval = conf.getInt(STATS_REDUCER_VALUE_INTERVAL, DEFAULT_VALUE_INTERVAL);
    log.info("log value interval(" + this.valueInterval + ")");
    
    this.minCount = conf.getInt(STATS_MIN_COUNT, DEFAULT_MIN_COUNT);
    log.info("minimum count(" + this.minCount + ")");
    
    this.countsOnly = conf.getBoolean(STATS_REDUCER_COUNTS, false);
    log.info("counts only(" + this.countsOnly + ")");
    
    // hyperlog precision
    this.normalPrecision = conf.getInt(StatsJob.HYPERLOG_NORMAL_OPTION, StatsJob.HYPERLOG_NORMAL_DEFAULT_VALUE);
    log.info("hyperlog normal precision(" + this.normalPrecision + ')');
    this.sparsePrecision = conf.getInt(StatsJob.HYPERLOG_SPARSE_OPTION, StatsJob.HYPERLOG_SPARSE_DEFAULT_VALUE);
    log.info("hyperlog sparse precision(" + this.sparsePrecision + ')');
    
    this.timestamp = System.currentTimeMillis();
}
 
源代码5 项目: arthas   文件: Log4jHelper.java
public static Boolean updateLevel(String name, String level) {
    if (Log4j) {
        Level l = Level.toLevel(level, Level.ERROR);
        Logger logger = LogManager.getLoggerRepository().exists(name);
        if (logger != null) {
            logger.setLevel(l);
            return true;
        } else {
            Logger root = LogManager.getLoggerRepository().getRootLogger();
            if (root.getName().equals(name)) {
                root.setLevel(l);
                return true;
            }
        }
        return false;
    }
    return null;
}
 
源代码6 项目: datawave   文件: StatsJob.java
/**
 * Processes the options for the Stats job.
 * 
 * @param inArgs
 *            input arguments to stats job
 * @param conf
 *            hadoop configuration
 */
private void parseStatsOptions(final String[] inArgs, final Configuration conf) {
    for (int n = 0; n < inArgs.length; n++) {
        String[] args = inArgs[n].split("=");
        JobArg arg = JobArg.getOption(args[0]);
        if (null != arg) {
            switch (arg) {
            // job args
                case JOB_LOG_LEVEL:
                    Level level = Level.toLevel(args[1], DEFAULT_LOG_LEVEL);
                    log.setLevel(level);
                    log.info("log level set to " + level.toString());
                    break;
                default:
                    conf.set(arg.key, args[1]);
                    break;
            }
        }
    }
    
    // validate required entries
    String vis = conf.get(STATS_VISIBILITY);
    if (null == vis) {
        throw new IllegalStateException("column visibility property (" + STATS_VISIBILITY + ") is not set");
    }
    log.info("column visibility (" + vis + ")");
    
    this.inputTableName = conf.get(INPUT_TABLE_NAME);
    if (null == this.inputTableName) {
        throw new IllegalStateException("input table property (" + INPUT_TABLE_NAME + ") is not set");
    }
    log.info("input table(" + this.inputTableName + ")");
    
    this.outputTableName = conf.get(OUTPUT_TABLE_NAME);
    if (null == this.outputTableName) {
        throw new IllegalStateException("output table property (" + OUTPUT_TABLE_NAME + ") is not set");
    }
    log.info("output table(" + this.outputTableName + ")");
}
 
源代码7 项目: datamill   文件: ApiHandler.java
private static void setLogLevel() {
    String logLevelValue = System.getenv(LOG_LEVEL_PROPERTY);
    if (logLevelValue != null) {
        logger.debug("Setting log level to {}", logLevelValue);
        Level logLevel = Level.toLevel(logLevelValue);

        org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
        if (rootLogger != null) {
            rootLogger.setLevel(logLevel);
        }
    }
}
 
源代码8 项目: ats-framework   文件: DbAppenderConfiguration.java
/**
 * Custom deserialization of DbAppenderConfiguration
 * @param s serialization stream.
 * @throws IOException if IO exception.
 * @throws ClassNotFoundException if class not found.
 */
private void readObject(
                         final ObjectInputStream s ) throws IOException, ClassNotFoundException {

    s.defaultReadObject();
    int levelInt = s.readInt();
    loggingThreshold = Level.toLevel(levelInt);
}
 
源代码9 项目: big-c   文件: MiniRPCBenchmark.java
public static void main(String[] args) throws Exception {
  System.out.println("Benchmark: RPC session establishment.");
  if(args.length < 1)
    printUsage();

  Configuration conf = new Configuration();
  int count = Integer.parseInt(args[0]);
  if(args.length > 1)
    conf.set(KEYTAB_FILE_KEY, args[1]);
  if(args.length > 2)
    conf.set(USER_NAME_KEY, args[2]);
  boolean useDelegationToken = false;
  if(args.length > 3)
    useDelegationToken = args[3].equalsIgnoreCase("useToken");
  Level l = Level.ERROR;
  if(args.length > 4)
    l = Level.toLevel(args[4]);

  MiniRPCBenchmark mb = new MiniRPCBenchmark(l);
  long elapsedTime = 0;
  if(useDelegationToken) {
    System.out.println(
        "Running MiniRPCBenchmark with delegation token authentication.");
    elapsedTime = mb.runMiniBenchmarkWithDelegationToken(
                            conf, count, KEYTAB_FILE_KEY, USER_NAME_KEY);
  } else {
    String auth = SecurityUtil.getAuthenticationMethod(conf).toString();
    System.out.println(
        "Running MiniRPCBenchmark with " + auth + " authentication.");
    elapsedTime = mb.runMiniBenchmark(
                            conf, count, KEYTAB_FILE_KEY, USER_NAME_KEY);
  }
  System.out.println(org.apache.hadoop.util.VersionInfo.getVersion());
  System.out.println("Number  of  connects: " + count);
  System.out.println("Average connect time: " + ((double)elapsedTime/count));
}
 
源代码10 项目: hadoop   文件: MiniRPCBenchmark.java
public static void main(String[] args) throws Exception {
  System.out.println("Benchmark: RPC session establishment.");
  if(args.length < 1)
    printUsage();

  Configuration conf = new Configuration();
  int count = Integer.parseInt(args[0]);
  if(args.length > 1)
    conf.set(KEYTAB_FILE_KEY, args[1]);
  if(args.length > 2)
    conf.set(USER_NAME_KEY, args[2]);
  boolean useDelegationToken = false;
  if(args.length > 3)
    useDelegationToken = args[3].equalsIgnoreCase("useToken");
  Level l = Level.ERROR;
  if(args.length > 4)
    l = Level.toLevel(args[4]);

  MiniRPCBenchmark mb = new MiniRPCBenchmark(l);
  long elapsedTime = 0;
  if(useDelegationToken) {
    System.out.println(
        "Running MiniRPCBenchmark with delegation token authentication.");
    elapsedTime = mb.runMiniBenchmarkWithDelegationToken(
                            conf, count, KEYTAB_FILE_KEY, USER_NAME_KEY);
  } else {
    String auth = SecurityUtil.getAuthenticationMethod(conf).toString();
    System.out.println(
        "Running MiniRPCBenchmark with " + auth + " authentication.");
    elapsedTime = mb.runMiniBenchmark(
                            conf, count, KEYTAB_FILE_KEY, USER_NAME_KEY);
  }
  System.out.println(org.apache.hadoop.util.VersionInfo.getVersion());
  System.out.println("Number  of  connects: " + count);
  System.out.println("Average connect time: " + ((double)elapsedTime/count));
}
 
源代码11 项目: hadoop   文件: NNThroughputBenchmark.java
/**
 * Parse first 2 arguments, corresponding to the "-op" option.
 * 
 * @param args argument list
 * @return true if operation is all, which means that options not related
 * to this operation should be ignored, or false otherwise, meaning
 * that usage should be printed when an unrelated option is encountered.
 */
protected boolean verifyOpArgument(List<String> args) {
  if(args.size() < 2 || ! args.get(0).startsWith("-op"))
    printUsage();

  // process common options
  int krIndex = args.indexOf("-keepResults");
  keepResults = (krIndex >= 0);
  if(keepResults) {
    args.remove(krIndex);
  }

  int llIndex = args.indexOf("-logLevel");
  if(llIndex >= 0) {
    if(args.size() <= llIndex + 1)
      printUsage();
    logLevel = Level.toLevel(args.get(llIndex+1), Level.ERROR);
    args.remove(llIndex+1);
    args.remove(llIndex);
  }

  int ugrcIndex = args.indexOf("-UGCacheRefreshCount");
  if(ugrcIndex >= 0) {
    if(args.size() <= ugrcIndex + 1)
      printUsage();
    int g = Integer.parseInt(args.get(ugrcIndex+1));
    if(g > 0) ugcRefreshCount = g;
    args.remove(ugrcIndex+1);
    args.remove(ugrcIndex);
  }

  String type = args.get(1);
  if(OP_ALL_NAME.equals(type)) {
    type = getOpName();
    return true;
  }
  if(!getOpName().equals(type))
    printUsage();
  return false;
}
 
源代码12 项目: ml-ease   文件: AbstractAvroJob.java
protected AbstractAvroJob(String jobId, JobConfig config)
{
  _jobId = jobId;
  _config = config;
  Level loggingLevel = Level.toLevel(_config.getString("logging.level", "DEBUG"));
  _log.setLevel(loggingLevel);
}
 
源代码13 项目: big-c   文件: NNThroughputBenchmark.java
/**
 * Parse first 2 arguments, corresponding to the "-op" option.
 * 
 * @param args argument list
 * @return true if operation is all, which means that options not related
 * to this operation should be ignored, or false otherwise, meaning
 * that usage should be printed when an unrelated option is encountered.
 */
protected boolean verifyOpArgument(List<String> args) {
  if(args.size() < 2 || ! args.get(0).startsWith("-op"))
    printUsage();

  // process common options
  int krIndex = args.indexOf("-keepResults");
  keepResults = (krIndex >= 0);
  if(keepResults) {
    args.remove(krIndex);
  }

  int llIndex = args.indexOf("-logLevel");
  if(llIndex >= 0) {
    if(args.size() <= llIndex + 1)
      printUsage();
    logLevel = Level.toLevel(args.get(llIndex+1), Level.ERROR);
    args.remove(llIndex+1);
    args.remove(llIndex);
  }

  int ugrcIndex = args.indexOf("-UGCacheRefreshCount");
  if(ugrcIndex >= 0) {
    if(args.size() <= ugrcIndex + 1)
      printUsage();
    int g = Integer.parseInt(args.get(ugrcIndex+1));
    if(g > 0) ugcRefreshCount = g;
    args.remove(ugrcIndex+1);
    args.remove(ugrcIndex);
  }

  String type = args.get(1);
  if(OP_ALL_NAME.equals(type)) {
    type = getOpName();
    return true;
  }
  if(!getOpName().equals(type))
    printUsage();
  return false;
}
 
源代码14 项目: cacheonix-core   文件: XLevel.java
public
static
Level toLevel(int i) throws  IllegalArgumentException {
  switch(i) {
  case TRACE_INT: return XLevel.TRACE;
  case LETHAL_INT: return XLevel.LETHAL;
  }
  return Level.toLevel(i);
}
 
源代码15 项目: hadoop   文件: TestChild.java
@Override
protected void setup(Context context) throws IOException,
    InterruptedException {
  Configuration conf = context.getConfiguration();
  boolean oldConfigs = conf.getBoolean(OLD_CONFIGS, false);
  if (oldConfigs) {
    String javaOpts = conf.get(JobConf.MAPRED_TASK_JAVA_OPTS);
    assertNotNull(JobConf.MAPRED_TASK_JAVA_OPTS + " is null!", 
                  javaOpts);
    assertEquals(JobConf.MAPRED_TASK_JAVA_OPTS + " has value of: " + 
                 javaOpts, 
                 javaOpts, TASK_OPTS_VAL);
  } else {
    String mapJavaOpts = conf.get(JobConf.MAPRED_MAP_TASK_JAVA_OPTS);
    assertNotNull(JobConf.MAPRED_MAP_TASK_JAVA_OPTS + " is null!", 
                  mapJavaOpts);
    assertEquals(JobConf.MAPRED_MAP_TASK_JAVA_OPTS + " has value of: " + 
                 mapJavaOpts, 
                 mapJavaOpts, MAP_OPTS_VAL);
  }
  
  Level logLevel = 
    Level.toLevel(conf.get(JobConf.MAPRED_MAP_TASK_LOG_LEVEL, 
                           Level.INFO.toString()));  
  assertEquals(JobConf.MAPRED_MAP_TASK_LOG_LEVEL + "has value of " + 
               logLevel, logLevel, Level.OFF);
}
 
源代码16 项目: systemds   文件: ParForProgramBlock.java
/**
 * ParForProgramBlock constructor. It reads the specified parameter settings, where defaults for non-specified parameters
 * have been set in ParForStatementBlock.validate(). Furthermore, it generates the IDs for the ParWorkers.
 * 
 * @param ID parfor program block id
 * @param prog runtime program
 * @param iterPredVar ?
 * @param params map of parameters
 * @param resultVars list of result variable names
 */
public ParForProgramBlock(int ID, Program prog, String iterPredVar, HashMap<String,String> params, ArrayList<ResultVar> resultVars) 
{
	super(prog, iterPredVar);
	
	//ID generation and setting 
	setParForProgramBlockIDs( ID );
	_resultVars = resultVars;
	_resultVarsIDSeq = new IDSequence();
	_dpVarsIDSeq = new IDSequence();
	
	//parse and use internal parameters (already set to default if not specified)
	_params = params;
	try {
		_numThreads      = Integer.parseInt( getParForParam(ParForStatementBlock.PAR) );
		_taskPartitioner = PTaskPartitioner.valueOf( getParForParam(ParForStatementBlock.TASK_PARTITIONER) );
		_taskSize        = Integer.parseInt( getParForParam(ParForStatementBlock.TASK_SIZE) );
		_dataPartitioner = PDataPartitioner.valueOf( getParForParam(ParForStatementBlock.DATA_PARTITIONER) );
		_resultMerge     = PResultMerge.valueOf( getParForParam(ParForStatementBlock.RESULT_MERGE) );
		_execMode        = PExecMode.valueOf( getParForParam(ParForStatementBlock.EXEC_MODE) );
		_optMode         = POptMode.valueOf( getParForParam(ParForStatementBlock.OPT_MODE) );
		_optLogLevel     = Level.toLevel( getParForParam(ParForStatementBlock.OPT_LOG) );
		_monitor         = (Integer.parseInt(getParForParam(ParForStatementBlock.PROFILE) ) == 1);
	}
	catch(Exception ex) {
		throw new RuntimeException("Error parsing specified ParFOR parameters.",ex);
	}
	
	//reset the internal opt mode if optimization globally disabled.
	if( !OPTIMIZE )
		_optMode = POptMode.NONE;
	
	_variablesDPOriginal = new LocalVariableMap();
	_variablesDPReuse = new LocalVariableMap();
	
	//create IDs for all parworkers
	if( _execMode == PExecMode.LOCAL /*&& _optMode==POptMode.NONE*/ )
		setLocalParWorkerIDs();

	//initialize program block cache if necessary
	if( USE_PB_CACHE ) 
		_pbcache = new HashMap<>();
	
	//created profiling report after parfor exec
	_monitorReport = _monitor;
	
	//materialized meta data (reused for all invocations)
	_hasFunctions = ProgramRecompiler.containsAtLeastOneFunction(this);
	
	LOG.trace("PARFOR: ParForProgramBlock created with mode = "+_execMode+", optmode = "+_optMode+", numThreads = "+_numThreads);
}
 
源代码17 项目: unitime   文件: MessageLogAppender.java
public Level getMinLevel() {
	if (iMinLevel == null) {
		iMinLevel = Level.toLevel(ApplicationProperty.MessageLogLevel.value());
	}
	return iMinLevel;
}
 
源代码18 项目: hazelcast-simulator   文件: LogOperation.java
public Level getLevel() {
    return Level.toLevel(level, Level.INFO);
}
 
源代码19 项目: cognition   文件: AbstractLoggingBolt.java
@Override
public void configure(Configuration conf) throws ConfigurationException {
  level = Level.toLevel(conf.getString(LEVEL), Level.DEBUG);
}
 
源代码20 项目: JVoiceXML   文件: LoggingReceiver.java
/**
 * Sets the minimal logging level.
 * 
 * @param lev
 *            The minimal logging level.
 */
public void setLevel(final String lev) {
    level = Level.toLevel(lev);
}