DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Software Design and Architecture
  3. Security
  4. Using Logback with Weld

Using Logback with Weld

Rob Williams user avatar by
Rob Williams
·
Oct. 11, 11 · Interview
Like (0)
Save
Tweet
Share
4.77K Views

Join the DZone community and get the full member experience.

Join For Free

The Weld stuff all comes with the jboss logging stuff woven into it. And the fun part is, that of course, since the logging is not part of a standard, you have to bring in another dependency (solder) to make it work. Then there's more fun. It declares jboss-logging as provided, which is apparently wrong. After pissing away way, way, way too much time trying to get this all working in my weld project with Arquillian tests, I decided I wanted to use logback. Thankfully, that went pretty quickly and painlessly.

First thing to do is add the logback-core, logback-classic and slf4j-api dependencies to your pom. Then make a class with a Produces annotated method comme ça:

package com.ontometrics.logging;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LoggerFactoryProducer {
    
    @Produces
    @OntoLogger
    public Logger produceLog(InjectionPoint injectionPoint) {
        return LoggerFactory.getLogger(injectionPoint.getMember().getDeclaringClass());
    }

}
Of course, you need an annotation for the logger qualifier that identifies this as yours. I had the jboss logging working, but there were multiple producers and I was getting the warning on the injections. I was trying to get down to zero warnings when I found that the whole little cardhouse was just barely upright. Actually, eclipse (or jboss tools) was lopsided on this account too, because I got to where it was satisfied that it could figure out which logger to inject on 3/4 of my files, but 2 or 3 still gave the warning, though they were identically configured.

Next step was to just go around injecting the logger. The other good thing in this was there was no need to do anything to shrinkwrap. All works now. Also, you can pass a logback-test.xml config file to shrinkwrap. I don't like going to my jboss install to configure the logger, and I couldn't get it to show me debug messages, for whatever loopy reason.

From http://www.jroller.com/robwilliams/entry/using_logback_with_weld

JBoss Dependency Debug (command) Testing Pass (software) Eclipse producer Injection

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Spring Boot vs Eclipse MicroProfile: Resident Set Size (RSS) and Time to First Request (TFR) Comparative
  • What Are the Benefits of Java Module With Example
  • Multi-Cloud Integration
  • Stop Using Spring Profiles Per Environment

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: