Path: blob/trunk/third_party/closure/goog/debug/logrecord.js
2868 views
// Copyright 2006 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Definition of the LogRecord class. Please minimize16* dependencies this file has on other closure classes as any dependency it17* takes won't be able to use the logging infrastructure.18*19*/2021goog.provide('goog.debug.LogRecord');22232425/**26* LogRecord objects are used to pass logging requests between27* the logging framework and individual log Handlers.28* @constructor29* @param {goog.debug.Logger.Level} level One of the level identifiers.30* @param {string} msg The string message.31* @param {string} loggerName The name of the source logger.32* @param {number=} opt_time Time this log record was created if other than now.33* If 0, we use #goog.now.34* @param {number=} opt_sequenceNumber Sequence number of this log record. This35* should only be passed in when restoring a log record from persistence.36*/37goog.debug.LogRecord = function(38level, msg, loggerName, opt_time, opt_sequenceNumber) {39this.reset(level, msg, loggerName, opt_time, opt_sequenceNumber);40};414243/**44* Time the LogRecord was created.45* @type {number}46* @private47*/48goog.debug.LogRecord.prototype.time_;495051/**52* Level of the LogRecord53* @type {goog.debug.Logger.Level}54* @private55*/56goog.debug.LogRecord.prototype.level_;575859/**60* Message associated with the record61* @type {string}62* @private63*/64goog.debug.LogRecord.prototype.msg_;656667/**68* Name of the logger that created the record.69* @type {string}70* @private71*/72goog.debug.LogRecord.prototype.loggerName_;737475/**76* Sequence number for the LogRecord. Each record has a unique sequence number77* that is greater than all log records created before it.78* @type {number}79* @private80*/81goog.debug.LogRecord.prototype.sequenceNumber_ = 0;828384/**85* Exception associated with the record86* @type {Object}87* @private88*/89goog.debug.LogRecord.prototype.exception_ = null;909192/**93* @define {boolean} Whether to enable log sequence numbers.94*/95goog.define('goog.debug.LogRecord.ENABLE_SEQUENCE_NUMBERS', true);969798/**99* A sequence counter for assigning increasing sequence numbers to LogRecord100* objects.101* @type {number}102* @private103*/104goog.debug.LogRecord.nextSequenceNumber_ = 0;105106107/**108* Sets all fields of the log record.109* @param {goog.debug.Logger.Level} level One of the level identifiers.110* @param {string} msg The string message.111* @param {string} loggerName The name of the source logger.112* @param {number=} opt_time Time this log record was created if other than now.113* If 0, we use #goog.now.114* @param {number=} opt_sequenceNumber Sequence number of this log record. This115* should only be passed in when restoring a log record from persistence.116*/117goog.debug.LogRecord.prototype.reset = function(118level, msg, loggerName, opt_time, opt_sequenceNumber) {119if (goog.debug.LogRecord.ENABLE_SEQUENCE_NUMBERS) {120this.sequenceNumber_ = typeof opt_sequenceNumber == 'number' ?121opt_sequenceNumber :122goog.debug.LogRecord.nextSequenceNumber_++;123}124125this.time_ = opt_time || goog.now();126this.level_ = level;127this.msg_ = msg;128this.loggerName_ = loggerName;129delete this.exception_;130};131132133/**134* Get the source Logger's name.135*136* @return {string} source logger name (may be null).137*/138goog.debug.LogRecord.prototype.getLoggerName = function() {139return this.loggerName_;140};141142143/**144* Get the exception that is part of the log record.145*146* @return {Object} the exception.147*/148goog.debug.LogRecord.prototype.getException = function() {149return this.exception_;150};151152153/**154* Set the exception that is part of the log record.155*156* @param {Object} exception the exception.157*/158goog.debug.LogRecord.prototype.setException = function(exception) {159this.exception_ = exception;160};161162163/**164* Get the source Logger's name.165*166* @param {string} loggerName source logger name (may be null).167*/168goog.debug.LogRecord.prototype.setLoggerName = function(loggerName) {169this.loggerName_ = loggerName;170};171172173/**174* Get the logging message level, for example Level.SEVERE.175* @return {goog.debug.Logger.Level} the logging message level.176*/177goog.debug.LogRecord.prototype.getLevel = function() {178return this.level_;179};180181182/**183* Set the logging message level, for example Level.SEVERE.184* @param {goog.debug.Logger.Level} level the logging message level.185*/186goog.debug.LogRecord.prototype.setLevel = function(level) {187this.level_ = level;188};189190191/**192* Get the "raw" log message, before localization or formatting.193*194* @return {string} the raw message string.195*/196goog.debug.LogRecord.prototype.getMessage = function() {197return this.msg_;198};199200201/**202* Set the "raw" log message, before localization or formatting.203*204* @param {string} msg the raw message string.205*/206goog.debug.LogRecord.prototype.setMessage = function(msg) {207this.msg_ = msg;208};209210211/**212* Get event time in milliseconds since 1970.213*214* @return {number} event time in millis since 1970.215*/216goog.debug.LogRecord.prototype.getMillis = function() {217return this.time_;218};219220221/**222* Set event time in milliseconds since 1970.223*224* @param {number} time event time in millis since 1970.225*/226goog.debug.LogRecord.prototype.setMillis = function(time) {227this.time_ = time;228};229230231/**232* Get the sequence number.233* <p>234* Sequence numbers are normally assigned in the LogRecord235* constructor, which assigns unique sequence numbers to236* each new LogRecord in increasing order.237* @return {number} the sequence number.238*/239goog.debug.LogRecord.prototype.getSequenceNumber = function() {240return this.sequenceNumber_;241};242243244