Skip to content

Commit

Permalink
Add stack trace to logs (#375)
Browse files Browse the repository at this point in the history
* Add stack trace to logs
* Add default config for live logging

Signed-off-by: Sylvain Leclerc <[email protected]>
  • Loading branch information
sylvlecl authored Apr 22, 2022
1 parent 998b47f commit cda6cd1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion java/src/main/java/com/powsybl/python/CustomAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
package com.powsybl.python;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.IThrowableProxy;
import ch.qos.logback.classic.spi.ThrowableProxyUtil;
import ch.qos.logback.core.AppenderBase;
import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.encoder.Encoder;

/**
Expand All @@ -22,8 +25,14 @@ public class CustomAppender extends AppenderBase<ILoggingEvent> {
@Override
protected void append(final ILoggingEvent e) {
PyPowsyblApiLib.LoggerCallback logMessage = (PyPowsyblApiLib.LoggerCallback) PyPowsyblApiLib.loggerCallback;

String message = e.getFormattedMessage();
IThrowableProxy throwable = e.getThrowableProxy();
if (throwable != null) {
message = message + CoreConstants.LINE_SEPARATOR + ThrowableProxyUtil.asString(throwable);
}
logMessage.invoke(PyLoggingUtil.logbackLevelToPythonLevel(e.getLevel()), e.getTimeStamp(),
CTypeUtil.toCharPtr(e.getLoggerName()), CTypeUtil.toCharPtr(e.getFormattedMessage()));
CTypeUtil.toCharPtr(e.getLoggerName()), CTypeUtil.toCharPtr(message));
}

public Encoder<ILoggingEvent> getEncoder() {
Expand Down
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
#Change those options to get logs
log_cli=false
log_level=ERROR

0 comments on commit cda6cd1

Please sign in to comment.