Grails exceptions filtering, RabbitMQ plugin - grails

grails is filtering exceptions and show only related errors.
how to get exceptions thrown in handleMessage of rabbitmq on console?
For example, simple consuming service with Division by zero operation. I want to see all exceptions happened in handleMessage on the console.
class SimpleService {
static rabbitSubscribe = 'test'
void handleMessage(message) {
def a = 10/0
}
}

Your question is quite short, so I'm assuming a lot. Do you mean that you're using 2.0 and seeing the truncated stacktraces in run-app? You can add the --stacktrace and/or -verbose commandline options to see more output, e.g.
grails run-app --stacktrace -verbose

Related

What is required to display custom messages in jenkins report?

I have Jenkins ver. 2.7.4 and I want to see custom messages in report
besides stack trace. What do I need to do for this?
If you are writing a jenkins plugin and you've subclassed Notifier, then you can log to the build output using an instance of BuildListener, like so:
Helper method:
private void logger(BuildListener listener, String message){
listener.getLogger().println(message);
}
Example Usage:
logger(listener, "Verbose Logging Enabled");
You can see a real world example of this in the source code for the packagecloud plugin for jenkins
See: https://wiki.jenkins-ci.org/display/JENKINS/Packagecloud+Plugin

Cloud Dataflow: java.lang.IllegalStateException: no evaluator registered for GroupedValues

I'm getting the following exception when running the pipeline locally. There is no exception when submitting for cloud execution.
Thanks,
Genady
INFO: Executing pipeline using the DirectPipelineRunner.
Exception in thread "main" java.lang.IllegalStateException: no evaluator registered for GroupedValues [GroupedValues]
at com.google.cloud.dataflow.sdk.runners.DirectPipelineRunner$Evaluator.visitTransform(DirectPipelineRunner.java:606)
at com.google.cloud.dataflow.sdk.runners.TransformTreeNode.visit(TransformTreeNode.java:200)
at com.google.cloud.dataflow.sdk.runners.TransformTreeNode.visit(TransformTreeNode.java:196)
at com.google.cloud.dataflow.sdk.runners.TransformHierarchy.visit(TransformHierarchy.java:109)
at com.google.cloud.dataflow.sdk.Pipeline.traverseTopologically(Pipeline.java:204)
at com.google.cloud.dataflow.sdk.runners.DirectPipelineRunner$Evaluator.run(DirectPipelineRunner.java:583)
at com.google.cloud.dataflow.sdk.runners.DirectPipelineRunner.run(DirectPipelineRunner.java:327)
at com.google.cloud.dataflow.sdk.runners.DirectPipelineRunner.run(DirectPipelineRunner.java:70)
at app.Main.main(Main.java:124)
The code outline is basically this:
PCollection<KV<MyKey, Iterable<MyValue>>> groupedByMyKey = ...
PCollection<KV<MyKey, MyAggregated>> aggregated = groupedByMyKey.apply(
Combine.<MyKey, MyValue, MyAggregated>groupedValues(new Aggregator()));
Aggregator class extends CombineFn<MyValue, List<MyValue>, MyAggregated>
Can you share a code snippet that triggers this? GroupedValues is a PTransform that is often used within various combining transforms, so it might be from using something like Min, Max, etc.
The error means that the DirectPipelineRunner doesn't know how to evaluate a GroupedValues. However, that's unexpected, since that should have been expanded into a ParDo before execution.
I found the reason to this behaviour
I was using a command line argument to run it in remote mode (--runner=BlockingDataflowPipelineRunner) and then forced it to run locally with
PipelineRunner<?> runner = DirectPipelineRunner.fromOptions(options);
runner.run(p);
After removing these lines and just using the --runner=DirectPipelineRunner argument it worked as expected.

logging my application's classes at DEBUG level, all others at WARN

I've configured my Grails app to read the log4j config from /conf/log4j.properties file instead of the more usual DSL in Config.groovy, by adding the following Spring bean:
log4jConfigurer(MethodInvokingFactoryBean) {
targetClass = "org.springframework.util.Log4jConfigurer"
targetMethod = "initLogging"
arguments = ["/conf/log4j.properties", 1000 * 60] // 2nd arg is refresh interval in ms
}
My goal is to log all the classes in the app itself at the DEBUG level, and all others at the WARN level. /conf/log4j.properties contains the following:
log4j.logger.com.myapp=DEBUG, CONSOLE
log4j.logger.grails.app=DEBUG, CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%-5p myapp %c{3} %d{HH:mm:ss,SSS} %t : %m%n
It seems the namespace com.myapp is used for regular classes in my app (e.g. those under src/groovy), whereas the namespace grails.app is used for Grails artefacts (controllers, services, taglibs, etc.). However the grails.app namespace also includes artefacts from plugins, which I don't want to log at the DEBUG level.
Is there a way to enable DEBUG logging only for the classes in my application?
You append your package unto the grails.app.controllers to get just your application.
info 'grails.app.controllers.mypackage'
Adding the following solved the problem
log4j.logger.grails.app.conf.com.myapp=DEBUG, CONSOLE
log4j.logger.grails.app.filters.com.myapp=DEBUG, CONSOLE
log4j.logger.grails.app.taglib.com.myapp=DEBUG, CONSOLE
log4j.logger.grails.app.services.com.myapp=DEBUG, CONSOLE
log4j.logger.grails.app.controllers.com.myapp=DEBUG, CONSOLE
log4j.logger.grails.app.domain.com.myapp=DEBUG, CONSOLE
Presumably if a Grails app has other types of artefacts that you want to log at the DEBUG level, an additional logger should be configured for each one.

Spock Integration Test fails when run with other integration tests-succeeds in isolation using integration:spock

I am adding a first spock integration test to an existing set of tests for a grails 2.1.1 application. The test runs and tests pass when run using:
grails test-app integration:spock CreditServiceSpec
(Yes, everything is in the default package - fixing this is a ton of work that will not be approved...file under technical debt.)
However, when I run all the tests (grails test-app), unit test pass, spock unit tests pass, integration tests pass, but I get the following failure for spock integration:
| Completed 818 integration tests, 0 failed in 104001ms
| Running 1 spock test...
| Failure: CreditServiceSpec
| groovy.lang.GroovyRuntimeException: failed to invoke constructor: public org.codehaus.groovy.grails.test.support.GrailsTestAutowirer(org.springframework.context.ApplicationContext) with arguments: [] reason: java.lang.IllegalArgumentException
at grails.plugin.spock.IntegrationSpec.$spock_initializeSharedFields(IntegrationSpec.groovy:33)
| Completed 0 spock test, 0 failed in 33ms
| Tests PASSED - view reports in /Users/*/projects/GrailsPlugins/DomainServices/target/test-reports
I get the exact same exception whether I run the full test I built or the following, very strip down example:
import grails.plugin.spock.IntegrationSpec
class CreditServiceSpec extends IntegrationSpec {
def setup() {}
def cleanup() {}
public void "sample"() {
setup:"Nothing to do here."
expect:"This is the truest of truths..."
true == true
}
}
I did crack open IntegrationSpec and looked at line 33:
#Shared private autowirer = new GrailsTestAutowirer(applicationContext)
But determining how/why the applicationContext is not being passed in properly is beyond me and, perhaps, is the thrust of my question.
Has anyone encountered this kind of behavior and found a way to get spock integration to play nice with other tests? Thanks.
It looks like Grails 2.1.1 had several issues with Spock tests in the Integration scope. Jeff's comment and Peter's in particular sound like the issue you were having; basically the ApplicationHolder was null or an empty list.
The parent task lists Grails 2.2.5 as the fix version. Any chance you can upgrade to that (or some even later version) and see if the problem persists?
There have also been cases where a simple grails clean has fixed issues like this.
I had a problem with the exact same symptom.
I was using the BuildTestData plugin and used the #Build annotation in a IntegrationSpec, but using the #Build with use a transformation wich extended the #TestFor transformation which is incompatible with the Intengration runtime.
So just remove the #Build annotations and it will run.

Grails conversionPattern change at runtime

Using a standard log4j configuration for my grails app, with a custom conversion pattern like that :
log4j = {
appenders {
console name:'stdout', layout:pattern(conversionPattern: '[%-7p][%d{dd/MM/yyyy HH:mm:ss,SSS}] %C %m%n')
}
root {
warn 'stdout'
additivity = true
}
error 'org.grails.plugins.springsecurity'
error 'org.codehaus.groovy.grails.web.servlet' // controllers
// ...
warn 'org.mortbay.log',
'org.apache.tomcat',
'org.apache.tomcat.util.digester'
debug 'grails.app'
}
My grails app start as expected .. with the good conversionPattern ... but only during few log lines ... to finally fallback to the default grails conversionPattern ... :-/
Any idea ?
I don't code in Grails but I do know log4j very well.
On the surface, it seems you need to inspect those lines that aren't formatted as expected. Chances are, they are not caught by the logger that uses your stdout appender.
From what I can piece together, it looks to me like maybe your warning logger is the only one that uses your stdout appender. Meaning anything other than warnings would not format as expected. Further, it's also possible that loggers present in your libraries catch some log statements but not others.
Basically, the best way to solve this is to modify your pattern to give you good information on your loggers (I would suggest replacing the %C pattern, which is very slow to execute, with %c to see the exact category that was used by the logger). Then, look at the differences between what's properly formatted and everything else.
Do they have a common level (info, debug, error, etc)?
Do they stem from the same package?
Are they 3rd party library calls?
Figure out what they have in common and you will find your error.

Resources