OohLaLog Plugin

  • Tags: logging, monitoring, log4j
  • Latest: 0.4.4
  • Last Updated: 19 August 2014
  • Grails version: 2.0 > *
1 vote
Dependency:
compile ":ooh-la-log:0.4.4"
Custom repositories:
mavenRepo "http://nexus.bertramlabs.com/content/repositories/publicReleases/"

 Documentation  Source  Issues

Summary

Grails Oohlalog Log4j Appender for Passing logs to the oohlalog API.

Installation

grails install-plugin ooh-la-log

Description

The Grails OohLaLog plugin adds a log4j appender to forward traffic to the oohlalog api service. This allows its users to aggregate logs across multiple servers, setup alarms, custom counters, and realtime monitor their application. See OohLaLog.

Log4J Appender

Modify your Config.groovy file to add an appender to log4j.

Example:

log4j = {
  appenders {
    appender new com.oohlalog.log4j.OohLaLogAppender( 
       name: "oohlalog", 
       authToken: "my-api-token",
       host: "api.oohlalog.com")
  }
  root {
  	info 'oohlalog'
  }
}

Appender properties:

The above configuration will automatically forward log messages of info level or higher to your oohlalog app. Simply visit oohlalog.com to signup and get your api token.

Grails Artefact Logging and Counting

The following methods are available in all Domain Classes, Controllers, and Services

void oohlaCount(String counterName, int increment = 1)

void oohlaLog(String level, String message, String category = "[artifact name]", Object exceptionOrStringDetails = null, String token = null, Long timestamp = System.currentTimeMillis() )

These methods bypass Log4J level threshold checks.

Level should be one of the standard log4J levels (TRACE, DEBUG, INFO, WARN, ALL, ERROR, FATAL)

Token can be used to relate a sequence of logs together (i.e. specific user activity)

Example:

class myService {
	def myMethod() {
        oohlaLog('DEBUG','interesting!') //always sent to OohLaLog
        oohlaCount('myMethod.called')
	}

def myOtherMethod() { log.debug('toooo interesting!') // not sent to OohLaLog if threshold is INFO (as above) }

}

To use these methods please configure the OohLaLoh log4j appender as mentioned above or add the following Config.groovy setting:

oohlalog.authToken='XXXX-XXXX-XXXXXXX'// REQUIRED 
oohlalog.host="api.oohlalog.com"// OPTIONAL 
oohlalog.path="/api/logging/save.json" // OPTIONAL 
oohlalog.port=80 // OPTIONAL 
oohlalog.secure=false // OPTIONAL 
oohlalog.debug=false // OPTIONAL 
oohlalog.hostName=null // OPTIONAL how the log source will appear

Appender properties:

Web Transaction Counting

Static Property

You may enable Controller Action counters by adding a static property to your Controllers:

Example:

class MyController {
	static oohLaLogCountActions = true
		…
}

All action requests will be counted as "Controller name (+).Action name (+)"

Config.groovy

You may also enable Controller Action counters via Config.groovy configuration:

// globally enables counting 
oohlalog.webtransactions = true 
// enables counting for a specific controller
oohlalog.webtransactions.myController = true 
// enables counting for a specific controller with a custom counter
namespaceoohlalog.webtransactions.myController = 'MyCtrlr' 
// enables counting for a specific controller action the default counter
nameoohlalog.webtransactions.myController.myAction = true 
// enables counting for a specific controller action with a custom counter namespace
oohlalog.webtransactions.myController.myAction = 'myAct'

To use these configurations please configure the OohLaLoh log4j appender or Config setting as mentioned above.

Annotations

You may also enable controler Controller Action counters via Annotation. The Annotation can be used for the Controller class and the Controller Actions:

Example:

import com.oohlalog.grails.OohLaLogWebTransaction
@OohLaLogWebTransaction('mycont')
class MyController {
  def test() { 
	render text:'test!' // counts as "mycont.test"
  }

@OohLaLogWebTransaction('my.idx') def index() { render text:'index!' // counts as "my.idx" } }

To use the taglib please configure the OohLaLoh log4j appender or Config setting as mentioned above.

Integration With Spring Security

It you have the Spring Security Core plugin installed you can automatically capture the principal's username (if available) as the log message "token". This can be used to trace user activity.

To enable this feature:

  1. Install the Spring Security Core Plugin
2. Add the following to `Config.groovy`.
oohlalog.springSecurityContext = true

Web Browser Logging and Counting

There are three tags available:

  • <olo:lib> - adds and configures the JavaScript library. Accepts "version" and "minified" attributes. The OohLaLog API JS global is "olo".
  • <olo:counterImage> - adds an image that will increment a counter when loaded by a client. Accepts "name" attribute.
  • <olo:logImage> - adds an image that will submit a log when loaded by a client. Accepts "level", "category", and "message" attributes.
Example:
<html>
<head>
<olo:lib/>
</head>
<body>
<input type="button" value="Count!" onclick="olo.count('mycounter',1);"/>
Counter Image
<olo:counterImage name="myImageCounter"/>
<br/>
Log Image
<olo:logImage level="INFO" category="myCat" message="hello world"/>
</body>
</html>

JavaScript API:

olo.count(code,incr,name+,callback+, apiKey+)
olo.info(msg,category,details+,priority+,token+,callback+,apiKey+)
olo.warn(msg,category,details+,priority+,token+,callback+,apiKey+)
olo.error(msg,category,details+,priority+,token+,callback+,apiKey+)
olo.debug(msg,category,details+,priority+,token+,callback+,apiKey+)
olo.trace(msg,category,details+,priority+,token+,callback+,apiKey+)

+optional

Low Level API:

olo.counter.get(cfg)
olo.counter.increment(cfg)
olo.counter.reset(cfg)
olo.logger.get(cfg)
olo.logger.save(cfg)
olo.logger.delete(cfg)

Examples:

olo.counter.increment(
"code">
"error">code: null
}); olo.counter.get(
"code">
"error">code: null
}); olo.warn('my msg','my cat'); olo.logger.save({category:'spanky',level:'DEBUG',message:'Howdy',callback:function(obj){alert('success='+obj.success)}}); olo.trace('my msg','my cat');

All methods support chaining.

To use the taglib please configure the OohLaLoh log4j appender or Config setting as mentioned above.