Skip to content

Instantly share code, notes, and snippets.

@danveloper
danveloper / gist:5208601
Last active December 15, 2015 05:20
UI Atmosphere Subscription -- Real Time Logging
<!-- ... resources & jquery snipped for brevity ... -->
<atmosphere:resources/>
<r:script>
$(document).ready(function() {
var url = '${createLink(uri:ApplicationHolder.application.config.grails.atmosphere.mappingUri)}';
$.atmosphere.subscribe(url, Logging.router, $.atmosphere.request = {transport:'websocket', fallbackTransport:'streaming'});
...
});
</r:script>
@danveloper
danveloper / LoggingService.groovy
Created March 20, 2013 21:23
Registering new atmosphere mapping -- Real Time Logging Project
// Registering an application's logging instance either means creating a new mapping for it.
// If a mapping already exists, update its "latest update time" property.
private def registerApplicationInstance(String ipAddress, String hostname, String appName) {
if (!applications[appName]) {
applications[appName] = []
}
def existing = findApplicationObject(appName, ipAddress, hostname)
if (!existing) {
// Register the new application and create a unique mapping for it.
applications[appName] << [ipAddress: ipAddress, hostname: hostname, lastUpdateTime: new LocalDateTime()]
@danveloper
danveloper / Config.groovy
Created March 20, 2013 21:22
Atmosphere "base mapping uri" config -- Real Time Logging Project
grails.atmosphere.mappingUri = '/atmosphere/logging'
@danveloper
danveloper / LogMessageCommand.groovy
Created March 20, 2013 21:21
Logging Service Activator -- Real Time Logging Project
class LogMessageCommand {
String level
String threadName
String application
String message
String hostname
String ipAddress
LocalDateTime messageTime = new LocalDateTime() // this is joda-time
}
@danveloper
danveloper / resources.groovy
Created March 20, 2013 21:20
Spring Integration Resources Configuration -- Real Time Logging
beans = {
...
/* Attach the message adapter */
logServiceActivator(LoggingServiceActivator)
/* Create the log channel, for internal transport */
integration.channel(id: "logChannel")
/* Attach a chain to the log channel, this will delegate the message to the LoggingServiceActivator */
integration.chain("input-channel": "logChannel") {
@danveloper
danveloper / BuildConfig.groovy
Created March 20, 2013 21:19
Spring Integration Grails Dependencies -- Real Time Logging Project
dependencies {
...
compile 'org.springframework.integration:spring-integration-core:2.2.0.RELEASE'
compile 'org.springframework.integration:spring-integration-jms:2.2.0.RELEASE'
compile 'org.springframework.integration:spring-integration-stream:2.2.0.RELEASE'
...
}
@danveloper
danveloper / resources.groovy
Created March 20, 2013 21:19
ActiveMQ integration with Spring context -- Real Time Logging Project
beans = {
...
xmlns amq:"http://activemq.apache.org/schema/core"
/* Establish the broker */
amq.broker(useJmx: false, persistent: false) {
amq.transportConnectors() {
amq.transportConnector(uri: "tcp://localhost:61616")
}
}
@danveloper
danveloper / BuildConfig.groovy
Created March 20, 2013 21:18
ActiveMQ Grails Dependencies -- Real Time Logging Project
dependencies {
...
compile 'org.apache.activemq:activemq-core:5.7.0'
// (this is necessary for namespace support)
compile 'org.apache.xbean:xbean-spring:3.12'
...
}
@danveloper
danveloper / build.gradle
Last active December 15, 2015 05:19
Enhanced JMS Appender Maven Artifact -- Real Time Logging Project
// If you prefer Gradle
compile 'com.danveloper.log4j:enhanced-log4j-appender:0.1-SNAPSHOT'
@danveloper
danveloper / log4j.properties
Created March 20, 2013 21:16
log4j.properties -- Real Time Logging Project
log4j.rootLogger=INFO, stdout, jms
## Be sure that ActiveMQ messages are not logged to 'jms' appender
log4j.logger.org.apache.activemq=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %-5p %c - %m%n
## Configure 'jms' appender. You'll also need jndi.properties file in order to make it work