Search in sources :

Example 1 with StackTraceElementProxy

use of ch.qos.logback.classic.spi.StackTraceElementProxy in project cdap by caskdata.

the class TwillLogThrowableAdapter method getStackTraceElementProxyArray.

@Override
public StackTraceElementProxy[] getStackTraceElementProxyArray() {
    StackTraceElementProxy[] result = new StackTraceElementProxy[throwable.getStackTraces().length];
    for (int i = 0; i < throwable.getStackTraces().length; i++) {
        StackTraceElement original = throwable.getStackTraces()[i];
        result[i] = new StackTraceElementProxy(original);
    }
    return result;
}
Also used : StackTraceElementProxy(ch.qos.logback.classic.spi.StackTraceElementProxy)

Example 2 with StackTraceElementProxy

use of ch.qos.logback.classic.spi.StackTraceElementProxy in project cdap by caskdata.

the class StackTraceElementProxyArraySerializer method encode.

static GenericArray<GenericRecord> encode(Schema schema, StackTraceElementProxy[] stackTraceElementProxies) {
    if (stackTraceElementProxies != null) {
        Schema steArraySchema = schema.getTypes().get(1);
        GenericArray<GenericRecord> steArray = new GenericData.Array<>(stackTraceElementProxies.length, steArraySchema);
        for (StackTraceElementProxy ste : stackTraceElementProxies) {
            steArray.add(StackTraceElementProxySerializer.encode(steArraySchema.getElementType(), ste));
        }
        return steArray;
    }
    return null;
}
Also used : GenericArray(org.apache.avro.generic.GenericArray) Schema(org.apache.avro.Schema) GenericRecord(org.apache.avro.generic.GenericRecord) StackTraceElementProxy(ch.qos.logback.classic.spi.StackTraceElementProxy)

Example 3 with StackTraceElementProxy

use of ch.qos.logback.classic.spi.StackTraceElementProxy in project cdap by caskdata.

the class ThrowableProxySerializer method decode.

static IThrowableProxy decode(GenericRecord datum) {
    if (datum != null) {
        String className = LoggingUtil.stringOrNull(datum.get("className"));
        String message = LoggingUtil.stringOrNull(datum.get("message"));
        int commonFramesCount = (Integer) datum.get("commonFramesCount");
        @SuppressWarnings("unchecked") StackTraceElementProxy[] steArray = StackTraceElementProxyArraySerializer.decode((GenericArray<GenericRecord>) datum.get("stackTraceElementProxyArray"));
        IThrowableProxy cause = ThrowableProxySerializer.decode((GenericRecord) datum.get("cause"));
        @SuppressWarnings("unchecked") IThrowableProxy[] suppressed = ThrowableProxyArraySerializer.decode((GenericArray<GenericRecord>) datum.get("suppressed"));
        return new ThrowableProxyImpl(cause, className, commonFramesCount, message, steArray, suppressed);
    }
    return null;
}
Also used : IThrowableProxy(ch.qos.logback.classic.spi.IThrowableProxy) GenericRecord(org.apache.avro.generic.GenericRecord) StackTraceElementProxy(ch.qos.logback.classic.spi.StackTraceElementProxy)

Example 4 with StackTraceElementProxy

use of ch.qos.logback.classic.spi.StackTraceElementProxy in project platformlayer by platformlayer.

the class LogbackHook method append.

@Override
protected void append(E e) {
    OpsContext opsContext = OpsContext.get();
    if (opsContext != null) {
        ILoggingEvent event = (ILoggingEvent) e;
        // Note that we can get the unformatted message in getMessage(), presumably along with the parameters...
        String message = event.getFormattedMessage();
        Level level = event.getLevel();
        int levelInt = level.toInt();
        List<String[]> exceptionStacks = null;
        IThrowableProxy throwableInformation = event.getThrowableProxy();
        while (throwableInformation != null) {
            String[] exceptionStackTrace = null;
            StackTraceElementProxy[] trace = throwableInformation.getStackTraceElementProxyArray();
            String exceptionMessage = throwableInformation.getMessage();
            String exceptionClass = throwableInformation.getClassName();
            if (trace != null) {
                exceptionStackTrace = new String[1 + trace.length];
                exceptionStackTrace[0] = exceptionClass + ": " + exceptionMessage;
                for (int i = 0; i < trace.length; i++) {
                    exceptionStackTrace[1 + i] = trace[i].getSTEAsString();
                }
            } else {
                exceptionStackTrace = new String[1];
                exceptionStackTrace[0] = exceptionClass + ": " + exceptionMessage;
            }
            if (exceptionStacks == null) {
                exceptionStacks = Lists.newArrayList();
            }
            exceptionStacks.add(exceptionStackTrace);
            throwableInformation = throwableInformation.getCause();
        }
        if (message != null || exceptionStacks != null) {
            opsContext.getJobLogger().logMessage(message, exceptionStacks, levelInt);
            if (levelInt >= Level.ERROR_INT) {
                // String key = "warn-" + OpsSystem.buildSimpleTimeString() + "-" + (System.nanoTime() % 1000);
                if (opsContext != null) {
                    // && opsContext.getOperation() != null) {
                    if (exceptionStacks != null && !exceptionStacks.isEmpty()) {
                        String[] exceptionStack = exceptionStacks.get(0);
                        if (exceptionStack != null && exceptionStack.length > 0) {
                            message += "; " + exceptionStack[0];
                        }
                    }
                    opsContext.addWarning(null, message);
                }
            }
        }
    }
}
Also used : IThrowableProxy(ch.qos.logback.classic.spi.IThrowableProxy) Level(ch.qos.logback.classic.Level) OpsContext(org.platformlayer.ops.OpsContext) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) StackTraceElementProxy(ch.qos.logback.classic.spi.StackTraceElementProxy)

Example 5 with StackTraceElementProxy

use of ch.qos.logback.classic.spi.StackTraceElementProxy in project cdap by caskdata.

the class StackTraceElementProxyArraySerializer method decode.

static StackTraceElementProxy[] decode(GenericArray<GenericRecord> datum) {
    if (datum != null) {
        StackTraceElementProxy[] stackTraceElementProxies = new StackTraceElementProxy[datum.size()];
        int i = 0;
        for (GenericRecord aDatum : datum) {
            stackTraceElementProxies[i++] = StackTraceElementProxySerializer.decode(aDatum);
        }
        return stackTraceElementProxies;
    }
    return null;
}
Also used : GenericRecord(org.apache.avro.generic.GenericRecord) StackTraceElementProxy(ch.qos.logback.classic.spi.StackTraceElementProxy)

Aggregations

StackTraceElementProxy (ch.qos.logback.classic.spi.StackTraceElementProxy)6 GenericRecord (org.apache.avro.generic.GenericRecord)3 IThrowableProxy (ch.qos.logback.classic.spi.IThrowableProxy)2 Level (ch.qos.logback.classic.Level)1 ClassPackagingData (ch.qos.logback.classic.spi.ClassPackagingData)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 Schema (org.apache.avro.Schema)1 GenericArray (org.apache.avro.generic.GenericArray)1 OpsContext (org.platformlayer.ops.OpsContext)1