forked from daniloercoli/JS-XML-RPC-lib-for-WordPress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog4js.js
2509 lines (2268 loc) · 64.6 KB
/
log4js.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*jsl:option explicit*/
/**
* @fileoverview log4js is a library to log in JavaScript in similar manner
* than in log4j for Java. The API should be nearly the same.
*
* This file contains all log4js code and is the only file required for logging.
*
* <h3>Example:</h3>
* <pre>
* var log = new Log4js.getLogger("some-category-name"); //create logger instance
* log.setLevel(Log4js.Level.TRACE); //set the Level
* log.addAppender(new ConsoleAppender(log, false)); // console that launches in new window
* // if multiple appenders are set all will log
* log.addAppender(new ConsoleAppender(log, true)); // console that is in-line in the page
* log.addAppender(new FileAppender("C:\\somefile.log")); // file appender logs to C:\\somefile.log
*
* ...
*
* //call the log
* log.trace("trace me" );
* </pre>
*
* @version 0.3
* @author Stephan Strittmatter - http://jroller.com/page/stritti
* @author Seth Chisamore - http://www.chisamore.com
* @since 2005-05-20
* Website: http://log4js.berlios.de
*/
var Log4js = {
/**
* Current version of log4js.
* @static
* @final
*/
version: "1.0",
/**
* Date of logger initialized.
* @static
* @final
*/
applicationStartDate: new Date(),
/**
* Hashtable of loggers.
* @static
* @final
* @private
*/
loggers: {},
/**
* Get a logger instance. Instance is cached on categoryName level.
* @param {String} categoryName name of category to log to.
* @return {Logger} instance of logger for the category
* @static
*/
getLogger: function(categoryName) {
// Use default logger if categoryName is not specified or invalid
if (!(typeof categoryName == "string")) {
categoryName = "[default]";
}
if (!Log4js.loggers[categoryName]) {
// Create the logger for this name if it doesn't already exist
Log4js.loggers[categoryName] = new Log4js.Logger(categoryName);
}
return Log4js.loggers[categoryName];
},
/**
* Get the default logger instance.
* @return {Logger} instance of default logger
* @static
*/
getDefaultLogger: function() {
return Log4js.getLogger("[default]");
},
/**
* Atatch an observer function to an elements event browser independent.
*
* @param element element to attach event
* @param name name of event
* @param observer observer method to be called
* @private
*/
attachEvent: function (element, name, observer) {
if (element.addEventListener) { //DOM event model
element.addEventListener(name, observer, false);
} else if (element.attachEvent) { //M$ event model
element.attachEvent('on' + name, observer);
}
}
/**
* Load a JS-script dynamically.
* @param {String} src
*/
/* $import: function (src) {
var documentScripts = document.getElementsByTagName("script");
for (index = 0; index < documentScripts.length; ++index)
{
var documentScript = documentScripts[index];
if (documentScript.src == src) {
return false;
}
}
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = src;
document.getElementsByTagName('head')[0].appendChild(script);
return true;
}
*/
};
/**
* Internal object extension (OO) methods.
*
* @private
* @ignore
*/
Log4js.extend = function(destination, source) {
for (property in source) {
destination[property] = source[property];
}
return destination;
}
/**
* Functions taken from Prototype library,
* didn't want to require for just few functions.
* More info at {@link http://prototype.conio.net/}
* @private
*/
Log4js.bind = function(fn, object) {
return function() {
return fn.apply(object, arguments);
};
};
/**
* Log4js.Level Enumeration. Do not use directly. Use static objects instead.
* @constructor
* @param {Number} level number of level
* @param {String} levelString String representation of level
* @private
*/
Log4js.Level = function(level, levelStr) {
this.level = level;
this.levelStr = levelStr;
};
Log4js.Level.prototype = {
/**
* converts given String to corresponding Level
* @param {String} sArg String value of Level
* @param {Log4js.Level} defaultLevel default Level, if no String representation
* @return Level object
* @type Log4js.Level
*/
toLevel: function(sArg, defaultLevel) {
if(sArg === null) {
return defaultLevel;
}
if(typeof sArg == "string") {
var s = sArg.toUpperCase();
if(s == "ALL") {return Log4js.Level.ALL;}
if(s == "DEBUG") {return Log4js.Level.DEBUG;}
if(s == "INFO") {return Log4js.Level.INFO;}
if(s == "WARN") {return Log4js.Level.WARN;}
if(s == "ERROR") {return Log4js.Level.ERROR;}
if(s == "FATAL") {return Log4js.Level.FATAL;}
if(s == "OFF") {return Log4js.Level.OFF;}
if(s == "TRACE") {return Log4js.Level.TRACE;}
return defaultLevel;
} else if(typeof sArg == "number") {
switch(sArg) {
case ALL_INT: return Log4js.Level.ALL;
case DEBUG_INT: return Log4js.Level.DEBUG;
case INFO_INT: return Log4js.Level.INFO;
case WARN_INT: return Log4js.Level.WARN;
case ERROR_INT: return Log4js.Level.ERROR;
case FATAL_INT: return Log4js.Level.FATAL;
case OFF_INT: return Log4js.Level.OFF;
case TRACE_INT: return Log4js.Level.TRACE;
default: return defaultLevel;
}
} else {
return defaultLevel;
}
},
/**
* @return converted Level to String
* @type String
*/
toString: function() {
return this.levelStr;
},
/**
* @return internal Number value of Level
* @type Number
*/
valueOf: function() {
return this.level;
}
};
// Static variables
/**
* @private
*/
Log4js.Level.OFF_INT = Number.MAX_VALUE;
/**
* @private
*/
Log4js.Level.FATAL_INT = 50000;
/**
* @private
*/
Log4js.Level.ERROR_INT = 40000;
/**
* @private
*/
Log4js.Level.WARN_INT = 30000;
/**
* @private
*/
Log4js.Level.INFO_INT = 20000;
/**
* @private
*/
Log4js.Level.DEBUG_INT = 10000;
/**
* @private
*/
Log4js.Level.TRACE_INT = 5000;
/**
* @private
*/
Log4js.Level.ALL_INT = Number.MIN_VALUE;
/**
* Logging Level OFF - all disabled
* @type Log4js.Level
* @static
*/
Log4js.Level.OFF = new Log4js.Level(Log4js.Level.OFF_INT, "OFF");
/**
* Logging Level Fatal
* @type Log4js.Level
* @static
*/
Log4js.Level.FATAL = new Log4js.Level(Log4js.Level.FATAL_INT, "FATAL");
/**
* Logging Level Error
* @type Log4js.Level
* @static
*/
Log4js.Level.ERROR = new Log4js.Level(Log4js.Level.ERROR_INT, "ERROR");
/**
* Logging Level Warn
* @type Log4js.Level
* @static
*/
Log4js.Level.WARN = new Log4js.Level(Log4js.Level.WARN_INT, "WARN");
/**
* Logging Level Info
* @type Log4js.Level
* @static
*/
Log4js.Level.INFO = new Log4js.Level(Log4js.Level.INFO_INT, "INFO");
/**
* Logging Level Debug
* @type Log4js.Level
* @static
*/
Log4js.Level.DEBUG = new Log4js.Level(Log4js.Level.DEBUG_INT, "DEBUG");
/**
* Logging Level Trace
* @type Log4js.Level
* @static
*/
Log4js.Level.TRACE = new Log4js.Level(Log4js.Level.TRACE_INT, "TRACE");
/**
* Logging Level All - All traces are enabled
* @type Log4js.Level
* @static
*/
Log4js.Level.ALL = new Log4js.Level(Log4js.Level.ALL_INT, "ALL");
/**
* Log4js CustomEvent
* @constructor
* @author Corey Johnson - original code in Lumberjack (http://gleepglop.com/javascripts/logger/)
* @author Seth Chisamore - adapted for Log4js
* @private
*/
Log4js.CustomEvent = function() {
this.listeners = [];
};
Log4js.CustomEvent.prototype = {
/**
* @param method method to be added
*/
addListener : function(method) {
this.listeners.push(method);
},
/**
* @param method method to be removed
*/
removeListener : function(method) {
var foundIndexes = this.findListenerIndexes(method);
for(var i = 0; i < foundIndexes.length; i++) {
this.listeners.splice(foundIndexes[i], 1);
}
},
/**
* @param handler
*/
dispatch : function(handler) {
for(var i = 0; i < this.listeners.length; i++) {
try {
this.listeners[i](handler);
}
catch (e) {
log4jsLogger.warn("Could not run the listener " + this.listeners[i] + ". \n" + e);
}
}
},
/**
* @private
* @param method
*/
findListenerIndexes : function(method) {
var indexes = [];
for(var i = 0; i < this.listeners.length; i++) {
if (this.listeners[i] == method) {
indexes.push(i);
}
}
return indexes;
}
};
/**
* Models a logging event.
* @constructor
* @param {String} categoryName name of category
* @param {Log4js.Level} level level of message
* @param {String} message message to log
* @param {Log4js.Logger} logger the associated logger
* @author Seth Chisamore
*/
Log4js.LoggingEvent = function(categoryName, level, message, exception, logger) {
/**
* the timestamp of the Logging Event
* @type Date
* @private
*/
this.startTime = new Date();
/**
* category of event
* @type String
* @private
*/
this.categoryName = categoryName;
/**
* the logging message
* @type String
* @private
*/
this.message = message;
/**
* the logging exception
* @type Exception
* @private
*/
this.exception = exception;
/**
* level of log
* @type Log4js.Level
* @private
*/
this.level = level;
/**
* reference to logger
* @type Log4js.Logger
* @private
*/
this.logger = logger;
};
Log4js.LoggingEvent.prototype = {
/**
* get the timestamp formatted as String.
* @return {String} formatted timestamp
* @see Log4js#setDateFormat()
*/
getFormattedTimestamp: function() {
if(this.logger) {
return this.logger.getFormattedTimestamp(this.startTime);
} else {
return this.startTime.toGMTString();
}
}
};
/**
* Logger to log messages to the defined appender.</p>
* Default appender is Appender, which is ignoring all messages. Please
* use setAppender() to set a specific appender (e.g. WindowAppender).
* use {@see Log4js#getLogger(String)} to get an instance.
* @constructor
* @param name name of category to log to
* @author Stephan Strittmatter
*/
Log4js.Logger = function(name) {
this.loggingEvents = [];
this.appenders = [];
/** category of logger */
this.category = name || "";
/** level to be logged */
this.level = Log4js.Level.FATAL;
this.dateformat = Log4js.DateFormatter.DEFAULT_DATE_FORMAT;
this.dateformatter = new Log4js.DateFormatter();
this.onlog = new Log4js.CustomEvent();
this.onclear = new Log4js.CustomEvent();
/** appender to write in */
this.appenders.push(new Log4js.Appender(this));
// if multiple log objects are instantiated this will only log to the log
// object that is declared last can't seem to get the attachEvent method to
// work correctly
try {
window.onerror = this.windowError.bind(this);
} catch (e) {
//log4jsLogger.fatal(e);
}
};
Log4js.Logger.prototype = {
/**
* add additional appender. DefaultAppender always is there.
* @param appender additional wanted appender
*/
addAppender: function(appender) {
if (appender instanceof Log4js.Appender) {
appender.setLogger(this);
this.appenders.push(appender);
} else {
throw "Not instance of an Appender: " + appender;
}
},
/**
* set Array of appenders. Previous Appenders are cleared and removed.
* @param {Array} appenders Array of Appenders
*/
setAppenders: function(appenders) {
//clear first all existing appenders
for(var i = 0; i < this.appenders.length; i++) {
this.appenders[i].doClear();
}
this.appenders = appenders;
for(var j = 0; j < this.appenders.length; j++) {
this.appenders[j].setLogger(this);
}
},
/**
* Set the Loglevel default is LogLEvel.TRACE
* @param level wanted logging level
*/
setLevel: function(level) {
this.level = level;
},
/**
* main log method logging to all available appenders
* @private
*/
log: function(logLevel, message, exception) {
var loggingEvent = new Log4js.LoggingEvent(this.category, logLevel,
message, exception, this);
this.loggingEvents.push(loggingEvent);
this.onlog.dispatch(loggingEvent);
},
/** clear logging */
clear : function () {
try{
this.loggingEvents = [];
this.onclear.dispatch();
} catch(e){}
},
/** checks if Level Trace is enabled */
isTraceEnabled: function() {
if (this.level.valueOf() <= Log4js.Level.TRACE.valueOf()) {
return true;
}
return false;
},
/**
* Trace messages
* @param message {Object} message to be logged
*/
trace: function(message) {
if (this.isTraceEnabled()) {
this.log(Log4js.Level.TRACE, message, null);
}
},
/** checks if Level Debug is enabled */
isDebugEnabled: function() {
if (this.level.valueOf() <= Log4js.Level.DEBUG.valueOf()) {
return true;
}
return false;
},
/**
* Debug messages
* @param message {Object} message to be logged
*/
debug: function(message) {
if (this.isDebugEnabled()) {
this.log(Log4js.Level.DEBUG, message, null);
}
},
/**
* Debug messages
* @param {Object} message message to be logged
* @param {Throwable} throwable
*/
debug: function(message, throwable) {
if (this.isDebugEnabled()) {
this.log(Log4js.Level.DEBUG, message, throwable);
}
},
/** checks if Level Info is enabled */
isInfoEnabled: function() {
if (this.level.valueOf() <= Log4js.Level.INFO.valueOf()) {
return true;
}
return false;
},
/**
* logging info messages
* @param {Object} message message to be logged
*/
info: function(message) {
if (this.isInfoEnabled()) {
this.log(Log4js.Level.INFO, message, null);
}
},
/**
* logging info messages
* @param {Object} message message to be logged
* @param {Throwable} throwable
*/
info: function(message, throwable) {
if (this.isInfoEnabled()) {
this.log(Log4js.Level.INFO, message, throwable);
}
},
/** checks if Level Warn is enabled */
isWarnEnabled: function() {
if (this.level.valueOf() <= Log4js.Level.WARN.valueOf()) {
return true;
}
return false;
},
/** logging warn messages */
warn: function(message) {
if (this.isWarnEnabled()) {
this.log(Log4js.Level.WARN, message, null);
}
},
/** logging warn messages */
warn: function(message, throwable) {
if (this.isWarnEnabled()) {
this.log(Log4js.Level.WARN, message, throwable);
}
},
/** checks if Level Error is enabled */
isErrorEnabled: function() {
if (this.level.valueOf() <= Log4js.Level.ERROR.valueOf()) {
return true;
}
return false;
},
/** logging error messages */
error: function(message) {
if (this.isErrorEnabled()) {
this.log(Log4js.Level.ERROR, message, null);
}
},
/** logging error messages */
error: function(message, throwable) {
if (this.isErrorEnabled()) {
this.log(Log4js.Level.ERROR, message, throwable);
}
},
/** checks if Level Fatal is enabled */
isFatalEnabled: function() {
if (this.level.valueOf() <= Log4js.Level.FATAL.valueOf()) {
return true;
}
return false;
},
/** logging fatal messages */
fatal: function(message) {
if (this.isFatalEnabled()) {
this.log(Log4js.Level.FATAL, message, null);
}
},
/** logging fatal messages */
fatal: function(message, throwable) {
if (this.isFatalEnabled()) {
this.log(Log4js.Level.FATAL, message, throwable);
}
},
/**
* Capture main window errors and log as fatal.
* @private
*/
windowError: function(msg, url, line){
var message = "Error in (" + (url || window.location) + ") on line "+ line +" with message (" + msg + ")";
this.log(Log4js.Level.FATAL, message, null);
},
/**
* Set the date format of logger. Following switches are supported:
* <ul>
* <li>yyyy - The year</li>
* <li>MM - the month</li>
* <li>dd - the day of month<li>
* <li>hh - the hour<li>
* <li>mm - minutes</li>
* <li>O - timezone offset</li>
* </ul>
* @param {String} format format String for the date
* @see #getTimestamp
*/
setDateFormat: function(format) {
this.dateformat = format;
},
/**
* Generates a timestamp using the format set in {Log4js.setDateFormat}.
* @param {Date} date the date to format
* @see #setDateFormat
* @return A formatted timestamp with the current date and time.
*/
getFormattedTimestamp: function(date) {
return this.dateformatter.formatDate(date, this.dateformat);
}
};
/**
* Abstract base class for other appenders.
* It is doing nothing.
*
* @constructor
* @param {Log4js.Logger} logger log4js instance this appender is attached to
* @author Stephan Strittmatter
*/
Log4js.Appender = function () {
/**
* Reference to calling logger
* @type Log4js.Logger
* @private
*/
this.logger = null;
};
Log4js.Appender.prototype = {
/**
* appends the given loggingEvent appender specific
* @param {Log4js.LoggingEvent} loggingEvent loggingEvent to append
*/
doAppend: function(loggingEvent) {
return;
},
/**
* clears the Appender
*/
doClear: function() {
return;
},
/**
* Set the Layout for this appender.
* @param {Log4js.Layout} layout Layout for formatting loggingEvent
*/
setLayout: function(layout){
this.layout = layout;
},
/**
* Set reference to the logger.
* @param {Log4js.Logger} the invoking logger
*/
setLogger: function(logger){
// add listener to the logger methods
logger.onlog.addListener(Log4js.bind(this.doAppend, this));
logger.onclear.addListener(Log4js.bind(this.doClear, this));
this.logger = logger;
}
};
/**
* Interface for Layouts.
* Use this Layout as "interface" for other Layouts. It is doing nothing.
*
* @constructor
* @author Stephan Strittmatter
*/
Log4js.Layout = function(){return;};
Log4js.Layout.prototype = {
/**
* Implement this method to create your own layout format.
* @param {Log4js.LoggingEvent} loggingEvent loggingEvent to format
* @return formatted String
* @type String
*/
format: function(loggingEvent) {
return "";
},
/**
* Returns the content type output by this layout.
* @return The base class returns "text/plain".
* @type String
*/
getContentType: function() {
return "text/plain";
},
/**
* @return Returns the header for the layout format. The base class returns null.
* @type String
*/
getHeader: function() {
return null;
},
/**
* @return Returns the footer for the layout format. The base class returns null.
* @type String
*/
getFooter: function() {
return null;
},
/**
* @return Separator between events
* @type String
*/
getSeparator: function() {
return "";
}
};
/**
* Console Appender writes the logs to a console. If "inline" is
* set to "false" the console launches in another window otherwise
* the window is inline on the page and toggled on and off with "Alt-D".
* Note: At FireFox &gb; 2.0 the keystroke is little different now: "SHIFT+ALT+D".
*
* @constructor
* @extends Log4js.Appender
* @param {boolean} isInline boolean value that indicates whether the console be placed inline, default is to launch in new window
*
* @author Corey Johnson - original console code in Lumberjack (http://gleepglop.com/javascripts/logger/)
* @author Seth Chisamore - adapted for use as a log4js appender
*/
Log4js.ConsoleAppender = function(isInline) {
/**
* @type Log4js.Layout
* @private
*/
this.layout = new Log4js.PatternLayout(Log4js.PatternLayout.TTCC_CONVERSION_PATTERN);
/**
* @type boolean
* @private
*/
this.inline = isInline;
/**
* @type String
* @private
*/
this.accesskey = "d";
/**
* @private
*/
this.tagPattern = null;
this.commandHistory = [];
this.commandIndex = 0;
/**
* true if popup is blocked.
*/
this.popupBlocker = false;
/**
* current output div-element.
*/
this.outputElement = null;
this.docReference = null;
this.winReference = null;
if(this.inline) {
Log4js.attachEvent(window, 'load', Log4js.bind(this.initialize, this));
}
};
Log4js.ConsoleAppender.prototype = Log4js.extend(new Log4js.Appender(), {
/**
* Set the access key to show/hide the inline console (default "e;d"e;)
* @param key access key to show/hide the inline console
*/
setAccessKey : function(key) {
this.accesskey = key;
},
/**
* @private
*/
initialize : function() {
if(!this.inline) {
var doc = null;
var win = null;
window.top.consoleWindow = window.open("", this.logger.category,
"left=0,top=0,width=700,height=700,scrollbars=no,status=no,resizable=yes;toolbar=no");
window.top.consoleWindow.opener = self;
win = window.top.consoleWindow;
if (!win) {
this.popupBlocker=true;
alert("Popup window manager blocking the Log4js popup window to bedisplayed.\n\n"
+ "Please disabled this to properly see logged events.");
} else {
doc = win.document;
doc.open();
doc.write("<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN ");
doc.write(" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>\n\n");
doc.write("<html><head><title>Log4js - " + this.logger.category + "</title>\n");
doc.write("</head><body style=\"background-color:darkgray\"></body>\n");
win.blur();
win.focus();
}
this.docReference = doc;
this.winReference = win;
} else {
this.docReference = document;
this.winReference = window;
}
this.outputCount = 0;
this.tagPattern = ".*";
// I hate writing javascript in HTML... but what's a better alternative
this.logElement = this.docReference.createElement('div');
this.docReference.body.appendChild(this.logElement);
this.logElement.style.display = 'none';
this.logElement.style.position = "absolute";
this.logElement.style.left = '0px';
this.logElement.style.width = '100%';
this.logElement.style.textAlign = "left";
this.logElement.style.fontFamily = "lucida console";
this.logElement.style.fontSize = "100%";
this.logElement.style.backgroundColor = 'darkgray';
this.logElement.style.opacity = 0.9;
this.logElement.style.zIndex = 2000;
// Add toolbarElement
this.toolbarElement = this.docReference.createElement('div');
this.logElement.appendChild(this.toolbarElement);
this.toolbarElement.style.padding = "0 0 0 2px";
// Add buttons
this.buttonsContainerElement = this.docReference.createElement('span');
this.toolbarElement.appendChild(this.buttonsContainerElement);
if(this.inline) {
var closeButton = this.docReference.createElement('button');
closeButton.style.cssFloat = "right";
closeButton.style.styleFloat = "right"; // IE dom bug...doesn't understand cssFloat
closeButton.style.color = "black";
closeButton.innerHTML = "close";
closeButton.onclick = Log4js.bind(this.toggle, this);
this.buttonsContainerElement.appendChild(closeButton);
}
var clearButton = this.docReference.createElement('button');
clearButton.style.cssFloat = "right";
clearButton.style.styleFloat = "right"; // IE dom bug...doesn't understand cssFloat
clearButton.style.color = "black";
clearButton.innerHTML = "clear";
clearButton.onclick = Log4js.bind(this.logger.clear, this.logger);
this.buttonsContainerElement.appendChild(clearButton);
//Add CategoryName and Level Filter
this.tagFilterContainerElement = this.docReference.createElement('span');
this.toolbarElement.appendChild(this.tagFilterContainerElement);
this.tagFilterContainerElement.style.cssFloat = 'left';
this.tagFilterContainerElement.appendChild(this.docReference.createTextNode("Log4js - " + this.logger.category));
this.tagFilterContainerElement.appendChild(this.docReference.createTextNode(" | Level Filter: "));
this.tagFilterElement = this.docReference.createElement('input');
this.tagFilterContainerElement.appendChild(this.tagFilterElement);
this.tagFilterElement.style.width = '200px';
this.tagFilterElement.value = this.tagPattern;
this.tagFilterElement.setAttribute('autocomplete', 'off'); // So Firefox doesn't flip out
Log4js.attachEvent(this.tagFilterElement, 'keyup', Log4js.bind(this.updateTags, this));
Log4js.attachEvent(this.tagFilterElement, 'click', Log4js.bind( function() {this.tagFilterElement.select();}, this));
// Add outputElement
this.outputElement = this.docReference.createElement('div');
this.logElement.appendChild(this.outputElement);
this.outputElement.style.overflow = "auto";
this.outputElement.style.clear = "both";
this.outputElement.style.height = (this.inline) ? ("200px"):("650px");
this.outputElement.style.width = "100%";
this.outputElement.style.backgroundColor = 'black';
this.inputContainerElement = this.docReference.createElement('div');
this.inputContainerElement.style.width = "100%";
this.logElement.appendChild(this.inputContainerElement);
this.inputElement = this.docReference.createElement('input');
this.inputContainerElement.appendChild(this.inputElement);
this.inputElement.style.width = '100%';
this.inputElement.style.borderWidth = '0px'; // Inputs with 100% width always seem to be too large (I HATE THEM) they only work if the border, margin and padding are 0
this.inputElement.style.margin = '0px';
this.inputElement.style.padding = '0px';
this.inputElement.value = 'Type command here';
this.inputElement.setAttribute('autocomplete', 'off'); // So Firefox doesn't flip out
Log4js.attachEvent(this.inputElement, 'keyup', Log4js.bind(this.handleInput, this));
Log4js.attachEvent(this.inputElement, 'click', Log4js.bind( function() {this.inputElement.select();}, this));
if(this.inline){
window.setInterval(Log4js.bind(this.repositionWindow, this), 500);
this.repositionWindow();
// Allow acess key link
var accessElement = this.docReference.createElement('button');
accessElement.style.position = "absolute";
accessElement.style.top = "-100px";
accessElement.accessKey = this.accesskey;