Java Code Examples for org.apache.log4j.Level#toLevel()

The following examples show how to use org.apache.log4j.Level#toLevel() . 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: XLevel.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
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);    
}
 
Example 2
Source File: BetterCommandLine.java    From antsdb with GNU Lesser General Public License v3.0 6 votes vote down vote up
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();
}
 
Example 3
Source File: StatsHyperLogReducer.java    From datawave with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 4
Source File: LogManager.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
@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);
}
 
Example 5
Source File: Log4jHelper.java    From arthas with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 6
Source File: TestChild.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 7
Source File: XLevel.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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);
}
 
Example 8
Source File: NNThroughputBenchmark.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 9
Source File: StatsJob.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * 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 + ")");
}
 
Example 10
Source File: AbstractAvroJob.java    From ml-ease with Apache License 2.0 5 votes vote down vote up
protected AbstractAvroJob(String jobId, JobConfig config)
{
  _jobId = jobId;
  _config = config;
  Level loggingLevel = Level.toLevel(_config.getString("logging.level", "DEBUG"));
  _log.setLevel(loggingLevel);
}
 
Example 11
Source File: ApiHandler.java    From datamill with ISC License 5 votes vote down vote up
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);
        }
    }
}
 
Example 12
Source File: DbAppenderConfiguration.java    From ats-framework with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 13
Source File: MiniRPCBenchmark.java    From big-c with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 14
Source File: MiniRPCBenchmark.java    From hadoop with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 15
Source File: NNThroughputBenchmark.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 16
Source File: AbstractLoggingBolt.java    From cognition with Apache License 2.0 4 votes vote down vote up
@Override
public void configure(Configuration conf) throws ConfigurationException {
  level = Level.toLevel(conf.getString(LEVEL), Level.DEBUG);
}
 
Example 17
Source File: LogOperation.java    From hazelcast-simulator with Apache License 2.0 4 votes vote down vote up
public Level getLevel() {
    return Level.toLevel(level, Level.INFO);
}
 
Example 18
Source File: MessageLogAppender.java    From unitime with Apache License 2.0 4 votes vote down vote up
public Level getMinLevel() {
	if (iMinLevel == null) {
		iMinLevel = Level.toLevel(ApplicationProperty.MessageLogLevel.value());
	}
	return iMinLevel;
}
 
Example 19
Source File: ParForProgramBlock.java    From systemds with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 20
Source File: LoggingReceiver.java    From JVoiceXML with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Sets the minimal logging level.
 * 
 * @param lev
 *            The minimal logging level.
 */
public void setLevel(final String lev) {
    level = Level.toLevel(lev);
}