Java Code Examples for org.apache.log4j.helpers.OptionConverter#toLevel()
The following examples show how to use
org.apache.log4j.helpers.OptionConverter#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: PropertySetter.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** 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; }
Example 2
Source File: HierarchyDynamicMBean.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
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); } }
Example 3
Source File: LevelMatchFilter.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void setLevelToMatch(String level) { levelToMatch = OptionConverter.toLevel(level, null); }
Example 4
Source File: LayoutDynamicMBean.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
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())); } }
Example 5
Source File: LoggerDynamicMBean.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
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())); } }
Example 6
Source File: AppenderDynamicMBean.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
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())); } }
Example 7
Source File: OptionConverterTestCase.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void toLevelTest1() { String val = "INFO"; Level p = OptionConverter.toLevel(val, null); assertEquals(p, Level.INFO); }
Example 8
Source File: OptionConverterTestCase.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void toLevelTest2() { String val = "INFO#org.apache.log4j.xml.XLevel"; Level p = OptionConverter.toLevel(val, null); assertEquals(p, Level.INFO); }
Example 9
Source File: OptionConverterTestCase.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void toLevelTest3() { String val = "TRACE#org.apache.log4j.xml.XLevel"; Level p = OptionConverter.toLevel(val, null); assertEquals(p, XLevel.TRACE); }
Example 10
Source File: OptionConverterTestCase.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void toLevelTest4() { String val = "TR#org.apache.log4j.xml.XLevel"; Level p = OptionConverter.toLevel(val, null); assertEquals(p, null); }
Example 11
Source File: OptionConverterTestCase.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void toLevelTest5() { String val = "INFO#org.apache.log4j.xml.TOTO"; Level p = OptionConverter.toLevel(val, null); assertEquals(p, null); }