View | Details | Raw Unified | Return to bug 40212
Collapse All | Expand All

(-)tests/src/java/org/apache/log4j/CategoryTest.java (-1 / +1 lines)
Lines 96-102 Link Here
96
     */
96
     */
97
    public MockCategory(final String name) {
97
    public MockCategory(final String name) {
98
      super(name);
98
      super(name);
99
      repository = new Hierarchy(this);
99
      setHierarchy(new Hierarchy(this));
100
    }
100
    }
101
101
102
    /**
102
    /**
(-)tests/src/java/org/apache/log4j/customLogger/XLogger.java (-4 / +4 lines)
Lines 72-78 Link Here
72
     XLevel#LETHAL}.  */
72
     XLevel#LETHAL}.  */
73
  public
73
  public
74
  void lethal(String message, Throwable t) { 
74
  void lethal(String message, Throwable t) { 
75
    if(repository.isDisabled(XLevel.LETHAL_INT)) 
75
    if(getLoggerRepository().isDisabled(XLevel.LETHAL_INT)) 
76
      return;
76
      return;
77
    if(XLevel.LETHAL.isGreaterOrEqual(this.getEffectiveLevel()))
77
    if(XLevel.LETHAL.isGreaterOrEqual(this.getEffectiveLevel()))
78
      forcedLog(FQCN, XLevel.LETHAL, message, t);
78
      forcedLog(FQCN, XLevel.LETHAL, message, t);
Lines 83-89 Link Here
83
     XLevel#LETHAL}.  */
83
     XLevel#LETHAL}.  */
84
  public
84
  public
85
  void lethal(String message) { 
85
  void lethal(String message) { 
86
    if(repository.isDisabled(XLevel.LETHAL_INT)) 
86
    if(getLoggerRepository().isDisabled(XLevel.LETHAL_INT)) 
87
      return;
87
      return;
88
    if(XLevel.LETHAL.isGreaterOrEqual(this.getEffectiveLevel()))
88
    if(XLevel.LETHAL.isGreaterOrEqual(this.getEffectiveLevel()))
89
      forcedLog(FQCN, XLevel.LETHAL, message, null);
89
      forcedLog(FQCN, XLevel.LETHAL, message, null);
Lines 117-123 Link Here
117
  */
117
  */
118
  public
118
  public
119
  void trace(String message, Throwable t) { 
119
  void trace(String message, Throwable t) { 
120
    if(repository.isDisabled(XLevel.TRACE_INT))
120
    if(getLoggerRepository().isDisabled(XLevel.TRACE_INT))
121
      return;   
121
      return;   
122
    if(XLevel.TRACE.isGreaterOrEqual(this.getEffectiveLevel()))
122
    if(XLevel.TRACE.isGreaterOrEqual(this.getEffectiveLevel()))
123
      forcedLog(FQCN, XLevel.TRACE, message, t);
123
      forcedLog(FQCN, XLevel.TRACE, message, t);
Lines 128-134 Link Here
128
  */
128
  */
129
  public
129
  public
130
  void trace(String message) { 
130
  void trace(String message) { 
131
    if(repository.isDisabled(XLevel.TRACE_INT))
131
    if(getLoggerRepository().isDisabled(XLevel.TRACE_INT))
132
      return;   
132
      return;   
133
    if(XLevel.TRACE.isGreaterOrEqual(this.getEffectiveLevel()))
133
    if(XLevel.TRACE.isGreaterOrEqual(this.getEffectiveLevel()))
134
      forcedLog(FQCN, XLevel.TRACE, message, null);
134
      forcedLog(FQCN, XLevel.TRACE, message, null);
(-)src/main/java/org/apache/log4j/spi/NOPLogger.java (-1 / +1 lines)
Lines 37-43 Link Here
37
     */
37
     */
38
    public NOPLogger(NOPLoggerRepository repo, final String name) {
38
    public NOPLogger(NOPLoggerRepository repo, final String name) {
39
        super(name);
39
        super(name);
40
        this.repository = repo;
40
        setHierarchy(repo);
41
        this.level = Level.OFF;
41
        this.level = Level.OFF;
42
        this.parent = this;
42
        this.parent = this;
43
    }
43
    }
(-)src/main/java/org/apache/log4j/Category.java (-22 / +35 lines)
Lines 35-42 Link Here
35
import org.apache.log4j.spi.LoggingEvent;
35
import org.apache.log4j.spi.LoggingEvent;
36
import org.apache.log4j.spi.LoggerRepository;
36
import org.apache.log4j.spi.LoggerRepository;
37
import org.apache.log4j.spi.HierarchyEventListener;
37
import org.apache.log4j.spi.HierarchyEventListener;
38
import org.apache.log4j.spi.NOPLoggerRepository;
38
import org.apache.log4j.helpers.NullEnumeration;
39
import org.apache.log4j.helpers.NullEnumeration;
39
import org.apache.log4j.helpers.AppenderAttachableImpl;
40
import org.apache.log4j.helpers.AppenderAttachableImpl;
41
import org.apache.log4j.helpers.LogLog;
40
42
41
import java.util.Enumeration;
43
import java.util.Enumeration;
42
import java.util.MissingResourceException;
44
import java.util.MissingResourceException;
Lines 120-126 Link Here
120
  protected ResourceBundle resourceBundle;
122
  protected ResourceBundle resourceBundle;
121
123
122
  // Categories need to know what Hierarchy they are in
124
  // Categories need to know what Hierarchy they are in
123
  protected LoggerRepository repository;
125
  private LoggerRepository repository;
126
  // Remember who set the repository to null
127
  private Exception nulledBy;
124
128
125
129
126
  AppenderAttachableImpl aai;
130
  AppenderAttachableImpl aai;
Lines 162-168 Link Here
162
      aai = new AppenderAttachableImpl();
166
      aai = new AppenderAttachableImpl();
163
    }
167
    }
164
    aai.addAppender(newAppender);
168
    aai.addAppender(newAppender);
165
    repository.fireAddAppenderEvent(this, newAppender);
169
    getLoggerRepository().fireAddAppenderEvent(this, newAppender);
166
  }
170
  }
167
171
168
  /**
172
  /**
Lines 212-218 Link Here
212
    }
216
    }
213
217
214
    if(writes == 0) {
218
    if(writes == 0) {
215
      repository.emitNoAppenderWarning(this);
219
      getLoggerRepository().emitNoAppenderWarning(this);
216
    }
220
    }
217
  }
221
  }
218
222
Lines 254-260 Link Here
254
    @param message the message object to log. */
258
    @param message the message object to log. */
255
  public
259
  public
256
  void debug(Object message) {
260
  void debug(Object message) {
257
    if(repository.isDisabled(Level.DEBUG_INT))
261
    if(getLoggerRepository().isDisabled(Level.DEBUG_INT))
258
      return;
262
      return;
259
    if(Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel())) {
263
    if(Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel())) {
260
      forcedLog(FQCN, Level.DEBUG, message, null);
264
      forcedLog(FQCN, Level.DEBUG, message, null);
Lines 273-279 Link Here
273
   @param t the exception to log, including its stack trace.  */
277
   @param t the exception to log, including its stack trace.  */
274
  public
278
  public
275
  void debug(Object message, Throwable t) {
279
  void debug(Object message, Throwable t) {
276
    if(repository.isDisabled(Level.DEBUG_INT))
280
    if(getLoggerRepository().isDisabled(Level.DEBUG_INT))
277
      return;
281
      return;
278
    if(Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel()))
282
    if(Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel()))
279
      forcedLog(FQCN, Level.DEBUG, message, t);
283
      forcedLog(FQCN, Level.DEBUG, message, t);
Lines 299-305 Link Here
299
    @param message the message object to log */
303
    @param message the message object to log */
300
  public
304
  public
301
  void error(Object message) {
305
  void error(Object message) {
302
    if(repository.isDisabled(Level.ERROR_INT))
306
    if(getLoggerRepository().isDisabled(Level.ERROR_INT))
303
      return;
307
      return;
304
    if(Level.ERROR.isGreaterOrEqual(this.getEffectiveLevel()))
308
    if(Level.ERROR.isGreaterOrEqual(this.getEffectiveLevel()))
305
      forcedLog(FQCN, Level.ERROR, message, null);
309
      forcedLog(FQCN, Level.ERROR, message, null);
Lines 316-322 Link Here
316
   @param t the exception to log, including its stack trace.  */
320
   @param t the exception to log, including its stack trace.  */
317
  public
321
  public
318
  void error(Object message, Throwable t) {
322
  void error(Object message, Throwable t) {
319
    if(repository.isDisabled(Level.ERROR_INT))
323
    if(getLoggerRepository().isDisabled(Level.ERROR_INT))
320
      return;
324
      return;
321
    if(Level.ERROR.isGreaterOrEqual(this.getEffectiveLevel()))
325
    if(Level.ERROR.isGreaterOrEqual(this.getEffectiveLevel()))
322
      forcedLog(FQCN, Level.ERROR, message, t);
326
      forcedLog(FQCN, Level.ERROR, message, t);
Lines 359-365 Link Here
359
    @param message the message object to log */
363
    @param message the message object to log */
360
  public
364
  public
361
  void fatal(Object message) {
365
  void fatal(Object message) {
362
    if(repository.isDisabled(Level.FATAL_INT))
366
    if(getLoggerRepository().isDisabled(Level.FATAL_INT))
363
      return;
367
      return;
364
    if(Level.FATAL.isGreaterOrEqual(this.getEffectiveLevel()))
368
    if(Level.FATAL.isGreaterOrEqual(this.getEffectiveLevel()))
365
      forcedLog(FQCN, Level.FATAL, message, null);
369
      forcedLog(FQCN, Level.FATAL, message, null);
Lines 376-382 Link Here
376
   @param t the exception to log, including its stack trace.  */
380
   @param t the exception to log, including its stack trace.  */
377
  public
381
  public
378
  void fatal(Object message, Throwable t) {
382
  void fatal(Object message, Throwable t) {
379
    if(repository.isDisabled(Level.FATAL_INT))
383
    if(getLoggerRepository().isDisabled(Level.FATAL_INT))
380
      return;
384
      return;
381
    if(Level.FATAL.isGreaterOrEqual(this.getEffectiveLevel()))
385
    if(Level.FATAL.isGreaterOrEqual(this.getEffectiveLevel()))
382
      forcedLog(FQCN, Level.FATAL, message, t);
386
      forcedLog(FQCN, Level.FATAL, message, t);
Lines 499-505 Link Here
499
     @since 1.1 */
503
     @since 1.1 */
500
  public
504
  public
501
  LoggerRepository  getHierarchy() {
505
  LoggerRepository  getHierarchy() {
502
    return repository;
506
    return getLoggerRepository();
503
  }
507
  }
504
508
505
  /**
509
  /**
Lines 509-514 Link Here
509
     @since 1.2 */
513
     @since 1.2 */
510
  public
514
  public
511
  LoggerRepository  getLoggerRepository() {
515
  LoggerRepository  getLoggerRepository() {
516
    if (repository == null) {
517
	LogLog.error("Category.repository was null likely due to error in class reloading or someone setting it to null. Using NOPLoggerRepository.", nulledBy);
518
	repository = new NOPLoggerRepository();
519
    }
512
    return repository;
520
    return repository;
513
  }
521
  }
514
522
Lines 660-666 Link Here
660
    @param message the message object to log */
668
    @param message the message object to log */
661
  public
669
  public
662
  void info(Object message) {
670
  void info(Object message) {
663
    if(repository.isDisabled(Level.INFO_INT))
671
    if(getLoggerRepository().isDisabled(Level.INFO_INT))
664
      return;
672
      return;
665
    if(Level.INFO.isGreaterOrEqual(this.getEffectiveLevel()))
673
    if(Level.INFO.isGreaterOrEqual(this.getEffectiveLevel()))
666
      forcedLog(FQCN, Level.INFO, message, null);
674
      forcedLog(FQCN, Level.INFO, message, null);
Lines 677-683 Link Here
677
   @param t the exception to log, including its stack trace.  */
685
   @param t the exception to log, including its stack trace.  */
678
  public
686
  public
679
  void info(Object message, Throwable t) {
687
  void info(Object message, Throwable t) {
680
    if(repository.isDisabled(Level.INFO_INT))
688
    if(getLoggerRepository().isDisabled(Level.INFO_INT))
681
      return;
689
      return;
682
    if(Level.INFO.isGreaterOrEqual(this.getEffectiveLevel()))
690
    if(Level.INFO.isGreaterOrEqual(this.getEffectiveLevel()))
683
      forcedLog(FQCN, Level.INFO, message, t);
691
      forcedLog(FQCN, Level.INFO, message, t);
Lines 731-737 Link Here
731
    *   */
739
    *   */
732
  public
740
  public
733
  boolean isDebugEnabled() {
741
  boolean isDebugEnabled() {
734
    if(repository.isDisabled( Level.DEBUG_INT))
742
    if(getLoggerRepository().isDisabled( Level.DEBUG_INT))
735
      return false;
743
      return false;
736
    return Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel());
744
    return Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel());
737
  }
745
  }
Lines 746-752 Link Here
746
  */
754
  */
747
  public
755
  public
748
  boolean isEnabledFor(Priority level) {
756
  boolean isEnabledFor(Priority level) {
749
    if(repository.isDisabled(level.level))
757
    if(getLoggerRepository().isDisabled(level.level))
750
      return false;
758
      return false;
751
    return level.isGreaterOrEqual(this.getEffectiveLevel());
759
    return level.isGreaterOrEqual(this.getEffectiveLevel());
752
  }
760
  }
Lines 760-766 Link Here
760
  */
768
  */
761
  public
769
  public
762
  boolean isInfoEnabled() {
770
  boolean isInfoEnabled() {
763
    if(repository.isDisabled(Level.INFO_INT))
771
    if(getLoggerRepository().isDisabled(Level.INFO_INT))
764
      return false;
772
      return false;
765
    return Level.INFO.isGreaterOrEqual(this.getEffectiveLevel());
773
    return Level.INFO.isGreaterOrEqual(this.getEffectiveLevel());
766
  }
774
  }
Lines 776-782 Link Here
776
     @since 0.8.4 */
784
     @since 0.8.4 */
777
  public
785
  public
778
  void l7dlog(Priority priority, String key, Throwable t) {
786
  void l7dlog(Priority priority, String key, Throwable t) {
779
    if(repository.isDisabled(priority.level)) {
787
    if(getLoggerRepository().isDisabled(priority.level)) {
780
      return;
788
      return;
781
    }
789
    }
782
    if(priority.isGreaterOrEqual(this.getEffectiveLevel())) {
790
    if(priority.isGreaterOrEqual(this.getEffectiveLevel())) {
Lines 800-806 Link Here
800
  */
808
  */
801
  public
809
  public
802
  void l7dlog(Priority priority, String key,  Object[] params, Throwable t) {
810
  void l7dlog(Priority priority, String key,  Object[] params, Throwable t) {
803
    if(repository.isDisabled(priority.level)) {
811
    if(getLoggerRepository().isDisabled(priority.level)) {
804
      return;
812
      return;
805
    }
813
    }
806
    if(priority.isGreaterOrEqual(this.getEffectiveLevel())) {
814
    if(priority.isGreaterOrEqual(this.getEffectiveLevel())) {
Lines 819-825 Link Here
819
   */
827
   */
820
  public
828
  public
821
  void log(Priority priority, Object message, Throwable t) {
829
  void log(Priority priority, Object message, Throwable t) {
822
    if(repository.isDisabled(priority.level)) {
830
    if(getLoggerRepository().isDisabled(priority.level)) {
823
      return;
831
      return;
824
    }
832
    }
825
    if(priority.isGreaterOrEqual(this.getEffectiveLevel()))
833
    if(priority.isGreaterOrEqual(this.getEffectiveLevel()))
Lines 831-837 Link Here
831
 */
839
 */
832
  public
840
  public
833
  void log(Priority priority, Object message) {
841
  void log(Priority priority, Object message) {
834
    if(repository.isDisabled(priority.level)) {
842
    if(getLoggerRepository().isDisabled(priority.level)) {
835
      return;
843
      return;
836
    }
844
    }
837
    if(priority.isGreaterOrEqual(this.getEffectiveLevel()))
845
    if(priority.isGreaterOrEqual(this.getEffectiveLevel()))
Lines 849-855 Link Here
849
     @param t The throwable of the logging request, may be null.  */
857
     @param t The throwable of the logging request, may be null.  */
850
  public
858
  public
851
  void log(String callerFQCN, Priority level, Object message, Throwable t) {
859
  void log(String callerFQCN, Priority level, Object message, Throwable t) {
852
    if(repository.isDisabled(level.level)) {
860
    if(getLoggerRepository().isDisabled(level.level)) {
853
      return;
861
      return;
854
    }
862
    }
855
    if(level.isGreaterOrEqual(this.getEffectiveLevel())) {
863
    if(level.isGreaterOrEqual(this.getEffectiveLevel())) {
Lines 942-949 Link Here
942
  /**
950
  /**
943
     Only the Hiearchy class can set the hiearchy of a
951
     Only the Hiearchy class can set the hiearchy of a
944
     category. Default package access is MANDATORY here.  */
952
     category. Default package access is MANDATORY here.  */
953
  protected // TODO Must be protected for NOPLogger and CategoryTest.
945
  final
954
  final
946
  void setHierarchy(LoggerRepository repository) {
955
  void setHierarchy(LoggerRepository repository) {
956
    nulledBy = null;
957
    if (repository == null) {
958
	nulledBy = new Exception("Repository was nulled here.");
959
    }
947
    this.repository = repository;
960
    this.repository = repository;
948
  }
961
  }
949
962
Lines 1036-1042 Link Here
1036
    @param message the message object to log.  */
1049
    @param message the message object to log.  */
1037
  public
1050
  public
1038
  void warn(Object message) {
1051
  void warn(Object message) {
1039
    if(repository.isDisabled( Level.WARN_INT))
1052
    if(getLoggerRepository().isDisabled( Level.WARN_INT))
1040
      return;
1053
      return;
1041
1054
1042
    if(Level.WARN.isGreaterOrEqual(this.getEffectiveLevel()))
1055
    if(Level.WARN.isGreaterOrEqual(this.getEffectiveLevel()))
Lines 1054-1060 Link Here
1054
   @param t the exception to log, including its stack trace.  */
1067
   @param t the exception to log, including its stack trace.  */
1055
  public
1068
  public
1056
  void warn(Object message, Throwable t) {
1069
  void warn(Object message, Throwable t) {
1057
    if(repository.isDisabled(Level.WARN_INT))
1070
    if(getLoggerRepository().isDisabled(Level.WARN_INT))
1058
      return;
1071
      return;
1059
    if(Level.WARN.isGreaterOrEqual(this.getEffectiveLevel()))
1072
    if(Level.WARN.isGreaterOrEqual(this.getEffectiveLevel()))
1060
      forcedLog(FQCN, Level.WARN, message, t);
1073
      forcedLog(FQCN, Level.WARN, message, t);
(-)src/main/java/org/apache/log4j/Logger.java (-5 / +5 lines)
Lines 62-68 Link Here
62
    @param message the message object to log. */
62
    @param message the message object to log. */
63
  //public
63
  //public
64
  //void fine(Object message) {
64
  //void fine(Object message) {
65
  //  if(repository.isDisabled(Level.DEBUG_INT))
65
  //  if(getLoggerRepository().isDisabled(Level.DEBUG_INT))
66
  //	return;
66
  //	return;
67
  //  if(Level.DEBUG.isGreaterOrEqual(this.getChainedLevel())) {
67
  //  if(Level.DEBUG.isGreaterOrEqual(this.getChainedLevel())) {
68
  //	forcedLog(FQCN, Level.DEBUG, message, null);
68
  //	forcedLog(FQCN, Level.DEBUG, message, null);
Lines 81-87 Link Here
81
   @param t the exception to log, including its stack trace.  */
81
   @param t the exception to log, including its stack trace.  */
82
  //public
82
  //public
83
  //void fine(Object message, Throwable t) {
83
  //void fine(Object message, Throwable t) {
84
  //  if(repository.isDisabled(Level.DEBUG_INT))
84
  //  if(getLoggerRepository().isDisabled(Level.DEBUG_INT))
85
  //	return;
85
  //	return;
86
  //  if(Level.DEBUG.isGreaterOrEqual(this.getChainedLevel()))
86
  //  if(Level.DEBUG.isGreaterOrEqual(this.getChainedLevel()))
87
  //	forcedLog(FQCN, Level.FINE, message, t);
87
  //	forcedLog(FQCN, Level.FINE, message, t);
Lines 164-170 Link Here
164
     * @since 1.2.12
164
     * @since 1.2.12
165
     */
165
     */
166
    public void trace(Object message) {
166
    public void trace(Object message) {
167
      if (repository.isDisabled(Level.TRACE_INT)) {
167
      if (getLoggerRepository().isDisabled(Level.TRACE_INT)) {
168
        return;
168
        return;
169
      }
169
      }
170
170
Lines 186-192 Link Here
186
     * @since 1.2.12
186
     * @since 1.2.12
187
     */
187
     */
188
    public void trace(Object message, Throwable t) {
188
    public void trace(Object message, Throwable t) {
189
      if (repository.isDisabled(Level.TRACE_INT)) {
189
      if (getLoggerRepository().isDisabled(Level.TRACE_INT)) {
190
        return;
190
        return;
191
      }
191
      }
192
192
Lines 203-209 Link Here
203
     *         TRACE, <code>false</code> otherwise.
203
     *         TRACE, <code>false</code> otherwise.
204
     */
204
     */
205
    public boolean isTraceEnabled() {
205
    public boolean isTraceEnabled() {
206
        if (repository.isDisabled(Level.TRACE_INT)) {
206
        if (getLoggerRepository().isDisabled(Level.TRACE_INT)) {
207
            return false;
207
            return false;
208
          }
208
          }
209
209

Return to bug 40212