Not able to Print logs using SLF4j from Idp

Surinaidu Majji pioneer.suri at gmail.com
Fri May 29 08:02:30 EDT 2015


Hello All,
I came to know that the shibboleth using Slf4j for printing
logs(idp-audit.log, idp-process.log).This Slf4j is implemented with
"logback" to printing the files in the log files. Now we have our
application which is configuraed with SSO by using shibboleth-2.4.0. We are
using "ExternalAuthn" Login handler. In "ExternaAuthn" login handler
externalAuthnPath="/ext/ExternalLogin" which is a servlet. In this servlet
we have written log messages. but this servlet code is generated as a "jar"
file and putting into the idp/Web-inf/libs along with shibboleth libs.while
runnging the application we are not able to see the logs in console as well
as in the file also.

Application specific thing depends on shibboleth idp:
We are using Slf4j and implementing slf4j with log4j to print the logs in
console as well as in the file.The code which we are trying to printing the
logs from created jar which is placed in the tomcat(idp/Web-Inf/lib) but
when running the application i am not able to see printing the logs in the
console.

Please look into the follwoing configuration configured for jar:

    log4j.category.sample.sso.application=Debug, file, C
    log4j.additivity.sample.sso.application=true

    log4j.appender.C=org.apache.log4j.ConsoleAppender
    log4j.appender.C.Target=System.out
    log4j.appender.C.ImmediateFlush=true
    log4j.appender.C.layout=org.apache.log4j.PatternLayout
    log4j.appender.C.layout.ConversionPattern=%-5p %d [%t] %m%n


    ### direct messages to file ###
    log4j.appender.file=org.apache.log4j.RollingFileAppender

log4j.appender.file.File=${catalina.home}/var/ipau/logs/ssoapplication.log
    log4j.appender.file.Append=true
    log4j.appender.file.MaxFileSize=10MB
    # mylog.log.10 \u307e\u3067\u4fdd\u6301
    log4j.appender.file.MaxBackupIndex=50
    log4j.appender.file.layout=org.apache.log4j.PatternLayout
    log4j.appender.file.layout.ConversionPattern=%d %5p [%t] %c{1} - %m%n

    log4j.rootLogger=INFO, C, file

My project structure is:

Sample--
    src--
       sample--
          sso--
            application
       log4j.properties.

I am preparing the jar file from the above structure and placed in the
other war file in the tomcat.
As suggested in the Stackover flow,  i tried by reading the
log4j.properties file externally which is below.

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.Writer;
    import java.util.Properties;
    import java.util.regex.Matcher;

    import javax.servlet.ServletException;
    import javax.servlet.http.Cookie;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.apache.commons.codec.binary.Base64;
    import org.apache.log4j.PropertyConfigurator;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;


    public class PreProcessServlet extends HttpServlet {

    private static final long serialVersionUID = -572799841125956990L;

    PreLoginServlet() {

    }



    protected void service(HttpServletRequest request,
    HttpServletResponse response) throws ServletException, IOException {
        try {
              FileInputStream fis = new FileInputStream(new
File("/log4j.properties"));
    //          InputStream input =
this.class.getClassLoader().getResourceAsStream("log4j.properties");
              Properties prop = new Properties();
              prop.load(fis);
              PropertyConfigurator.configure(prop);
          } catch (IOException e) {
              e.printStackTrace();
              System.out.println("ERROR: Unable to load log4j.properties");
          }
        final Logger log = LoggerFactory
                .getLogger(PreProcessServlet .class);
    log.debug("Pre login process is started");

    System.out.println("sys printing");
    Boolean parametersAreValid = true;
    RegularExpression regularExpression = RegularExpression.getInstance();


    String sessionId = request.getParameter(GlobalStrings.sessionId);
    if (null != sessionId){
    Matcher sessionIdMatcher =
regularExpression.getSessionPattern().matcher(sessionId);
    if ((sessionId.equals(GlobalStrings.nullString)) ||
    (!sessionId.equals(GlobalStrings.nullString) &&
sessionIdMatcher.find())){
    log.error("PreLoginServlet "+ "Invalid SessionID " + sessionId);
    parametersAreValid = false;
    }
    }else{
    log.info("sessionId field is empty");
    }

    }

Update: I got the following error even i have added dependency
libs(slf4j-log4j12-1.7.5, log4j along with slf4j):
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further
details.


Could you please help any body to solve this problem.





Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://shibboleth.net/pipermail/users/attachments/20150529/8afcefd6/attachment.html>


More information about the users mailing list