下面列出了org.apache.log4j.Level#toLevel ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
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);
}
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();
}
@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();
}
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;
}
/**
* 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 + ")");
}
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);
}
}
}
/**
* 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);
}
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));
}
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));
}
/**
* 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;
}
protected AbstractAvroJob(String jobId, JobConfig config)
{
_jobId = jobId;
_config = config;
Level loggingLevel = Level.toLevel(_config.getString("logging.level", "DEBUG"));
_log.setLevel(loggingLevel);
}
/**
* 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;
}
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);
}
@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);
}
/**
* 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);
}
public Level getMinLevel() {
if (iMinLevel == null) {
iMinLevel = Level.toLevel(ApplicationProperty.MessageLogLevel.value());
}
return iMinLevel;
}
public Level getLevel() {
return Level.toLevel(level, Level.INFO);
}
@Override
public void configure(Configuration conf) throws ConfigurationException {
level = Level.toLevel(conf.getString(LEVEL), Level.DEBUG);
}
/**
* Sets the minimal logging level.
*
* @param lev
* The minimal logging level.
*/
public void setLevel(final String lev) {
level = Level.toLevel(lev);
}