Package org.sf.bee.commons.logging.handlers

Examples of org.sf.bee.commons.logging.handlers.LogAbstractHandler


        }
        return count;
    }

    private LogAbstractHandler getHandlerInstance(HandlerElement hndlElem) {
        LogAbstractHandler handler = null;
        try {
            // CREATE HANDLER INSTANCE
            if (StringUtils.hasText(hndlElem.getClassName())) {
                handler = (LogAbstractHandler) BeanUtils.newInstance(hndlElem.getClassName(), null, null);
                handler.setName(hndlElem.getName());
                handler.setLevel(hndlElem.getLevel());
                // set all custom properties
                final Enumeration names = hndlElem.propertyNames();
                while (names.hasMoreElements()) {
                    String name = (String) names.nextElement();
                    Object value = hndlElem.getProperty(name);
                    Class type = BeanUtils.getReturnType(handler.getClass(), BeanUtils.buildGET(name));
                    if (null != type && null != value) {
                        value = BeanUtils.cast(type, value);
                        BeanUtils.setValue(handler, name, value);
                    }
                }

                // FORMATTER
                if (null != handler) {
                    FormatterElement fmtElem = this.solveFormatterElement(hndlElem.getFormatterElement());
                    Formatter formatter = this.getFormatterInstance(fmtElem);
                    if (null != formatter) {
                        handler.setFormatter(formatter);
                    }
                }
            }
        } catch (Throwable ignored) {
            handler = null;
View Full Code Here


                continue;
            }
            // solve handler element looking in cache
            HandlerElement solved = this.solveHandlerElement(entry.getValue());
            // create handler and add to logger
            LogAbstractHandler handler = this.getHandlerInstance(solved);

            if (null != handler) {
                String nativeClassName = handler.getNativeClass().getName();
                // update solved handler in cache
                solved.setNativeClassName(nativeClassName);
                this.addHandlerElementToCache(solved);
                // update local handler in handlers Map
                entry.getValue().setNativeClassName(nativeClassName);
                // first need to close previouse handler
                int closed = this.closeHandler(logger, nativeClassName);
                _logger.log(Level.FINE, String.format("Closed %s handlers of class type '%s'", closed, solved.getClassName()));

                try {

                    // open new handler
                    if (!handler.isOpen()) {
                        // Open handler
                        handler.open();
                    }

                    // add handler to logger
                    if (null != handler.getNative()) {
                        logger.addHandler(handler.getNative());
                    }
                } catch (Throwable t) {
                    _logger.log(Level.WARNING,
                            String.format("Unable to open Handler: %s. Error Message was: %s",
                            entry.getKey(), t.getMessage()));
View Full Code Here

TOP

Related Classes of org.sf.bee.commons.logging.handlers.LogAbstractHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.