Skip to content

Commit

Permalink
Merge tag 'tags/v_1.1.0'
Browse files Browse the repository at this point in the history
This merges in the most recent changes from logback that were tagged with "v_1.1.0".
  • Loading branch information
tony19 committed Feb 2, 2014
2 parents ab7c8e4 + fd8751f commit 586e77a
Show file tree
Hide file tree
Showing 58 changed files with 1,121 additions and 192 deletions.
2 changes: 1 addition & 1 deletion logback-classic/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.tony19</groupId>
<artifactId>logback-android-parent</artifactId>
<version>1.0.13-1-SNAPSHOT</version>
<version>1.1.0-1-SNAPSHOT</version>
</parent>

<artifactId>logback-android-classic</artifactId>
Expand Down
@@ -0,0 +1,30 @@
/**
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2013, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
package ch.qos.logback.classic.gaffer

import ch.qos.logback.core.Appender

class AsyncAppenderDelegate extends AppenderDelegate {

Map<String, Appender<?>> appendersByName = [:]

AsyncAppenderDelegate(Appender appender, List<Appender<?>> appenders) {
super(appender)
appendersByName = appenders.collectEntries { [(it.name) : it]}
}

void appenderRef(String name){
component.addAppender(appendersByName[name])
}
}
Expand Up @@ -159,6 +159,7 @@ public synchronized void setLevel(Level newLevel) {
level = newLevel;
if (newLevel == null) {
effectiveLevelInt = parent.effectiveLevelInt;
newLevel = parent.getEffectiveLevel();
} else {
effectiveLevelInt = newLevel.levelInt;
}
Expand Down
Expand Up @@ -16,27 +16,7 @@
import java.util.HashMap;
import java.util.Map;

import ch.qos.logback.classic.pattern.CallerDataConverter;
import ch.qos.logback.classic.pattern.ClassOfCallerConverter;
import ch.qos.logback.classic.pattern.ContextNameConverter;
import ch.qos.logback.classic.pattern.PropertyConverter;
import ch.qos.logback.classic.pattern.DateConverter;
import ch.qos.logback.classic.pattern.EnsureExceptionHandling;
import ch.qos.logback.classic.pattern.ExtendedThrowableProxyConverter;
import ch.qos.logback.classic.pattern.FileOfCallerConverter;
import ch.qos.logback.classic.pattern.LevelConverter;
import ch.qos.logback.classic.pattern.LineOfCallerConverter;
import ch.qos.logback.classic.pattern.LineSeparatorConverter;
import ch.qos.logback.classic.pattern.LoggerConverter;
import ch.qos.logback.classic.pattern.MDCConverter;
import ch.qos.logback.classic.pattern.MarkerConverter;
import ch.qos.logback.classic.pattern.MessageConverter;
import ch.qos.logback.classic.pattern.MethodOfCallerConverter;
import ch.qos.logback.classic.pattern.NopThrowableInformationConverter;
import ch.qos.logback.classic.pattern.RelativeTimeConverter;
import ch.qos.logback.classic.pattern.RootCauseFirstThrowableProxyConverter;
import ch.qos.logback.classic.pattern.ThreadConverter;
import ch.qos.logback.classic.pattern.ThrowableProxyConverter;
import ch.qos.logback.classic.pattern.*;
import ch.qos.logback.classic.pattern.color.HighlightingCompositeConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.CoreConstants;
Expand Down Expand Up @@ -150,6 +130,7 @@ public class PatternLayout extends PatternLayoutBase<ILoggingEvent> {
defaultConverterMap.put("boldWhite", BoldWhiteCompositeConverter.class.getName());
defaultConverterMap.put("highlight", HighlightingCompositeConverter.class.getName());

defaultConverterMap.put("lsn", LocalSequenceNumberConverter.class.getName());


}
Expand Down
Expand Up @@ -50,7 +50,7 @@ void render(StringBuilder sbuf, IThrowableProxy tp) {

if (commonFrames > 0) {
sbuf.append(TRACE_PREFIX);
sbuf.append("\t... " + commonFrames).append(" common frames omitted")
sbuf.append("\t... ").append(commonFrames).append(" common frames omitted")
.append(CoreConstants.LINE_SEPARATOR);
}
}
Expand Down
Expand Up @@ -56,6 +56,18 @@ public void begin(InterpretationContext ic, String name, Attributes attributes)
ic.pushObject(getContext());
}

String getSystemProperty(String name) {
/*
* LOGBACK-743: accessing a system property in the presence of a
* SecurityManager (e.g. applet sandbox) can result in a SecurityException.
*/
try {
return System.getProperty(name);
} catch (SecurityException ex) {
return null;
}
}

void processScanAttrib(InterpretationContext ic, Attributes attributes) {
String scanAttrib = ic.subst(attributes.getValue(SCAN_ATTR));
if (!OptionHelper.isEmpty(scanAttrib)
Expand Down
Expand Up @@ -36,6 +36,9 @@ static public final boolean isRoot(java.util.logging.Logger julLogger) {
}

static public java.util.logging.Level asJULLevel(Level lbLevel) {
if (lbLevel == null)
throw new IllegalArgumentException("Unexpected level [null]");

switch (lbLevel.levelInt) {
case Level.ALL_INT:
return java.util.logging.Level.ALL;
Expand Down
Expand Up @@ -99,7 +99,14 @@ public SimpleSocketServer(LoggerContext lc, int port) {


public void run() {

final String oldThreadName = Thread.currentThread().getName();

try {

final String newThreadName = getServerThreadName();
Thread.currentThread().setName(newThreadName);

logger.info("Listening on port " + port);
serverSocket = getServerSocketFactory().createServerSocket(port);
while (!closed) {
Expand All @@ -112,7 +119,8 @@ public void run() {
synchronized (socketNodeList) {
socketNodeList.add(newSocketNode);
}
new Thread(newSocketNode).start();
final String clientThreadName = getClientThreadName(socket);
new Thread(newSocketNode, clientThreadName).start();
}
} catch (Exception e) {
if(closed) {
Expand All @@ -121,6 +129,24 @@ public void run() {
logger.error("Unexpected failure in run method", e);
}
}

finally {
Thread.currentThread().setName(oldThreadName);
}
}

/**
* Returns the name given to the server thread.
*/
protected String getServerThreadName() {
return String.format("Logback %s (port %d)", getClass().getSimpleName(), port);
}

/**
* Returns a name to identify each client thread.
*/
protected String getClientThreadName(Socket socket) {
return String.format("Logback SocketNode (client: %s)", socket.getRemoteSocketAddress());
}

/**
Expand Down
Expand Up @@ -57,13 +57,6 @@ public SocketNode(SimpleSocketServer socketServer, Socket socket, LoggerContext
remoteSocketAddress = socket.getRemoteSocketAddress();
this.context = context;
logger = context.getLogger(SocketNode.class);

try {
ois = new ObjectInputStream(new BufferedInputStream(socket
.getInputStream()));
} catch (Exception e) {
logger.error("Could not open ObjectInputStream to " + socket, e);
}
}

// public
Expand All @@ -73,6 +66,15 @@ public SocketNode(SimpleSocketServer socketServer, Socket socket, LoggerContext
// }

public void run() {

try {
ois = new ObjectInputStream(new BufferedInputStream(socket
.getInputStream()));
} catch (Exception e) {
logger.error("Could not open ObjectInputStream to " + socket, e);
closed = true;
}

ILoggingEvent event;
Logger remoteLogger;

Expand Down
Expand Up @@ -21,9 +21,7 @@ public class ExtendedThrowableProxyConverter extends ThrowableProxyConverter {

@Override
protected void extraData(StringBuilder builder, StackTraceElementProxy step) {
if (step != null) {
ThrowableProxyUtil.subjoinPackagingData(builder, step);
}
ThrowableProxyUtil.subjoinPackagingData(builder, step);
}

protected void prepareLoggingEvent(ILoggingEvent event) {
Expand Down
@@ -0,0 +1,36 @@
/**
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2013, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
package ch.qos.logback.classic.pattern;

import ch.qos.logback.classic.spi.ILoggingEvent;
import java.util.concurrent.atomic.AtomicLong;

/**
* A converters based on a a locally incremented sequence number. The sequence number is
* initialized to the number of milliseconds elapsed since 1970-01-01 until this instance
* is initialized.
*
* <p>
* <b>EXPERIMENTAL</b> This class is experimental and may be removed in the future.
*
*/
public class LocalSequenceNumberConverter extends ClassicConverter {

AtomicLong sequenceNumber = new AtomicLong(System.currentTimeMillis());

@Override
public String convert(ILoggingEvent event) {
return Long.toString(sequenceNumber.getAndIncrement());
}
}
Expand Up @@ -14,7 +14,6 @@
package ch.qos.logback.classic.pattern;

import ch.qos.logback.classic.spi.IThrowableProxy;
import ch.qos.logback.classic.spi.StackTraceElementProxy;
import ch.qos.logback.classic.spi.ThrowableProxyUtil;
import ch.qos.logback.core.CoreConstants;

Expand All @@ -26,40 +25,28 @@ public class RootCauseFirstThrowableProxyConverter extends ExtendedThrowableProx

@Override
protected String throwableProxyToString(IThrowableProxy tp) {
StringBuilder buf = new StringBuilder(2048);
subjoinRootCauseFirst(tp, buf);
StringBuilder buf = new StringBuilder(BUILDER_CAPACITY);
recursiveAppendRootCauseFirst(buf, null, ThrowableProxyUtil.REGULAR_EXCEPTION_INDENT, tp);
return buf.toString();
}

private void subjoinRootCauseFirst(IThrowableProxy tp, StringBuilder buf) {
if (tp.getCause() != null)
subjoinRootCauseFirst(tp.getCause(), buf);
subjoinRootCause(tp, buf);
}

private void subjoinRootCause(IThrowableProxy tp, StringBuilder buf) {
ThrowableProxyUtil.subjoinFirstLineRootCauseFirst(buf, tp);
buf.append(CoreConstants.LINE_SEPARATOR);
StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray();
int commonFrames = tp.getCommonFrames();

boolean unrestrictedPrinting = lengthOption > stepArray.length;


int maxIndex = (unrestrictedPrinting) ? stepArray.length : lengthOption;
if (commonFrames > 0 && unrestrictedPrinting) {
maxIndex -= commonFrames;
protected void recursiveAppendRootCauseFirst(StringBuilder sb, String prefix, int indent, IThrowableProxy tp) {
if (tp.getCause() != null) {
recursiveAppendRootCauseFirst(sb, prefix, indent, tp.getCause());
prefix = null; // to avoid adding it more than once
}

for (int i = 0; i < maxIndex; i++) {
String string = stepArray[i].toString();
buf.append(CoreConstants.TAB);
buf.append(string);
extraData(buf, stepArray[i]); // allow other data to be added
buf.append(CoreConstants.LINE_SEPARATOR);
ThrowableProxyUtil.indent(sb, indent - 1);
if (prefix != null) {
sb.append(prefix);
}
ThrowableProxyUtil.subjoinFirstLineRootCauseFirst(sb, tp);
sb.append(CoreConstants.LINE_SEPARATOR);
subjoinSTEPArray(sb, indent, tp);
IThrowableProxy[] suppressed = tp.getSuppressed();
if(suppressed != null) {
for(IThrowableProxy current : suppressed) {
recursiveAppendRootCauseFirst(sb, CoreConstants.SUPPRESSED, indent + ThrowableProxyUtil.SUPPRESSED_EXCEPTION_INDENT, current);
}
}

}


}

0 comments on commit 586e77a

Please sign in to comment.