001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2010-2011 ApexIdentity Inc.
015 * Portions Copyright 2011-2014 ForgeRock AS.
016 */
017
018package org.forgerock.openig.log;
019
020import org.forgerock.openig.heap.Name;
021
022/**
023 * The log entry data structure.
024 */
025public class LogEntry {
026    /** The time of the event being logged (milliseconds since the 1970 epoch). */
027    private final long time = System.currentTimeMillis();
028
029    /**
030     * The subject and/or event being logged.
031     */
032    private final Name source;
033
034    private final String type;
035
036    /** The logging level of the entry. */
037    private final LogLevel level;
038
039    /** Human-readable message text, suitable for display in any entry listings. */
040    private final String message;
041
042    /** The data being logged or {@code null} if no data. */
043    private final Object data;
044
045    LogEntry(Name source, LogLevel level, String message) {
046        this(source, level, message, null);
047    }
048
049    LogEntry(Name source, LogLevel level, String message, Object data) {
050        this(source, "log", level, message, data);
051    }
052
053    LogEntry(Name source, String type, LogLevel level, String message, Object data) {
054        this.source = source;
055        this.type = type;
056        this.level = level;
057        this.message = message;
058        this.data = data;
059    }
060
061    /**
062     * Returns the time of the event being logged (milliseconds since the 1970
063     * epoch).
064     *
065     * @return The time of the event being logged (milliseconds since the 1970
066     *         epoch).
067     */
068    public long getTime() {
069        return time;
070    }
071
072    /**
073     * Returns the subject and/or event being logged.
074     *
075     * @return The subject and/or event being logged.
076     */
077    public Name getSource() {
078        return source;
079    }
080
081    /**
082     * Returns the type of the event.
083     *
084     * @return the type of the event.
085     */
086    public String getType() {
087        return type;
088    }
089
090    /**
091     * Returns the logging level of the entry.
092     *
093     * @return The logging level of the entry.
094     */
095    public LogLevel getLevel() {
096        return level;
097    }
098
099    /**
100     * Returns Human-readable message text, suitable for display in any entry
101     * listings.
102     *
103     * @return Human-readable message text, suitable for display in any entry
104     *         listings.
105     */
106    public String getMessage() {
107        return message;
108    }
109
110    /**
111     * Returns the data being logged or {@code null} if no data.
112     *
113     * @return The data being logged or {@code null} if no data.
114     */
115    public Object getData() {
116        return data;
117    }
118
119}