001/*
002 * Copyright 2009-2022 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2009-2022 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2009-2022 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk.unboundidds.logs;
037
038
039
040import com.unboundid.util.Debug;
041import com.unboundid.util.NotMutable;
042import com.unboundid.util.NotNull;
043import com.unboundid.util.Nullable;
044import com.unboundid.util.ThreadSafety;
045import com.unboundid.util.ThreadSafetyLevel;
046
047
048
049/**
050 * This class provides a data structure that holds information about a log
051 * message that may appear in the Directory Server error log.
052 * <BR>
053 * <BLOCKQUOTE>
054 *   <B>NOTE:</B>  This class, and other classes within the
055 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
056 *   supported for use against Ping Identity, UnboundID, and
057 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
058 *   for proprietary functionality or for external specifications that are not
059 *   considered stable or mature enough to be guaranteed to work in an
060 *   interoperable way with other types of LDAP servers.
061 * </BLOCKQUOTE>
062 */
063@NotMutable()
064@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
065public final class ErrorLogMessage
066       extends LogMessage
067{
068  /**
069   * The serial version UID for this serializable class.
070   */
071  private static final long serialVersionUID = 1743586990943392442L;
072
073
074
075  // The name of the category for this error log message.
076  @Nullable private final ErrorLogCategory category;
077
078  // The name of the severity for this error log message.
079  @Nullable private final ErrorLogSeverity severity;
080
081  // The message ID for this error log message.
082  @Nullable private final Long messageID;
083
084  // The connection ID for the operation currently being processed by the thread
085  // that generated this error log message.
086  @Nullable private final Long triggeredByConnectionID;
087
088  // The operation ID for the operation currently being processed by the thread
089  // that generated this error log message.
090  @Nullable private final Long triggeredByOperationID;
091
092  // The Directory Server instance name for this error log message.
093  @Nullable private final String instanceName;
094
095  // The message string for this error log message.
096  @Nullable private final String message;
097
098  // The product name for this error log message.
099  @Nullable private final String productName;
100
101  // The startup ID for this error log message;
102  @Nullable private final String startupID;
103
104
105
106  /**
107   * Creates a new error log message from the provided message string.
108   *
109   * @param  s  The string to be parsed as an error log message.
110   *
111   * @throws  LogException  If the provided string cannot be parsed as a valid
112   *                        log message.
113   */
114  public ErrorLogMessage(@NotNull final String s)
115         throws LogException
116  {
117    this(new LogMessage(s));
118  }
119
120
121
122  /**
123   * Creates a new error log message from the provided message string.
124   *
125   * @param  m  The log message to be parsed as an error log message.
126   */
127  public ErrorLogMessage(@NotNull final LogMessage m)
128  {
129    super(m);
130
131    productName             = getNamedValue("product");
132    instanceName            = getNamedValue("instanceName");
133    startupID               = getNamedValue("startupID");
134    messageID               = getNamedValueAsLong("msgID");
135    message                 = getNamedValue("msg");
136    triggeredByConnectionID = getNamedValueAsLong("triggeredByConn");
137    triggeredByOperationID  = getNamedValueAsLong("triggeredByOp");
138
139    ErrorLogCategory cat = null;
140    try
141    {
142      cat = ErrorLogCategory.valueOf(getNamedValue("category"));
143    }
144    catch (final Exception e)
145    {
146      Debug.debugException(e);
147    }
148    category = cat;
149
150    ErrorLogSeverity sev = null;
151    try
152    {
153      sev = ErrorLogSeverity.valueOf(getNamedValue("severity"));
154    }
155    catch (final Exception e)
156    {
157      Debug.debugException(e);
158    }
159    severity = sev;
160  }
161
162
163
164  /**
165   * Retrieves the server product name for this error log message.
166   *
167   * @return  The server product name for this error log message, or
168   *          {@code null} if it is not included in the log message.
169   */
170  @Nullable()
171  public String getProductName()
172  {
173    return productName;
174  }
175
176
177
178  /**
179   * Retrieves the Directory Server instance name for this error log message.
180   *
181   * @return  The Directory Server instance name for this error log message, or
182   *          {@code null} if it is not included in the log message.
183   */
184  @Nullable()
185  public String getInstanceName()
186  {
187    return instanceName;
188  }
189
190
191
192  /**
193   * Retrieves the Directory Server startup ID for this error log message.
194   *
195   * @return  The Directory Server startup ID for this error log message, or
196   *          {@code null} if it is not included in the log message.
197   */
198  @Nullable()
199  public String getStartupID()
200  {
201    return startupID;
202  }
203
204
205
206  /**
207   * Retrieves the category for this error log message.
208   *
209   * @return  The category for this error log message, or {@code null} if it is
210   *          not included in the log message.
211   */
212  @Nullable()
213  public ErrorLogCategory getCategory()
214  {
215    return category;
216  }
217
218
219
220  /**
221   * Retrieves the severity for this error log message.
222   *
223   * @return  The severity for this error log message, or {@code null} if it is
224   *          not included in the log message.
225   */
226  @Nullable()
227  public ErrorLogSeverity getSeverity()
228  {
229    return severity;
230  }
231
232
233
234  /**
235   * Retrieves the numeric identifier for this error log message.
236   *
237   * @return  The numeric identifier for this error log message, or {@code null}
238   *          if it is not included in the log message.
239   */
240  @Nullable()
241  public Long getMessageID()
242  {
243    return messageID;
244  }
245
246
247
248  /**
249   * Retrieves the connection ID for the operation currently being processed by
250   * the thread that generated this error log message.
251   *
252   * @return  The connection ID for the operation currently being processed by
253   *          the thread that generated this error log message, or {@code null}
254   *          if it is not included in the log message.
255   */
256  @Nullable()
257  public Long getTriggeredByConnectionID()
258  {
259    return triggeredByConnectionID;
260  }
261
262
263
264  /**
265   * Retrieves the operation ID for the operation currently being processed by
266   * the thread that generated this error log message.
267   *
268   * @return  The operation ID for the operation currently being processed by
269   *          the thread that generated this error log message, or {@code null}
270   *          if it is not included in the log message.
271   */
272  @Nullable()
273  public Long getTriggeredByOperationID()
274  {
275    return triggeredByOperationID;
276  }
277
278
279
280  /**
281   * Retrieves the message text for this error log message.
282   *
283   * @return  The message text for this error log message, or {@code null} if it
284   *          is not included in the log message.
285   */
286  @Nullable()
287  public String getMessage()
288  {
289    return message;
290  }
291}