# lib/goog/debug/logrecord.js

    1// Copyright 2006 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7//      http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.1415/**16 * @fileoverview Definition of the LogRecord class. Please minimize17 * dependencies this file has on other closure classes as any dependency it18 * takes won't be able to use the logging infrastructure.19 *20 */2122goog.provide('goog.debug.LogRecord');23242526/**27 * LogRecord objects are used to pass logging requests between28 * the logging framework and individual log Handlers.29 * @constructor30 * @param {goog.debug.Logger.Level} level One of the level identifiers.31 * @param {string} msg The string message.32 * @param {string} loggerName The name of the source logger.33 * @param {number=} opt_time Time this log record was created if other than now.34 *     If 0, we use #goog.now.35 * @param {number=} opt_sequenceNumber Sequence number of this log record. This36 *     should only be passed in when restoring a log record from persistence.37 */38goog.debug.LogRecord = function(level, msg, loggerName,39    opt_time, opt_sequenceNumber) {40  this.reset(level, msg, loggerName, opt_time, opt_sequenceNumber);41};424344/**45 * Time the LogRecord was created.46 * @type {number}47 * @private48 */49goog.debug.LogRecord.prototype.time_;505152/**53 * Level of the LogRecord54 * @type {goog.debug.Logger.Level}55 * @private56 */57goog.debug.LogRecord.prototype.level_;585960/**61 * Message associated with the record62 * @type {string}63 * @private64 */65goog.debug.LogRecord.prototype.msg_;666768/**69 * Name of the logger that created the record.70 * @type {string}71 * @private72 */73goog.debug.LogRecord.prototype.loggerName_;747576/**77 * Sequence number for the LogRecord. Each record has a unique sequence number78 * that is greater than all log records created before it.79 * @type {number}80 * @private81 */82goog.debug.LogRecord.prototype.sequenceNumber_ = 0;838485/**86 * Exception associated with the record87 * @type {Object}88 * @private89 */90goog.debug.LogRecord.prototype.exception_ = null;919293/**94 * Exception text associated with the record95 * @type {?string}96 * @private97 */98goog.debug.LogRecord.prototype.exceptionText_ = null;99100101/**102 * @define {boolean} Whether to enable log sequence numbers.103 */104goog.define('goog.debug.LogRecord.ENABLE_SEQUENCE_NUMBERS', true);105106107/**108 * A sequence counter for assigning increasing sequence numbers to LogRecord109 * objects.110 * @type {number}111 * @private112 */113goog.debug.LogRecord.nextSequenceNumber_ = 0;114115116/**117 * Sets all fields of the log record.118 * @param {goog.debug.Logger.Level} level One of the level identifiers.119 * @param {string} msg The string message.120 * @param {string} loggerName The name of the source logger.121 * @param {number=} opt_time Time this log record was created if other than now.122 *     If 0, we use #goog.now.123 * @param {number=} opt_sequenceNumber Sequence number of this log record. This124 *     should only be passed in when restoring a log record from persistence.125 */126goog.debug.LogRecord.prototype.reset = function(level, msg, loggerName,127    opt_time, opt_sequenceNumber) {128  if (goog.debug.LogRecord.ENABLE_SEQUENCE_NUMBERS) {129    this.sequenceNumber_ = typeof opt_sequenceNumber == 'number' ?130        opt_sequenceNumber : goog.debug.LogRecord.nextSequenceNumber_++;131  }132133  this.time_ = opt_time || goog.now();134  this.level_ = level;135  this.msg_ = msg;136  this.loggerName_ = loggerName;137  delete this.exception_;138  delete this.exceptionText_;139};140141142/**143 * Get the source Logger's name.144 *145 * @return {string} source logger name (may be null).146 */147goog.debug.LogRecord.prototype.getLoggerName = function() {148  return this.loggerName_;149};150151152/**153 * Get the exception that is part of the log record.154 *155 * @return {Object} the exception.156 */157goog.debug.LogRecord.prototype.getException = function() {158  return this.exception_;159};160161162/**163 * Set the exception that is part of the log record.164 *165 * @param {Object} exception the exception.166 */167goog.debug.LogRecord.prototype.setException = function(exception) {168  this.exception_ = exception;169};170171172/**173 * Get the exception text that is part of the log record.174 *175 * @return {?string} Exception text.176 */177goog.debug.LogRecord.prototype.getExceptionText = function() {178  return this.exceptionText_;179};180181182/**183 * Set the exception text that is part of the log record.184 *185 * @param {string} text The exception text.186 */187goog.debug.LogRecord.prototype.setExceptionText = function(text) {188  this.exceptionText_ = text;189};190191192/**193 * Get the source Logger's name.194 *195 * @param {string} loggerName source logger name (may be null).196 */197goog.debug.LogRecord.prototype.setLoggerName = function(loggerName) {198  this.loggerName_ = loggerName;199};200201202/**203 * Get the logging message level, for example Level.SEVERE.204 * @return {goog.debug.Logger.Level} the logging message level.205 */206goog.debug.LogRecord.prototype.getLevel = function() {207  return this.level_;208};209210211/**212 * Set the logging message level, for example Level.SEVERE.213 * @param {goog.debug.Logger.Level} level the logging message level.214 */215goog.debug.LogRecord.prototype.setLevel = function(level) {216  this.level_ = level;217};218219220/**221 * Get the "raw" log message, before localization or formatting.222 *223 * @return {string} the raw message string.224 */225goog.debug.LogRecord.prototype.getMessage = function() {226  return this.msg_;227};228229230/**231 * Set the "raw" log message, before localization or formatting.232 *233 * @param {string} msg the raw message string.234 */235goog.debug.LogRecord.prototype.setMessage = function(msg) {236  this.msg_ = msg;237};238239240/**241 * Get event time in milliseconds since 1970.242 *243 * @return {number} event time in millis since 1970.244 */245goog.debug.LogRecord.prototype.getMillis = function() {246  return this.time_;247};248249250/**251 * Set event time in milliseconds since 1970.252 *253 * @param {number} time event time in millis since 1970.254 */255goog.debug.LogRecord.prototype.setMillis = function(time) {256  this.time_ = time;257};258259260/**261 * Get the sequence number.262 * <p>263 * Sequence numbers are normally assigned in the LogRecord264 * constructor, which assigns unique sequence numbers to265 * each new LogRecord in increasing order.266 * @return {number} the sequence number.267 */268goog.debug.LogRecord.prototype.getSequenceNumber = function() {269  return this.sequenceNumber_;270};271