Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add AMQP logging to the application.

  • Loading branch information...
commit 477f7c93ae821c31f7331eabaea5dd2f91616268 1 parent 7f11162
@pledbrook pledbrook authored
View
1  grailstwitter/grails-app/conf/BuildConfig.groovy
@@ -16,6 +16,7 @@ grails.project.dependency.resolution = {
compile ":spring-security-core:1.2.4"
runtime ":blueprint:1.0.2",
":cloud-foundry:1.2.1",
+ ":cloud-support:1.0.9",
":executor:0.3",
":hibernate:2.0.1",
":mongodb:1.0.0.RC4",
View
109 grailstwitter/grails-app/conf/Config.groovy
@@ -1,3 +1,6 @@
+import grails.plugin.cloudfoundry.AppCloudEnvironment
+import org.springframework.amqp.rabbit.log4j.AmqpAppender
+
// locations to search for config files that get merged into the main config
// config files can either be Java properties files or ConfigSlurper scripts
@@ -48,47 +51,6 @@ grails.logging.jul.usebridge = true
// packages to include in Spring bean scanning
grails.spring.bean.packages = []
-// set per-environment serverURL stem for creating absolute links
-environments {
- production {
- }
- development {
- }
- test {
- }
-
-}
-
-// log4j configuration
-log4j = {
- // Example of changing the log pattern for the default console
- // appender:
- //
- //appenders {
- // console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
- //}
-
- error 'org.codehaus.groovy.grails.web.servlet', // controllers
- 'org.codehaus.groovy.grails.web.pages', // GSP
- 'org.codehaus.groovy.grails.web.sitemesh', // layouts
- 'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
- 'org.codehaus.groovy.grails.web.mapping', // URL mapping
- 'org.codehaus.groovy.grails.commons', // core / classloading
- 'org.codehaus.groovy.grails.plugins', // plugins
- 'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
- 'org.springframework',
- 'org.hibernate',
- 'net.sf.ehcache.hibernate'
-
- warn 'org.mortbay.log'
-
- info 'org.springframework.amqp.rabbit', "grails.app"
- debug 'grails.app.controller.org.grails.twitter',
- 'grails.app.service.org.grails.twitter',
- 'grails.plugin.searchable'
-
-}
-
searchable {
compassConnection = null
compassSettings = [
@@ -116,6 +78,71 @@ rabbitmq {
}
}
+// log4j configuration
+log4j = {
+ // AMQP appender needs RabbitMQ connection settings. Pull from
+ // VCAP_SERVICES.
+ def rabbitConfig
+ def cloudEnv = new AppCloudEnvironment()
+ if (cloudEnv.available) {
+ def serviceInfo = new AppCloudEnvironment().getServiceByVendor('rabbitmq')
+ if (serviceInfo) {
+ }
+
+ rabbitConfig = [
+ host: serviceInfo.host,
+ username: serviceInfo.userName,
+ password: serviceInfo.password,
+ virtualHost: serviceInfo.virtualHost,
+ port: serviceInfo.port]
+
+ }
+ else {
+ def connFactory = owner.rabbitmq.connectionfactory
+ rabbitConfig = [
+ host: connFactory.hostname,
+ username: connFactory.username,
+ password: connFactory.password,
+ virtualHost: connFactory.virtualHost]
+ }
+
+ appenders {
+ rabbitConfig << [
+ name: "rabbit",
+ exchangeName: "amq.topic",
+ exchangeType: "topic",
+ routingKeyPattern: "logs.grailstwitter",
+ contentEncoding: "UTF-8",
+ applicationId: "grailstwitter" ]
+
+ appender new AmqpAppender(rabbitConfig)
+ console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
+ }
+
+ root {
+ info 'stdout', 'rabbit'
+ }
+
+ error 'org.codehaus.groovy.grails.web.servlet', // controllers
+ 'org.codehaus.groovy.grails.web.pages', // GSP
+ 'org.codehaus.groovy.grails.web.sitemesh', // layouts
+ 'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
+ 'org.codehaus.groovy.grails.web.mapping', // URL mapping
+ 'org.codehaus.groovy.grails.commons', // core / classloading
+ 'org.codehaus.groovy.grails.plugins', // plugins
+ 'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
+ 'org.springframework',
+ 'org.hibernate',
+ 'net.sf.ehcache.hibernate'
+
+ warn 'org.mortbay.log'
+
+ info 'grails.app'
+ debug 'grails.app.controllers.org.grails.twitter',
+ 'grails.app.services.org.grails.twitter'
+
+}
+
// Added by the Spring Security Core plugin:
grails.plugins.springsecurity.userLookup.userDomainClassName = 'org.grails.twitter.auth.Person'
grails.plugins.springsecurity.userLookup.authorityJoinClassName = 'org.grails.twitter.auth.PersonAuthority'
View
1  grailstwitter/grails-app/services/org/grails/twitter/StatusService.groovy
@@ -9,6 +9,7 @@ class StatusService {
void updateStatus(long userId, String message) {
def status = new Status(message: message, authorId: userId).save(flush: true, failOnError: true)
rabbitSend 'search.sync', '', "${status.id}:${status.class.name}"
+ log.info "Event: reindex status ${status.id}"
runAsync {
tagService.extractTagsFromMessage(status)
Please sign in to comment.
Something went wrong with that request. Please try again.