本文整理汇总了Java中org.apache.log4j.helpers.OptionConverter.toLevel方法的典型用法代码示例。如果您正苦于以下问题:Java OptionConverter.toLevel方法的具体用法?Java OptionConverter.toLevel怎么用?Java OptionConverter.toLevel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.log4j.helpers.OptionConverter
的用法示例。
在下文中一共展示了OptionConverter.toLevel方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertArg
import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
/**
Convert <code>val</code> a String parameter to an object of a
given type.
*/
protected
Object convertArg(String val, Class type) {
if(val == null)
return null;
String v = val.trim();
if (String.class.isAssignableFrom(type)) {
return val;
} else if (Integer.TYPE.isAssignableFrom(type)) {
return new Integer(v);
} else if (Long.TYPE.isAssignableFrom(type)) {
return new Long(v);
} else if (Boolean.TYPE.isAssignableFrom(type)) {
if ("true".equalsIgnoreCase(v)) {
return Boolean.TRUE;
} else if ("false".equalsIgnoreCase(v)) {
return Boolean.FALSE;
}
} else if (Priority.class.isAssignableFrom(type)) {
return OptionConverter.toLevel(v, (Level) Level.DEBUG);
}
return null;
}
示例2: setAttribute
import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
void setAttribute(Attribute attribute) throws AttributeNotFoundException,
InvalidAttributeValueException,
MBeanException,
ReflectionException {
// Check attribute is not null to avoid NullPointerException later on
if (attribute == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute cannot be null"),
"Cannot invoke a setter of "+dClassName+" with null attribute");
}
String name = attribute.getName();
Object value = attribute.getValue();
if (name == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute name cannot be null"),
"Cannot invoke the setter of "+dClassName+
" with null attribute name");
}
if(name.equals(THRESHOLD)) {
Level l = OptionConverter.toLevel((String) value,
hierarchy.getThreshold());
hierarchy.setThreshold(l);
}
}
示例3: convertArg
import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
/**
Convert <code>val</code> a String parameter to an object of a
given type.
*/
protected
Object convertArg(String val, Class type) {
if(val == null)
return null;
String v = val.trim();
if (String.class.isAssignableFrom(type)) {
return val;
} else if (Integer.TYPE.isAssignableFrom(type)) {
return new Integer(v);
} else if (Long.TYPE.isAssignableFrom(type)) {
return new Long(v);
} else if (Boolean.TYPE.isAssignableFrom(type)) {
if ("true".equalsIgnoreCase(v)) {
return Boolean.TRUE;
} else if ("false".equalsIgnoreCase(v)) {
return Boolean.FALSE;
}
} else if (Priority.class.isAssignableFrom(type)) {
return OptionConverter.toLevel(v, (Level) Level.DEBUG);
} else if (ErrorHandler.class.isAssignableFrom(type)) {
return OptionConverter.instantiateByClassName(v,
ErrorHandler.class, null);
}
return null;
}
示例4: setLevelToMatch
import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
void setLevelToMatch(String level) {
levelToMatch = OptionConverter.toLevel(level, null);
}
示例5: setAttribute
import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
void setAttribute(Attribute attribute) throws AttributeNotFoundException,
InvalidAttributeValueException,
MBeanException,
ReflectionException {
// Check attribute is not null to avoid NullPointerException later on
if (attribute == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute cannot be null"),
"Cannot invoke a setter of " + dClassName +
" with null attribute");
}
String name = attribute.getName();
Object value = attribute.getValue();
if (name == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute name cannot be null"),
"Cannot invoke the setter of "+dClassName+
" with null attribute name");
}
MethodUnion mu = (MethodUnion) dynamicProps.get(name);
if(mu != null && mu.writeMethod != null) {
Object[] o = new Object[1];
Class[] params = mu.writeMethod.getParameterTypes();
if(params[0] == org.apache.log4j.Priority.class) {
value = OptionConverter.toLevel((String) value,
(Level) getAttribute(name));
}
o[0] = value;
try {
mu.writeMethod.invoke(layout, o);
} catch(Exception e) {
cat.error("FIXME", e);
}
} else {
throw(new AttributeNotFoundException("Attribute " + name +
" not found in " +
this.getClass().getName()));
}
}
示例6: setAttribute
import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
void setAttribute(Attribute attribute) throws AttributeNotFoundException,
InvalidAttributeValueException,
MBeanException,
ReflectionException {
// Check attribute is not null to avoid NullPointerException later on
if (attribute == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute cannot be null"),
"Cannot invoke a setter of " + dClassName +
" with null attribute");
}
String name = attribute.getName();
Object value = attribute.getValue();
if (name == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute name cannot be null"),
"Cannot invoke the setter of "+dClassName+
" with null attribute name");
}
if(name.equals("priority")) {
if (value instanceof String) {
String s = (String) value;
Level p = logger.getLevel();
if(s.equalsIgnoreCase("NULL")) {
p = null;
} else {
p = OptionConverter.toLevel(s, p);
}
logger.setLevel(p);
}
} else {
throw(new AttributeNotFoundException("Attribute " + name +
" not found in " +
this.getClass().getName()));
}
}
示例7: setAttribute
import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
void setAttribute(Attribute attribute) throws AttributeNotFoundException,
InvalidAttributeValueException,
MBeanException,
ReflectionException {
// Check attribute is not null to avoid NullPointerException later on
if (attribute == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute cannot be null"),
"Cannot invoke a setter of " + dClassName +
" with null attribute");
}
String name = attribute.getName();
Object value = attribute.getValue();
if (name == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute name cannot be null"),
"Cannot invoke the setter of "+dClassName+
" with null attribute name");
}
MethodUnion mu = (MethodUnion) dynamicProps.get(name);
if(mu != null && mu.writeMethod != null) {
Object[] o = new Object[1];
Class[] params = mu.writeMethod.getParameterTypes();
if(params[0] == org.apache.log4j.Priority.class) {
value = OptionConverter.toLevel((String) value,
(Level) getAttribute(name));
}
o[0] = value;
try {
mu.writeMethod.invoke(appender, o);
} catch(Exception e) {
cat.error("FIXME", e);
}
} else if(name.endsWith(".layout")) {
} else {
throw(new AttributeNotFoundException("Attribute " + name +
" not found in " +
this.getClass().getName()));
}
}
示例8: toLevelTest1
import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
void toLevelTest1() {
String val = "INFO";
Level p = OptionConverter.toLevel(val, null);
assertEquals(p, Level.INFO);
}
示例9: toLevelTest2
import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
void toLevelTest2() {
String val = "INFO#org.apache.log4j.xml.XLevel";
Level p = OptionConverter.toLevel(val, null);
assertEquals(p, Level.INFO);
}
示例10: toLevelTest3
import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
void toLevelTest3() {
String val = "TRACE#org.apache.log4j.xml.XLevel";
Level p = OptionConverter.toLevel(val, null);
assertEquals(p, XLevel.TRACE);
}
示例11: toLevelTest4
import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
void toLevelTest4() {
String val = "TR#org.apache.log4j.xml.XLevel";
Level p = OptionConverter.toLevel(val, null);
assertEquals(p, null);
}
示例12: toLevelTest5
import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
void toLevelTest5() {
String val = "INFO#org.apache.log4j.xml.TOTO";
Level p = OptionConverter.toLevel(val, null);
assertEquals(p, null);
}