Discussion:
AOP to slf4j logger.info
Yan Jiang
2017-10-18 11:56:41 UTC
Permalink
Hi, all.

I am thinking to add some pre&post actions for SLF4J, logger.info() and
logger.error().
Is it possible to do this with Guice method interceptor?

Currently, I am doing something like:

Matcher<Class> subClassMatcher = Matchers.subclassesOf(org.slf4j.Logger.
class);
bindInterceptor(packageMatcher, Matchers.any(), new intercepters.Logger());


Backend, we are using SLF4J and LogBack.


But it doesn't work.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/c2ba51d4-9352-45bf-acc6-4c41c4b1dbd3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Luke Sandberg
2017-10-18 16:15:44 UTC
Permalink
Guice AOP only works on objects that Guice constructs. So probably not
Post by Yan Jiang
Hi, all.
I am thinking to add some pre&post actions for SLF4J, logger.info() and
logger.error().
Is it possible to do this with Guice method interceptor?
Matcher<Class> subClassMatcher = Matchers.subclassesOf(org.slf4j.Logger.
class);
bindInterceptor(packageMatcher, Matchers.any(), new intercepters.Logger
());
Backend, we are using SLF4J and LogBack.
But it doesn't work.
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/c2ba51d4-9352-45bf-acc6-4c41c4b1dbd3%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/c2ba51d4-9352-45bf-acc6-4c41c4b1dbd3%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/CAO9V1MKYRjpx53EKjgsnx86-Whm0XVCgi%2BV1L-gM6ha%3DP_3nbw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Yan Jiang
2017-10-19 01:56:35 UTC
Permalink
Thanks, Luke.

I get it now.

I still get one shot, SLF4j.logger is an interface, and Logback.Logger
implements that interface.
So I am thinking if I can do

import slf4j.Logger;

class Student {
@Logger Logger logger;
}

and bind(slf4j.Logger.class).to(logback.Logger.class);
I can still do it, right?

The tricky part is to Provider all the necessary information in
constructor, right?
Post by Luke Sandberg
Guice AOP only works on objects that Guice constructs. So probably not
Post by Yan Jiang
Hi, all.
I am thinking to add some pre&post actions for SLF4J, logger.info() and
logger.error().
Is it possible to do this with Guice method interceptor?
Matcher<Class> subClassMatcher = Matchers.subclassesOf(org.slf4j.Logger.
class);
bindInterceptor(packageMatcher, Matchers.any(), new intercepters.Logger
());
Backend, we are using SLF4J and LogBack.
But it doesn't work.
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/c2ba51d4-9352-45bf-acc6-4c41c4b1dbd3%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/c2ba51d4-9352-45bf-acc6-4c41c4b1dbd3%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/ac48a307-c038-4452-a2a6-8ee759934fe2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stephan Classen
2017-10-19 06:15:10 UTC
Permalink
Post by Yan Jiang
Thanks, Luke.
I get it now.
I still get one shot, SLF4j.logger is an interface, and Logback.Logger
implements that interface.
So I am thinking if I can do
import slf4j.Logger;
class Student {
@Logger Logger logger;
}
and bind(slf4j.Logger.class).to(logback.Logger.class);
I can still do it, right?
The tricky part is to Provider all the necessary information in
constructor, right?
Post by Luke Sandberg
Guice AOP only works on objects that Guice constructs. So probably
not
<javascript:>>
Post by Luke Sandberg
Post by Yan Jiang
Hi, all.
I am thinking to add some pre&post actions for SLF4J, logger.info()
and
Post by Luke Sandberg
Post by Yan Jiang
logger.error().
Is it possible to do this with Guice method interceptor?
Matcher<Class> subClassMatcher =
Matchers.subclassesOf(org.slf4j.Logger.
Post by Luke Sandberg
Post by Yan Jiang
class);
bindInterceptor(packageMatcher, Matchers.any(), new
intercepters.Logger
Post by Luke Sandberg
Post by Yan Jiang
());
Backend, we are using SLF4J and LogBack.
But it doesn't work.
--
You received this message because you are subscribed to the Google
Groups
Post by Luke Sandberg
Post by Yan Jiang
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it,
send an
Post by Luke Sandberg
Post by Yan Jiang
<javascript:>.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/c2ba51d4-9352-45bf-acc6-4c41c4b1dbd3%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/c2ba51d4-9352-45bf-acc6-4c41c4b1dbd3%40googlegroups.com?utm_medium=email&utm_source=footer>
Post by Luke Sandberg
Post by Yan Jiang
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/ac48a307-c038-4452-a2a6-8ee759934fe2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/7B3A900E-A0DF-4435-B09E-633263E2B677%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
Yan Jiang
2017-10-19 07:41:55 UTC
Permalink
Thank you, sci.

That is a good point.
I think I'll have to go with creating my own LoggerWrapper.
was not created by you (i.e. bindInstance) then it should work. Given the
class injected is not final.
Post by Yan Jiang
Thanks, Luke.
I get it now.
I still get one shot, SLF4j.logger is an interface, and Logback.Logger
implements that interface.
So I am thinking if I can do
import slf4j.Logger;
class Student {
@Logger Logger logger;
}
and bind(slf4j.Logger.class).to(logback.Logger.class);
I can still do it, right?
The tricky part is to Provider all the necessary information in
constructor, right?
Post by Luke Sandberg
Guice AOP only works on objects that Guice constructs. So probably not
Post by Yan Jiang
Hi, all.
I am thinking to add some pre&post actions for SLF4J, logger.info()
and logger.error().
Is it possible to do this with Guice method interceptor?
Matcher<Class> subClassMatcher = Matchers.subclassesOf(org.slf4j.Logger
.class);
bindInterceptor(packageMatcher, Matchers.any(), new intercepters.Logger
());
Backend, we are using SLF4J and LogBack.
But it doesn't work.
--
You received this message because you are subscribed to the Google
Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/c2ba51d4-9352-45bf-acc6-4c41c4b1dbd3%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/c2ba51d4-9352-45bf-acc6-4c41c4b1dbd3%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/052de221-75be-479a-92fe-b247899bd2a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...