tika-server

Apche Tika: How to save console log to a file. Use log4j?


Apache Tika 1.24.1.

I read that there is a logging facility called log4j, but didn't find a quick to copy example. Does tika have some command line argument to save console logs to a file? Thanks.


Solution

  • You can configure log4j used in Tika Server using your own custom configuration file. For example, you can write a custom log4j.properties file like this:

    log4j.rootLogger = INFO, FILE
    log4j.appender.FILE=org.apache.log4j.FileAppender
    log4j.appender.FILE.File=/tmp/log.out
    log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
    log4j.appender.FILE.layout.conversionPattern=%m%n
    

    Then you can specify it's location on the command line using the log4j.configuration system property. This can be used to load files from disk (using file: prefix), or placing the file within the configured classpath (useful if you are already doing tika-config.xml changes).

    In this example, if I placed the above custom log4j.properties file next to my Tika Server JAR file I could run the following:

    java -Dlog4j.configuration=file:"./log4j.properties" -jar tika-server-1.25.jar
    

    This will then log using the settings specified in the configuration - which in this example is to a file.

    You can use both the properties and XML based formats for log4j configuration using this approach.

    There is more information to be found on logging in Apache Tika here.