001/*
002 * Copyright 2009-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2009-2020 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) 2015-2020 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.ThreadSafety;
043import com.unboundid.util.ThreadSafetyLevel;
044
045
046
047/**
048 * This class provides a data structure that holds information about a log
049 * message that may appear in the Directory Server error log.
050 * <BR>
051 * <BLOCKQUOTE>
052 *   <B>NOTE:</B>  This class, and other classes within the
053 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
054 *   supported for use against Ping Identity, UnboundID, and
055 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
056 *   for proprietary functionality or for external specifications that are not
057 *   considered stable or mature enough to be guaranteed to work in an
058 *   interoperable way with other types of LDAP servers.
059 * </BLOCKQUOTE>
060 */
061@NotMutable()
062@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
063public final class ErrorLogMessage
064       extends LogMessage
065{
066  /**
067   * The serial version UID for this serializable class.
068   */
069  private static final long serialVersionUID = 1743586990943392442L;
070
071
072
073  // The name of the category for this error log message.
074  private final ErrorLogCategory category;
075
076  // The name of the severity for this error log message.
077  private final ErrorLogSeverity severity;
078
079  // The message ID for this error log message.
080  private final Long messageID;
081
082  // The connection ID for the operation currently being processed by the thread
083  // that generated this error log message.
084  private final Long triggeredByConnectionID;
085
086  // The operation ID for the operation currently being processed by the thread
087  // that generated this error log message.
088  private final Long triggeredByOperationID;
089
090  // The Directory Server instance name for this error log message.
091  private final String instanceName;
092
093  // The message string for this error log message.
094  private final String message;
095
096  // The product name for this error log message.
097  private final String productName;
098
099  // The startup ID for this error log message;
100  private final String startupID;
101
102
103
104  /**
105   * Creates a new error log message from the provided message string.
106   *
107   * @param  s  The string to be parsed as an error log message.
108   *
109   * @throws  LogException  If the provided string cannot be parsed as a valid
110   *                        log message.
111   */
112  public ErrorLogMessage(final String s)
113         throws LogException
114  {
115    this(new LogMessage(s));
116  }
117
118
119
120  /**
121   * Creates a new error log message from the provided message string.
122   *
123   * @param  m  The log message to be parsed as an error log message.
124   */
125  public ErrorLogMessage(final LogMessage m)
126  {
127    super(m);
128
129    productName             = getNamedValue("product");
130    instanceName            = getNamedValue("instanceName");
131    startupID               = getNamedValue("startupID");
132    messageID               = getNamedValueAsLong("msgID");
133    message                 = getNamedValue("msg");
134    triggeredByConnectionID = getNamedValueAsLong("triggeredByConn");
135    triggeredByOperationID  = getNamedValueAsLong("triggeredByOp");
136
137    ErrorLogCategory cat = null;
138    try
139    {
140      cat = ErrorLogCategory.valueOf(getNamedValue("category"));
141    }
142    catch (final Exception e)
143    {
144      Debug.debugException(e);
145    }
146    category = cat;
147
148    ErrorLogSeverity sev = null;
149    try
150    {
151      sev = ErrorLogSeverity.valueOf(getNamedValue("severity"));
152    }
153    catch (final Exception e)
154    {
155      Debug.debugException(e);
156    }
157    severity = sev;
158  }
159
160
161
162  /**
163   * Retrieves the server product name for this error log message.
164   *
165   * @return  The server product name for this error log message, or
166   *          {@code null} if it is not included in the log message.
167   */
168  public String getProductName()
169  {
170    return productName;
171  }
172
173
174
175  /**
176   * Retrieves the Directory Server instance name for this error log message.
177   *
178   * @return  The Directory Server instance name for this error log message, or
179   *          {@code null} if it is not included in the log message.
180   */
181  public String getInstanceName()
182  {
183    return instanceName;
184  }
185
186
187
188  /**
189   * Retrieves the Directory Server startup ID for this error log message.
190   *
191   * @return  The Directory Server startup ID for this error log message, or
192   *          {@code null} if it is not included in the log message.
193   */
194  public String getStartupID()
195  {
196    return startupID;
197  }
198
199
200
201  /**
202   * Retrieves the category for this error log message.
203   *
204   * @return  The category for this error log message, or {@code null} if it is
205   *          not included in the log message.
206   */
207  public ErrorLogCategory getCategory()
208  {
209    return category;
210  }
211
212
213
214  /**
215   * Retrieves the severity for this error log message.
216   *
217   * @return  The severity for this error log message, or {@code null} if it is
218   *          not included in the log message.
219   */
220  public ErrorLogSeverity getSeverity()
221  {
222    return severity;
223  }
224
225
226
227  /**
228   * Retrieves the numeric identifier for this error log message.
229   *
230   * @return  The numeric identifier for this error log message, or {@code null}
231   *          if it is not included in the log message.
232   */
233  public Long getMessageID()
234  {
235    return messageID;
236  }
237
238
239
240  /**
241   * Retrieves the connection ID for the operation currently being processed by
242   * the thread that generated this error log message.
243   *
244   * @return  The connection ID for the operation currently being processed by
245   *          the thread that generated this error log message, or {@code null}
246   *          if it is not included in the log message.
247   */
248  public Long getTriggeredByConnectionID()
249  {
250    return triggeredByConnectionID;
251  }
252
253
254
255  /**
256   * Retrieves the operation ID for the operation currently being processed by
257   * the thread that generated this error log message.
258   *
259   * @return  The operation ID for the operation currently being processed by
260   *          the thread that generated this error log message, or {@code null}
261   *          if it is not included in the log message.
262   */
263  public Long getTriggeredByOperationID()
264  {
265    return triggeredByOperationID;
266  }
267
268
269
270  /**
271   * Retrieves the message text for this error log message.
272   *
273   * @return  The message text for this error log message, or {@code null} if it
274   *          is not included in the log message.
275   */
276  public String getMessage()
277  {
278    return message;
279  }
280}