Skip to content

Commit

Permalink
[FIXED JENKINS-17983] Empty LogRecorder.Target.name was not working.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed May 16, 2013
1 parent 5ecbbef commit 84d1abd
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -58,6 +58,9 @@
<li class=bug>
NPE from <code>Run.getDynamic</code>.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-17935">issue 17935</a>)
<li class=bug>
Should be able to collect all log records at a given level using a blank logger name.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-17983">issue 17983</a>)
<li class=bug>
Reworked Upload Plugin gesture to work more like installation from an update center, and in particular to support dynamic load.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-16652">issue 16652</a>)
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/hudson/logging/LogRecorder.java
Expand Up @@ -110,11 +110,13 @@ public Level getLevel() {
public boolean includes(LogRecord r) {
if(r.getLevel().intValue() < level)
return false; // below the threshold
if (name.length() == 0) {
return true; // like root logger, includes everything
}
String logName = r.getLoggerName();
if(logName==null || !logName.startsWith(name))
return false; // not within this logger

String rest = r.getLoggerName().substring(name.length());
String rest = logName.substring(name.length());
return rest.startsWith(".") || rest.length()==0;
}

Expand Down
51 changes: 51 additions & 0 deletions core/src/test/java/hudson/logging/LogRecorderTest.java
@@ -0,0 +1,51 @@
/*
* The MIT License
*
* Copyright 2013 Jesse Glick.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.logging;

import java.util.logging.Level;
import java.util.logging.LogRecord;
import org.junit.Test;
import static org.junit.Assert.*;
import org.jvnet.hudson.test.Bug;

public class LogRecorderTest {

@Bug(17983)
@Test public void targetIncludes() {
assertTrue(includes("hudson", "hudson"));
assertFalse(includes("hudson", "hudsone"));
assertFalse(includes("hudson", "hudso"));
assertTrue(includes("hudson", "hudson.model.Hudson"));
assertFalse(includes("hudson", "jenkins.model.Jenkins"));
assertTrue(includes("", "hudson.model.Hudson"));
}

private static boolean includes(String target, String logger) {
LogRecord r = new LogRecord(Level.INFO, "whatever");
r.setLoggerName(logger);
return new LogRecorder.Target(target, Level.INFO).includes(r);
}

}

0 comments on commit 84d1abd

Please sign in to comment.