本文整理汇总了Java中org.apache.log4j.Level.toLevel方法的典型用法代码示例。如果您正苦于以下问题:Java Level.toLevel方法的具体用法?Java Level.toLevel怎么用?Java Level.toLevel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.log4j.Level
的用法示例。
在下文中一共展示了Level.toLevel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toLevel
import org.apache.log4j.Level; //导入方法依赖的package包/类
/**
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);
}
}
示例2: toLevel
import org.apache.log4j.Level; //导入方法依赖的package包/类
/**
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 SystemLogLevel.SYSTEM;
} else {
return Level.toLevel(sArg, defaultLevel);
}
}
示例3: configureLogging
import org.apache.log4j.Level; //导入方法依赖的package包/类
public static boolean configureLogging() {
if (!_RootDAO.isConfigured()) return false;
org.hibernate.Session hibSession = ApplicationConfigDAO.getInstance().createNewSession();
try {
for (ApplicationConfig config: (List<ApplicationConfig>)hibSession.createQuery("from ApplicationConfig where key like 'log4j.logger.%'").list()) {
Level level = Level.toLevel(config.getValue());
boolean root = "log4j.logger.root".equals(config.getKey());
Logger logger = (root ? Logger.getRootLogger() : Logger.getLogger(config.getKey().substring("log4j.logger.".length())));
logger.setLevel(level);
Debug.info("Logging level for " + logger.getName() + " set to " + level);
}
} finally {
hibSession.close();
}
return true;
}
示例4: update
import org.apache.log4j.Level; //导入方法依赖的package包/类
@Override
@PreAuthorize("checkPermission('ApplicationConfig')")
public void update(Record record, SessionContext context, Session hibSession) {
boolean root = record.getUniqueId() != null && record.getUniqueId() == 0;
Level level = Level.toLevel(Integer.valueOf(record.getField(1)));
solverServerService.setLoggingLevel(root ? null : record.getField(0), level.toInt());
record.setUniqueId(root ? 0 : System.currentTimeMillis());
String defaultValue = ApplicationProperties.getDefaultProperties().getProperty(root ? "log4j.rootLogger" : "log4j.logger." + record.getField(0));
if (defaultValue != null && defaultValue.indexOf(',') > 0)
defaultValue = defaultValue.substring(0, defaultValue.indexOf(',')).trim();
ApplicationConfig config = ApplicationConfig.getConfig(root ? "log4j.logger.root" : "log4j.logger." + record.getField(0));
if (level.toString().equalsIgnoreCase(defaultValue)) {
if (config != null)
hibSession.delete(config);
} else {
if (config == null) {
config = new ApplicationConfig();
config.setKey(root ? "log4j.logger.root" : "log4j.logger." + record.getField(0));
config.setDescription(MESSAGES.descriptionLoggingLevelFor(record.getField(0)));
}
config.setValue(level.toString());
hibSession.saveOrUpdate(config);
}
}
示例5: setLevel
import org.apache.log4j.Level; //导入方法依赖的package包/类
@Override
public void setLevel(String loggerName, String levelName) {
checkNotNull(loggerName, "loggerName");
checkNotNull(levelName, "levelName");
LOGGER.debug("updating logger level (loggerName={}, levelName={})", loggerName, levelName);
Logger logger = LogManager.getLogger(loggerName);
Level level = Level.toLevel(levelName);
logger.setLevel(level);
}
示例6: main
import org.apache.log4j.Level; //导入方法依赖的package包/类
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));
}
示例7: readObject
import org.apache.log4j.Level; //导入方法依赖的package包/类
/**
* 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);
}
示例8: parseArguments
import org.apache.log4j.Level; //导入方法依赖的package包/类
@Override
public int parseArguments(Parameters params) throws CmdLineException {
if (params.size() != 1)
throw new CmdLineException ("an option of type log level should have one parameter [trace,debug,info,warn,error,fatal,off]");
Level result = Level.toLevel(params.getParameter(0).toLowerCase());
setter.addValue(result);
log.debug("set log level " + result);
return 1;
}
示例9: toLevel
import org.apache.log4j.Level; //导入方法依赖的package包/类
public static Level toLevel(int val, Level defaultLevel) {
switch (val) {
case INT_CORE_WARNING: return SLevel.CORE_WARNING;
case INT_CORE_INFO: return SLevel.CORE_INFO;
case INT_THREAD: return SLevel.THREAD;
case INT_HTTP: return SLevel.HTTP;
case INT_ACCESS_VIOLATION: return SLevel.ACCESS_VIOLATION;
default: return Level.toLevel(val, defaultLevel);
}
}
示例10: enableDebugLoggingIfRequired
import org.apache.log4j.Level; //导入方法依赖的package包/类
public static boolean enableDebugLoggingIfRequired(
org.apache.hadoop.conf.Configuration conf) {
boolean result = false;
try {
Level desiredOraOopLoggingLevel =
Level.toLevel(conf.get(OraOopConstants.ORAOOP_LOGGING_LEVEL),
Level.INFO);
Level sqoopLogLevel =
Logger.getLogger(Sqoop.class.getName()).getParent().getLevel();
if (desiredOraOopLoggingLevel == Level.DEBUG
|| desiredOraOopLoggingLevel == Level.ALL
|| sqoopLogLevel == Level.DEBUG || sqoopLogLevel == Level.ALL) {
Category oraOopLogger =
Logger.getLogger(OraOopManagerFactory.class.getName()).getParent();
oraOopLogger.setLevel(Level.DEBUG);
LOG.debug("Enabled OraOop debug logging.");
result = true;
conf.set(OraOopConstants.ORAOOP_LOGGING_LEVEL, Level.DEBUG.toString());
}
} catch (Exception ex) {
LOG.error(String.format(
"Unable to determine whether debug logging should be enabled.\n%s",
getFullExceptionMessage(ex)));
}
return result;
}
示例11: setRootLevel
import org.apache.log4j.Level; //导入方法依赖的package包/类
@Override
public void setRootLevel(String levelName) {
checkNotNull(levelName, "levelName");
LOGGER.debug("updating root logger level (name={})", levelName);
Level level = Level.toLevel(levelName);
Logger logger = LogManager.getRootLogger();
logger.setLevel(level);
}
示例12: setup
import org.apache.log4j.Level; //导入方法依赖的package包/类
@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);
}
示例13: verifyOpArgument
import org.apache.log4j.Level; //导入方法依赖的package包/类
/**
* 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: configureLog4jFromSystemProperties
import org.apache.log4j.Level; //导入方法依赖的package包/类
public static void configureLog4jFromSystemProperties() {
final String LOGGER_PREFIX = "log4j";
Properties props = new Properties();
System.out.println("<Log_level>: DEBUG, WARN, ERROR, FATAL, INFO, TRACE, TRACE_INT, ALL, OFF");
System.out.print(
"Type \"-Dlog4j=<Log_level>\" as VM arguments to specify a log level - By default \"debug\" mode is on\n\n");
// Read the VM argument (e.g. java -Dlog4j=all ...)
for (String propertyName : System.getProperties().stringPropertyNames()) {
if (propertyName.startsWith(LOGGER_PREFIX)) {
/*
* take the value on the right of equal sign of VM argument and
* store it in "levelName" variable (e.g. java -Dlog4j=all, take
* the "all" value and store it in "levelName" variable)
*/
String levelName = System.getProperty(propertyName, "");
Level level = Level.toLevel(levelName); // If the conversion
// fails, then this
// method returns DEBUG
// If a value is assigned to log4j option and this value is not
// recognized by Level class
if (!"".equals(levelName) && !levelName.toUpperCase().equals(level.toString())) {
System.err.print("Skipping unrecognized log4j log level " + levelName + ": -D" + propertyName + "="
+ levelName + "\n\n");
} else {
try {
InputStream configStream = ParquetStats.class.getClassLoader()
.getResourceAsStream("log4j.properties");
props.load(configStream);
configStream.close();
} catch (Exception e) {
System.err.println("Error not laod configuration file");
System.exit(1);
}
props.setProperty("log4j.rootLogger", levelName + ", stdout");
LogManager.resetConfiguration();
PropertyConfigurator.configure(props);
}
}
}
}
示例15: convert
import org.apache.log4j.Level; //导入方法依赖的package包/类
@Override
public Level convert(final Method method, final String level) {
return Level.toLevel(level);
}