List of usage examples for java.util.logging StreamHandler setLevel
public synchronized void setLevel(Level newLevel) throws SecurityException
From source file:cn.org.once.cstack.cli.processor.LoggerPostProcessor.java
public Object postProcessBeforeInitialization(final Object bean, String beanName) throws BeansException { ReflectionUtils.doWithFields(bean.getClass(), new ReflectionUtils.FieldCallback() { public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { if (field.getAnnotation(InjectLogger.class) != null && field.getType().equals(Logger.class)) { ReflectionUtils.makeAccessible(field); Logger logger = Logger.getLogger(bean.getClass().getName()); field.set(bean, logger); StreamHandler fileHandler; try { FileOutputStream fileOutputStream = new FileOutputStream(new File("errors.log"), true); fileHandler = new StreamHandler(fileOutputStream, new SimpleFormatter()); fileHandler.setLevel(Level.SEVERE); logger.addHandler(fileHandler); } catch (SecurityException | IOException e) { throw new IllegalArgumentException(e); }/*from w ww . j a v a 2s . c o m*/ } } }); return bean; }