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