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 / +36 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 119-126 Link Here
119
121
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
125
      @deprecated Use getLoggerRepository() and setHierarchy() instead. */
123
  protected LoggerRepository repository;
126
  protected LoggerRepository repository;
127
  // Remember who set the repository to null
128
  private Exception nulledBy;
124
129
125
130
126
  AppenderAttachableImpl aai;
131
  AppenderAttachableImpl aai;
Lines 162-168 Link Here
162
      aai = new AppenderAttachableImpl();
167
      aai = new AppenderAttachableImpl();
163
    }
168
    }
164
    aai.addAppender(newAppender);
169
    aai.addAppender(newAppender);
165
    repository.fireAddAppenderEvent(this, newAppender);
170
    getLoggerRepository().fireAddAppenderEvent(this, newAppender);
166
  }
171
  }
167
172
168
  /**
173
  /**
Lines 212-218 Link Here
212
    }
217
    }
213
218
214
    if(writes == 0) {
219
    if(writes == 0) {
215
      repository.emitNoAppenderWarning(this);
220
      getLoggerRepository().emitNoAppenderWarning(this);
216
    }
221
    }
217
  }
222
  }
218
223
Lines 254-260 Link Here
254
    @param message the message object to log. */
259
    @param message the message object to log. */
255
  public
260
  public
256
  void debug(Object message) {
261
  void debug(Object message) {
257
    if(repository.isDisabled(Level.DEBUG_INT))
262
    if(getLoggerRepository().isDisabled(Level.DEBUG_INT))
258
      return;
263
      return;
259
    if(Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel())) {
264
    if(Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel())) {
260
      forcedLog(FQCN, Level.DEBUG, message, null);
265
      forcedLog(FQCN, Level.DEBUG, message, null);
Lines 273-279 Link Here
273
   @param t the exception to log, including its stack trace.  */
278
   @param t the exception to log, including its stack trace.  */
274
  public
279
  public
275
  void debug(Object message, Throwable t) {
280
  void debug(Object message, Throwable t) {
276
    if(repository.isDisabled(Level.DEBUG_INT))
281
    if(getLoggerRepository().isDisabled(Level.DEBUG_INT))
277
      return;
282
      return;
278
    if(Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel()))
283
    if(Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel()))
279
      forcedLog(FQCN, Level.DEBUG, message, t);
284
      forcedLog(FQCN, Level.DEBUG, message, t);
Lines 299-305 Link Here
299
    @param message the message object to log */
304
    @param message the message object to log */
300
  public
305
  public
301
  void error(Object message) {
306
  void error(Object message) {
302
    if(repository.isDisabled(Level.ERROR_INT))
307
    if(getLoggerRepository().isDisabled(Level.ERROR_INT))
303
      return;
308
      return;
304
    if(Level.ERROR.isGreaterOrEqual(this.getEffectiveLevel()))
309
    if(Level.ERROR.isGreaterOrEqual(this.getEffectiveLevel()))
305
      forcedLog(FQCN, Level.ERROR, message, null);
310
      forcedLog(FQCN, Level.ERROR, message, null);
Lines 316-322 Link Here
316
   @param t the exception to log, including its stack trace.  */
321
   @param t the exception to log, including its stack trace.  */
317
  public
322
  public
318
  void error(Object message, Throwable t) {
323
  void error(Object message, Throwable t) {
319
    if(repository.isDisabled(Level.ERROR_INT))
324
    if(getLoggerRepository().isDisabled(Level.ERROR_INT))
320
      return;
325
      return;
321
    if(Level.ERROR.isGreaterOrEqual(this.getEffectiveLevel()))
326
    if(Level.ERROR.isGreaterOrEqual(this.getEffectiveLevel()))
322
      forcedLog(FQCN, Level.ERROR, message, t);
327
      forcedLog(FQCN, Level.ERROR, message, t);
Lines 359-365 Link Here
359
    @param message the message object to log */
364
    @param message the message object to log */
360
  public
365
  public
361
  void fatal(Object message) {
366
  void fatal(Object message) {
362
    if(repository.isDisabled(Level.FATAL_INT))
367
    if(getLoggerRepository().isDisabled(Level.FATAL_INT))
363
      return;
368
      return;
364
    if(Level.FATAL.isGreaterOrEqual(this.getEffectiveLevel()))
369
    if(Level.FATAL.isGreaterOrEqual(this.getEffectiveLevel()))
365
      forcedLog(FQCN, Level.FATAL, message, null);
370
      forcedLog(FQCN, Level.FATAL, message, null);
Lines 376-382 Link Here
376
   @param t the exception to log, including its stack trace.  */
381
   @param t the exception to log, including its stack trace.  */
377
  public
382
  public
378
  void fatal(Object message, Throwable t) {
383
  void fatal(Object message, Throwable t) {
379
    if(repository.isDisabled(Level.FATAL_INT))
384
    if(getLoggerRepository().isDisabled(Level.FATAL_INT))
380
      return;
385
      return;
381
    if(Level.FATAL.isGreaterOrEqual(this.getEffectiveLevel()))
386
    if(Level.FATAL.isGreaterOrEqual(this.getEffectiveLevel()))
382
      forcedLog(FQCN, Level.FATAL, message, t);
387
      forcedLog(FQCN, Level.FATAL, message, t);
Lines 499-505 Link Here
499
     @since 1.1 */
504
     @since 1.1 */
500
  public
505
  public
501
  LoggerRepository  getHierarchy() {
506
  LoggerRepository  getHierarchy() {
502
    return repository;
507
    return getLoggerRepository();
503
  }
508
  }
504
509
505
  /**
510
  /**
Lines 509-514 Link Here
509
     @since 1.2 */
514
     @since 1.2 */
510
  public
515
  public
511
  LoggerRepository  getLoggerRepository() {
516
  LoggerRepository  getLoggerRepository() {
517
    if (repository == null) {
518
	LogLog.error("Category.repository was null likely due to error in class reloading or someone setting it to null. Using NOPLoggerRepository.", nulledBy);
519
	repository = new NOPLoggerRepository();
520
    }
512
    return repository;
521
    return repository;
513
  }
522
  }
514
523
Lines 660-666 Link Here
660
    @param message the message object to log */
669
    @param message the message object to log */
661
  public
670
  public
662
  void info(Object message) {
671
  void info(Object message) {
663
    if(repository.isDisabled(Level.INFO_INT))
672
    if(getLoggerRepository().isDisabled(Level.INFO_INT))
664
      return;
673
      return;
665
    if(Level.INFO.isGreaterOrEqual(this.getEffectiveLevel()))
674
    if(Level.INFO.isGreaterOrEqual(this.getEffectiveLevel()))
666
      forcedLog(FQCN, Level.INFO, message, null);
675
      forcedLog(FQCN, Level.INFO, message, null);
Lines 677-683 Link Here
677
   @param t the exception to log, including its stack trace.  */
686
   @param t the exception to log, including its stack trace.  */
678
  public
687
  public
679
  void info(Object message, Throwable t) {
688
  void info(Object message, Throwable t) {
680
    if(repository.isDisabled(Level.INFO_INT))
689
    if(getLoggerRepository().isDisabled(Level.INFO_INT))
681
      return;
690
      return;
682
    if(Level.INFO.isGreaterOrEqual(this.getEffectiveLevel()))
691
    if(Level.INFO.isGreaterOrEqual(this.getEffectiveLevel()))
683
      forcedLog(FQCN, Level.INFO, message, t);
692
      forcedLog(FQCN, Level.INFO, message, t);
Lines 731-737 Link Here
731
    *   */
740
    *   */
732
  public
741
  public
733
  boolean isDebugEnabled() {
742
  boolean isDebugEnabled() {
734
    if(repository.isDisabled( Level.DEBUG_INT))
743
    if(getLoggerRepository().isDisabled( Level.DEBUG_INT))
735
      return false;
744
      return false;
736
    return Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel());
745
    return Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel());
737
  }
746
  }
Lines 746-752 Link Here
746
  */
755
  */
747
  public
756
  public
748
  boolean isEnabledFor(Priority level) {
757
  boolean isEnabledFor(Priority level) {
749
    if(repository.isDisabled(level.level))
758
    if(getLoggerRepository().isDisabled(level.level))
750
      return false;
759
      return false;
751
    return level.isGreaterOrEqual(this.getEffectiveLevel());
760
    return level.isGreaterOrEqual(this.getEffectiveLevel());
752
  }
761
  }
Lines 760-766 Link Here
760
  */
769
  */
761
  public
770
  public
762
  boolean isInfoEnabled() {
771
  boolean isInfoEnabled() {
763
    if(repository.isDisabled(Level.INFO_INT))
772
    if(getLoggerRepository().isDisabled(Level.INFO_INT))
764
      return false;
773
      return false;
765
    return Level.INFO.isGreaterOrEqual(this.getEffectiveLevel());
774
    return Level.INFO.isGreaterOrEqual(this.getEffectiveLevel());
766
  }
775
  }
Lines 776-782 Link Here
776
     @since 0.8.4 */
785
     @since 0.8.4 */
777
  public
786
  public
778
  void l7dlog(Priority priority, String key, Throwable t) {
787
  void l7dlog(Priority priority, String key, Throwable t) {
779
    if(repository.isDisabled(priority.level)) {
788
    if(getLoggerRepository().isDisabled(priority.level)) {
780
      return;
789
      return;
781
    }
790
    }
782
    if(priority.isGreaterOrEqual(this.getEffectiveLevel())) {
791
    if(priority.isGreaterOrEqual(this.getEffectiveLevel())) {
Lines 800-806 Link Here
800
  */
809
  */
801
  public
810
  public
802
  void l7dlog(Priority priority, String key,  Object[] params, Throwable t) {
811
  void l7dlog(Priority priority, String key,  Object[] params, Throwable t) {
803
    if(repository.isDisabled(priority.level)) {
812
    if(getLoggerRepository().isDisabled(priority.level)) {
804
      return;
813
      return;
805
    }
814
    }
806
    if(priority.isGreaterOrEqual(this.getEffectiveLevel())) {
815
    if(priority.isGreaterOrEqual(this.getEffectiveLevel())) {
Lines 819-825 Link Here
819
   */
828
   */
820
  public
829
  public
821
  void log(Priority priority, Object message, Throwable t) {
830
  void log(Priority priority, Object message, Throwable t) {
822
    if(repository.isDisabled(priority.level)) {
831
    if(getLoggerRepository().isDisabled(priority.level)) {
823
      return;
832
      return;
824
    }
833
    }
825
    if(priority.isGreaterOrEqual(this.getEffectiveLevel()))
834
    if(priority.isGreaterOrEqual(this.getEffectiveLevel()))
Lines 831-837 Link Here
831
 */
840
 */
832
  public
841
  public
833
  void log(Priority priority, Object message) {
842
  void log(Priority priority, Object message) {
834
    if(repository.isDisabled(priority.level)) {
843
    if(getLoggerRepository().isDisabled(priority.level)) {
835
      return;
844
      return;
836
    }
845
    }
837
    if(priority.isGreaterOrEqual(this.getEffectiveLevel()))
846
    if(priority.isGreaterOrEqual(this.getEffectiveLevel()))
Lines 849-855 Link Here
849
     @param t The throwable of the logging request, may be null.  */
858
     @param t The throwable of the logging request, may be null.  */
850
  public
859
  public
851
  void log(String callerFQCN, Priority level, Object message, Throwable t) {
860
  void log(String callerFQCN, Priority level, Object message, Throwable t) {
852
    if(repository.isDisabled(level.level)) {
861
    if(getLoggerRepository().isDisabled(level.level)) {
853
      return;
862
      return;
854
    }
863
    }
855
    if(level.isGreaterOrEqual(this.getEffectiveLevel())) {
864
    if(level.isGreaterOrEqual(this.getEffectiveLevel())) {
Lines 942-949 Link Here
942
  /**
951
  /**
943
     Only the Hiearchy class can set the hiearchy of a
952
     Only the Hiearchy class can set the hiearchy of a
944
     category. Default package access is MANDATORY here.  */
953
     category. Default package access is MANDATORY here.  */
954
  protected // TODO Must be protected for NOPLogger and CategoryTest.
945
  final
955
  final
946
  void setHierarchy(LoggerRepository repository) {
956
  void setHierarchy(LoggerRepository repository) {
957
    nulledBy = null;
958
    if (repository == null) {
959
	nulledBy = new Exception("Repository was nulled here.");
960
    }
947
    this.repository = repository;
961
    this.repository = repository;
948
  }
962
  }
949
963
Lines 1036-1042 Link Here
1036
    @param message the message object to log.  */
1050
    @param message the message object to log.  */
1037
  public
1051
  public
1038
  void warn(Object message) {
1052
  void warn(Object message) {
1039
    if(repository.isDisabled( Level.WARN_INT))
1053
    if(getLoggerRepository().isDisabled( Level.WARN_INT))
1040
      return;
1054
      return;
1041
1055
1042
    if(Level.WARN.isGreaterOrEqual(this.getEffectiveLevel()))
1056
    if(Level.WARN.isGreaterOrEqual(this.getEffectiveLevel()))
Lines 1054-1060 Link Here
1054
   @param t the exception to log, including its stack trace.  */
1068
   @param t the exception to log, including its stack trace.  */
1055
  public
1069
  public
1056
  void warn(Object message, Throwable t) {
1070
  void warn(Object message, Throwable t) {
1057
    if(repository.isDisabled(Level.WARN_INT))
1071
    if(getLoggerRepository().isDisabled(Level.WARN_INT))
1058
      return;
1072
      return;
1059
    if(Level.WARN.isGreaterOrEqual(this.getEffectiveLevel()))
1073
    if(Level.WARN.isGreaterOrEqual(this.getEffectiveLevel()))
1060
      forcedLog(FQCN, Level.WARN, message, t);
1074
      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