-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mechanism for sending messages to execution log from Java #112
Closed
Closed
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1c30432
Prepare for release of framework-core 3.1.0
bertfrees 8e088a6
Mechanism for sending messages to execution log from Java
bertfrees 3914b67
fixup
bertfrees 4bc4cf1
slf4jXProcMessageListener: use default logger if the current step is …
bertfrees 7786a99
XProcMessageListenerAggregator: some warning were printed as errors
bertfrees bdb6b24
include timestamps in job messages (fixes #109)
josteinaj 03138e8
added timeStamp to jobElement.rnc
josteinaj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
logging-appender/src/main/java/org/daisy/pipeline/logging/EventBusAppender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package org.daisy.pipeline.logging; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import ch.qos.logback.classic.Level; | ||
import ch.qos.logback.classic.sift.MDCBasedDiscriminator; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.AppenderBase; | ||
|
||
import org.daisy.common.messaging.Message; | ||
import org.daisy.common.messaging.MessageBuliderFactory; | ||
import org.daisy.pipeline.event.EventBusProvider; | ||
|
||
import org.osgi.framework.BundleContext; | ||
import org.osgi.framework.FrameworkUtil; | ||
import org.osgi.framework.InvalidSyntaxException; | ||
|
||
/** | ||
* Configure like this: | ||
* | ||
* <appender name="EVENTBUS" class="org.daisy.pipeline.logging.EventBusAppender"> | ||
* <filter class="org.daisy.pipeline.logging.ThresholdFilter"> | ||
* <rootLevel>INFO</rootLevel> | ||
* <loggerLevels> | ||
* cz.vutbr.web=WARN | ||
* org.daisy.common.xproc.calabash.steps.Message=WARN | ||
* com.xmlcalabash.runtime.XAtomicStep=WARN | ||
* </loggerLevels> | ||
* </filter> | ||
* </appender> | ||
*/ | ||
public class EventBusAppender extends AppenderBase<ILoggingEvent> { | ||
|
||
private EventBusProvider eventBusProvider; | ||
private BundleContext bundleContext; | ||
private MessageBuliderFactory messageBuilderFactory; | ||
private List<ILoggingEvent> eventBuffer; | ||
private MDCBasedDiscriminator discriminator; | ||
|
||
@Override | ||
public void start() { | ||
bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); | ||
messageBuilderFactory = new MessageBuliderFactory(); | ||
eventBuffer = new ArrayList<ILoggingEvent>(); | ||
discriminator = new MDCBasedDiscriminator(); | ||
discriminator.setKey("jobid"); | ||
discriminator.setDefaultValue("default"); | ||
super.start(); | ||
} | ||
|
||
protected void append(ILoggingEvent event) { | ||
if (!isStarted()) | ||
return; | ||
String jobId = discriminator.getDiscriminatingValue(event); | ||
if (!"default".equals(jobId)) { | ||
if (eventBusProvider == null) { | ||
try { | ||
eventBusProvider = bundleContext.getService( | ||
bundleContext.getServiceReferences(EventBusProvider.class, null).iterator().next()); | ||
for (ILoggingEvent e : eventBuffer) | ||
append(eventBusProvider, discriminator.getDiscriminatingValue(e), e); | ||
eventBuffer.clear(); } | ||
catch (Exception e) { | ||
eventBuffer.add(event); | ||
return; }} | ||
append(eventBusProvider, jobId, event); } | ||
} | ||
|
||
private void append(EventBusProvider eventBus, String jobId, ILoggingEvent event) { | ||
Level level = event.getLevel(); | ||
Message m = messageBuilderFactory.newMessageBuilder() | ||
.withTimeStamp(new Date()) | ||
.withJobId(jobId) | ||
.withLevel(messageLevelFromLogbackLevel(level)) | ||
.withText(event.getFormattedMessage()) | ||
.build(); | ||
eventBus.get().post(m); | ||
} | ||
|
||
private static Message.Level messageLevelFromLogbackLevel(Level level) { | ||
switch(level.toInt()) { | ||
case Level.TRACE_INT: | ||
return Message.Level.TRACE; | ||
case Level.DEBUG_INT: | ||
return Message.Level.DEBUG; | ||
case Level.INFO_INT: | ||
return Message.Level.INFO; | ||
case Level.WARN_INT: | ||
return Message.Level.WARNING; | ||
case Level.ERROR_INT: | ||
return Message.Level.ERROR; | ||
case Level.ALL_INT: | ||
case Level.OFF_INT: | ||
default: | ||
return null; } | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way of getting an osgi agnostic appender? If the effort is to big just leave it like that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied from Slack: