001/*
002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     mguillaume
018 */
019
020package org.nuxeo.launcher.info;
021
022import java.util.Date;
023
024import javax.xml.bind.annotation.XmlAccessType;
025import javax.xml.bind.annotation.XmlAccessorType;
026import javax.xml.bind.annotation.XmlAttribute;
027import javax.xml.bind.annotation.XmlRootElement;
028
029import org.apache.commons.logging.Log;
030import org.apache.commons.logging.LogFactory;
031import org.apache.commons.logging.impl.SimpleLog;
032
033@XmlAccessorType(XmlAccessType.NONE)
034@XmlRootElement(name = "message")
035public class MessageInfo {
036
037    static final Log log = LogFactory.getLog(MessageInfo.class);
038
039    public MessageInfo() {
040    }
041
042    /**
043     * @since 5.7
044     */
045    public MessageInfo(int level, String message) {
046        this.level = level;
047        this.message = message;
048    }
049
050    /**
051     * @see org.apache.commons.logging.impl.SimpleLog levels
052     */
053    @XmlAttribute()
054    public int level;
055
056    @XmlAttribute()
057    public Date time = new Date();
058
059    @XmlAttribute()
060    public String message;
061
062    /**
063     * Log content of the message info
064     *
065     * @since 5.7
066     */
067    public void log() {
068        String msg = "\t" + message;
069        switch (level) {
070        case SimpleLog.LOG_LEVEL_TRACE:
071            log.trace(msg);
072            break;
073        case SimpleLog.LOG_LEVEL_DEBUG:
074            log.debug(msg);
075            break;
076        case SimpleLog.LOG_LEVEL_INFO:
077            log.info(msg);
078            break;
079        case SimpleLog.LOG_LEVEL_WARN:
080            log.warn(msg);
081            break;
082        case SimpleLog.LOG_LEVEL_ERROR:
083            log.error(msg);
084            break;
085        case SimpleLog.LOG_LEVEL_FATAL:
086            log.fatal(msg);
087            break;
088        default:
089        }
090    }
091
092}