Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support @autowiring of Loggers [SPR-4431] #9109

Closed
spring-projects-issues opened this issue Feb 6, 2008 · 8 comments
Closed

Support @autowiring of Loggers [SPR-4431] #9109

spring-projects-issues opened this issue Feb 6, 2008 · 8 comments
Assignees
Labels
has: votes-jira in: core status: declined type: enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 6, 2008

Kenny MacLeod opened SPR-4431 and commented

It occurred to me that a neat application of autowiring would be the ability to autowire logger objects.

Say a class declares something like:

private @Autowired Log logger;

where Log is from commons-logging. Spring would then generate a Log object for the declaring class and then inject it.

I don't think this can be done using the existing resolveResolvableDependency mechanism, since information about the dependent class isn't made available in order to create the Log.

Thoughts?


Attachments:

Issue Links:

11 votes, 14 watchers

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 4, 2008

Paul Grove commented

Can we add support for SL4J instead or as well as commons logging?
IMHO SL4J is a better solution for providing a common logging API and is gaining community adoption across main large OS projects.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jul 27, 2011

Jonathon Freeman commented

JBoss Seam has a @Logger annotation that does just this, and it's incredibly handy. I was surprised this kind of thing wasn't already in Spring, what with logging being so ubiquitous.

I also agree with Paul Grove above: if/when this is added, please at least support SLF4J (if not outright replace commons with it). SLF4J (along with logback) is basically the new replacement for log4j... the creator of log4j is the same guy that created SLF4J and logback.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Aug 29, 2012

Sinuhé commented

Project Lombok has some similar annotations: http://projectlombok.org/features/Log.html

An "invisible" log field is created at compile time. The advantage is it works for all objects (not only Spring beans).

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Aug 30, 2012

Gleb Schukin commented

I've created BeanPostProcessor that injects slf4j logger into beans. See files attached.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Sep 12, 2012

Chris Shayan commented

Hi

But if the scope is prototype then it will keep instantiate the logger which in case of lof4j i think is not necessary. Am I wrong or what? Please advice.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Sep 12, 2012

Gleb Schukin commented

See this link. Since logger is injected at bean creation should be no difference to declare loggers as instance variables instead of static one.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Sep 12, 2012

Pavel Sklenak commented

I don't like idea of a special annotation. This way I could end up with plenty annotations. Just consider for example private static final NLSBundle NLS = NLSBundle.of(ClassName.class). I created instead pluggable IAutowireCandidateFactory, see the code example, please. It just works with standard AutowiredAnnotationBeanPostProcessor.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Sep 22, 2015

Juergen Hoeller commented

Closing groups of outdated issues. Please reopen if still relevant.

@spring-projects-issues spring-projects-issues added status: declined type: enhancement in: core has: votes-jira labels Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has: votes-jira in: core status: declined type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants