简体   繁体   中英

how to show result of java program in console output in eclipse using log4j logger?

i am trying to write a program with jena library for my ontology.
For jena i am using log4j when i add jena libraries to my project, eclipse console do not show any result but without it System.out.println("something") works good. i think problem is in log4j. and to set console output to it.but i don't know how to use this.
this is my code:

package tutorial;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.datatypes.xsd.*;

import java.io.*;
public class helloRDFworld {

    private InfModel model;

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        helloRDFworld  application=new  helloRDFworld();
        application.test();
    }

    private void loadantology (String antologyfile)
    {
        try {
            String uri =new File(antologyfile).toURI().toString();
            model.read(uri);
            } 
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public helloRDFworld(){
        model=ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
    }
    public void test()
    {
        loadantology("food.owl");

    }

}

this is my library list
在此输入图像描述在此输入图像描述
share your information please
with Regard

You need to create a log4j.properties file and add it to your classpath. Add this to your log4j.properties:

log4j.rootLogger = ALL, Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.conversionPattern=%m%n

Make sure you have your apache log4j library.

Then declare and initialise like this:

final static Logger logger = Logger.getLogger(classname.class);

Then use it to capture errors, debug or info messages eg

logger.info("This is info ");

Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM