001/*
002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     mguillaume
016 */
017
018package org.nuxeo.launcher.info;
019
020import java.util.Date;
021
022import javax.xml.bind.annotation.XmlAccessType;
023import javax.xml.bind.annotation.XmlAccessorType;
024import javax.xml.bind.annotation.XmlAttribute;
025import javax.xml.bind.annotation.XmlRootElement;
026
027import org.apache.commons.logging.Log;
028import org.apache.commons.logging.LogFactory;
029import org.apache.commons.logging.impl.SimpleLog;
030
031@XmlAccessorType(XmlAccessType.NONE)
032@XmlRootElement(name = "message")
033public class MessageInfo {
034
035    static final Log log = LogFactory.getLog(MessageInfo.class);
036
037    public MessageInfo() {
038    }
039
040    /**
041     * @since 5.7
042     */
043    public MessageInfo(int level, String message) {
044        this.level = level;
045        this.message = message;
046    }
047
048    /**
049     * @see org.apache.commons.logging.impl.SimpleLog levels
050     */
051    @XmlAttribute()
052    public int level;
053
054    @XmlAttribute()
055    public Date time = new Date();
056
057    @XmlAttribute()
058    public String message;
059
060    /**
061     * Log content of the message info
062     *
063     * @since 5.7
064     */
065    public void log() {
066        String msg = "\t" + message;
067        switch (level) {
068        case SimpleLog.LOG_LEVEL_TRACE:
069            log.trace(msg);
070            break;
071        case SimpleLog.LOG_LEVEL_DEBUG:
072            log.debug(msg);
073            break;
074        case SimpleLog.LOG_LEVEL_INFO:
075            log.info(msg);
076            break;
077        case SimpleLog.LOG_LEVEL_WARN:
078            log.warn(msg);
079            break;
080        case SimpleLog.LOG_LEVEL_ERROR:
081            log.error(msg);
082            break;
083        case SimpleLog.LOG_LEVEL_FATAL:
084            log.fatal(msg);
085            break;
086        default:
087        }
088    }
089
090}