001 /*
002 * Copyright 2009-2015 UnboundID Corp.
003 * All Rights Reserved.
004 */
005 /*
006 * Copyright (C) 2015 UnboundID Corp.
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021 package com.unboundid.ldap.sdk.unboundidds.logs;
022
023
024
025 import com.unboundid.util.NotMutable;
026 import com.unboundid.util.ThreadSafety;
027 import com.unboundid.util.ThreadSafetyLevel;
028
029 import static com.unboundid.util.Debug.*;
030
031
032
033 /**
034 * <BLOCKQUOTE>
035 * <B>NOTE:</B> This class is part of the Commercial Edition of the UnboundID
036 * LDAP SDK for Java. It is not available for use in applications that
037 * include only the Standard Edition of the LDAP SDK, and is not supported for
038 * use in conjunction with non-UnboundID products.
039 * </BLOCKQUOTE>
040 * This class provides a data structure that holds information about a log
041 * message that may appear in the Directory Server error log.
042 */
043 @NotMutable()
044 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
045 public final class ErrorLogMessage
046 extends LogMessage
047 {
048 /**
049 * The serial version UID for this serializable class.
050 */
051 private static final long serialVersionUID = 1743586990943392442L;
052
053
054
055 // The name of the category for this error log message.
056 private final ErrorLogCategory category;
057
058 // The name of the severity for this error log message.
059 private final ErrorLogSeverity severity;
060
061 // The message ID for this error log message.
062 private final Long messageID;
063
064 // The Directory Server instance name for this error log message.
065 private final String instanceName;
066
067 // The message string for this error log message.
068 private final String message;
069
070 // The product name for this error log message.
071 private final String productName;
072
073 // The startup ID for this error log message;
074 private final String startupID;
075
076
077
078 /**
079 * Creates a new error log message from the provided message string.
080 *
081 * @param s The string to be parsed as an error log message.
082 *
083 * @throws LogException If the provided string cannot be parsed as a valid
084 * log message.
085 */
086 public ErrorLogMessage(final String s)
087 throws LogException
088 {
089 this(new LogMessage(s));
090 }
091
092
093
094 /**
095 * Creates a new error log message from the provided message string.
096 *
097 * @param m The log message to be parsed as an error log message.
098 */
099 public ErrorLogMessage(final LogMessage m)
100 {
101 super(m);
102
103 productName = getNamedValue("product");
104 instanceName = getNamedValue("instanceName");
105 startupID = getNamedValue("startupID");
106 messageID = getNamedValueAsLong("msgID");
107 message = getNamedValue("msg");
108
109 ErrorLogCategory cat = null;
110 try
111 {
112 cat = ErrorLogCategory.valueOf(getNamedValue("category"));
113 }
114 catch (Exception e)
115 {
116 debugException(e);
117 }
118 category = cat;
119
120 ErrorLogSeverity sev = null;
121 try
122 {
123 sev = ErrorLogSeverity.valueOf(getNamedValue("severity"));
124 }
125 catch (Exception e)
126 {
127 debugException(e);
128 }
129 severity = sev;
130 }
131
132
133
134 /**
135 * Retrieves the server product name for this error log message.
136 *
137 * @return The server product name for this error log message, or
138 * {@code null} if it is not included in the log message.
139 */
140 public String getProductName()
141 {
142 return productName;
143 }
144
145
146
147 /**
148 * Retrieves the Directory Server instance name for this error log message.
149 *
150 * @return The Directory Server instance name for this error log message, or
151 * {@code null} if it is not included in the log message.
152 */
153 public String getInstanceName()
154 {
155 return instanceName;
156 }
157
158
159
160 /**
161 * Retrieves the Directory Server startup ID for this error log message.
162 *
163 * @return The Directory Server startup ID for this error log message, or
164 * {@code null} if it is not included in the log message.
165 */
166 public String getStartupID()
167 {
168 return startupID;
169 }
170
171
172
173 /**
174 * Retrieves the category for this error log message.
175 *
176 * @return The category for this error log message, or {@code null} if it is
177 * not included in the log message.
178 */
179 public ErrorLogCategory getCategory()
180 {
181 return category;
182 }
183
184
185
186 /**
187 * Retrieves the severity for this error log message.
188 *
189 * @return The severity for this error log message, or {@code null} if it is
190 * not included in the log message.
191 */
192 public ErrorLogSeverity getSeverity()
193 {
194 return severity;
195 }
196
197
198
199 /**
200 * Retrieves the numeric identifier for this error log message.
201 *
202 * @return The numeric identifier for this error log message, or {@code null}
203 * if it is not included in the log message.
204 */
205 public Long getMessageID()
206 {
207 return messageID;
208 }
209
210
211
212 /**
213 * Retrieves the message text for this error log message.
214 *
215 * @return The message text for this error log message, or {@code null} if it
216 * is not included in the log message.
217 */
218 public String getMessage()
219 {
220 return message;
221 }
222 }