Debian Codegraph @

closure-library/closure/goog/debug/logrecord.js

raw
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 at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // 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 and
13 // limitations under the License.
14
15 /**
16 * @fileoverview Definition of the LogRecord class. Please minimize
17 * dependencies this file has on other closure classes as any dependency it
18 * takes won't be able to use the logging infrastructure.
19 *
20 */
21
22 goog.provide('goog.debug.LogRecord');
23
24
25
26 /**
27 * LogRecord objects are used to pass logging requests between
28 * the logging framework and individual log Handlers.
29 * @constructor
30 * @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. This
36 * should only be passed in when restoring a log record from persistence.
37 */
38 goog.debug.LogRecord = function(
39 level, msg, loggerName, opt_time, opt_sequenceNumber) {
40 this.reset(level, msg, loggerName, opt_time, opt_sequenceNumber);
41 };
42
43
44 /**
45 * Time the LogRecord was created.
46 * @type {number}
47 * @private
48 */
49 goog.debug.LogRecord.prototype.time_;
50
51
52 /**
53 * Level of the LogRecord
54 * @type {goog.debug.Logger.Level}
55 * @private
56 */
57 goog.debug.LogRecord.prototype.level_;
58
59
60 /**
61 * Message associated with the record
62 * @type {string}
63 * @private
64 */
65 goog.debug.LogRecord.prototype.msg_;
66
67
68 /**
69 * Name of the logger that created the record.
70 * @type {string}
71 * @private
72 */
73 goog.debug.LogRecord.prototype.loggerName_;
74
75
76 /**
77 * Sequence number for the LogRecord. Each record has a unique sequence number
78 * that is greater than all log records created before it.
79 * @type {number}
80 * @private
81 */
82 goog.debug.LogRecord.prototype.sequenceNumber_ = 0;
83
84
85 /**
86 * Exception associated with the record
87 * @type {Object}
88 * @private
89 */
90 goog.debug.LogRecord.prototype.exception_ = null;
91
92
93 /**
94 * @define {boolean} Whether to enable log sequence numbers.
95 */
96 goog.define('goog.debug.LogRecord.ENABLE_SEQUENCE_NUMBERS', true);
97
98
99 /**
100 * A sequence counter for assigning increasing sequence numbers to LogRecord
101 * objects.
102 * @type {number}
103 * @private
104 */
105 goog.debug.LogRecord.nextSequenceNumber_ = 0;
106
107
108 /**
109 * Sets all fields of the log record.
110 * @param {goog.debug.Logger.Level} level One of the level identifiers.
111 * @param {string} msg The string message.
112 * @param {string} loggerName The name of the source logger.
113 * @param {number=} opt_time Time this log record was created if other than now.
114 * If 0, we use #goog.now.
115 * @param {number=} opt_sequenceNumber Sequence number of this log record. This
116 * should only be passed in when restoring a log record from persistence.
117 */
118 goog.debug.LogRecord.prototype.reset = function(
119 level, msg, loggerName, opt_time, opt_sequenceNumber) {
120 if (goog.debug.LogRecord.ENABLE_SEQUENCE_NUMBERS) {
121 this.sequenceNumber_ = typeof opt_sequenceNumber == 'number' ?
122 opt_sequenceNumber :
123 goog.debug.LogRecord.nextSequenceNumber_++;
124 }
125
126 this.time_ = opt_time || goog.now();
127 this.level_ = level;
128 this.msg_ = msg;
129 this.loggerName_ = loggerName;
130 delete this.exception_;
131 };
132
133
134 /**
135 * Get the source Logger's name.
136 *
137 * @return {string} source logger name (may be null).
138 */
139 goog.debug.LogRecord.prototype.getLoggerName = function() {
140 return this.loggerName_;
141 };
142
143
144 /**
145 * Get the exception that is part of the log record.
146 *
147 * @return {Object} the exception.
148 */
149 goog.debug.LogRecord.prototype.getException = function() {
150 return this.exception_;
151 };
152
153
154 /**
155 * Set the exception that is part of the log record.
156 *
157 * @param {Object} exception the exception.
158 */
159 goog.debug.LogRecord.prototype.setException = function(exception) {
160 this.exception_ = exception;
161 };
162
163
164 /**
165 * Get the source Logger's name.
166 *
167 * @param {string} loggerName source logger name (may be null).
168 */
169 goog.debug.LogRecord.prototype.setLoggerName = function(loggerName) {
170 this.loggerName_ = loggerName;
171 };
172
173
174 /**
175 * Get the logging message level, for example Level.SEVERE.
176 * @return {goog.debug.Logger.Level} the logging message level.
177 */
178 goog.debug.LogRecord.prototype.getLevel = function() {
179 return this.level_;
180 };
181
182
183 /**
184 * Set the logging message level, for example Level.SEVERE.
185 * @param {goog.debug.Logger.Level} level the logging message level.
186 */
187 goog.debug.LogRecord.prototype.setLevel = function(level) {
188 this.level_ = level;
189 };
190
191
192 /**
193 * Get the "raw" log message, before localization or formatting.
194 *
195 * @return {string} the raw message string.
196 */
197 goog.debug.LogRecord.prototype.getMessage = function() {
198 return this.msg_;
199 };
200
201
202 /**
203 * Set the "raw" log message, before localization or formatting.
204 *
205 * @param {string} msg the raw message string.
206 */
207 goog.debug.LogRecord.prototype.setMessage = function(msg) {
208 this.msg_ = msg;
209 };
210
211
212 /**
213 * Get event time in milliseconds since 1970.
214 *
215 * @return {number} event time in millis since 1970.
216 */
217 goog.debug.LogRecord.prototype.getMillis = function() {
218 return this.time_;
219 };
220
221
222 /**
223 * Set event time in milliseconds since 1970.
224 *
225 * @param {number} time event time in millis since 1970.
226 */
227 goog.debug.LogRecord.prototype.setMillis = function(time) {
228 this.time_ = time;
229 };
230
231
232 /**
233 * Get the sequence number.
234 * <p>
235 * Sequence numbers are normally assigned in the LogRecord
236 * constructor, which assigns unique sequence numbers to
237 * each new LogRecord in increasing order.
238 * @return {number} the sequence number.
239 */
240 goog.debug.LogRecord.prototype.getSequenceNumber = function() {
241 return this.sequenceNumber_;
242 };