Logs

Logging mechanism is very flexible in Tigase server. You can adjust separate logging level for each single component. You can also direct loggin to many different destinations like console, file, network socket and so on. Unfortunately it also mean it is a bit complex. The general idea however is quite simple so once you understand it it shouldn’t be difficult for you anymore. This guide however describes logging very briefly. Loot at full configuration documentation for detailed explanation.

In standard sever configuration you usually want to turn off all logging to console and all warning and more serious notices directed to log file. Let’s say logs will be written to /var/log/tigase-server.log which shouldn’t get bigger than 10MB and 5 old logs will be preserved. Here are instructions how to set options.

Open tigase-config.xml in you favorite text editor and search for string: "logging". You should find section looking like this:

<node name="logging">
  <map>
    <entry value="FINE" type="String" key=".level"/>
    <entry value="java.util.logging.ConsoleHandler+java.util.logging.FileHandler" type="String" key="handlers"/>
    <entry value="tigase.util.LogFormatter" type="String" key="java.util.logging.ConsoleHandler.formatter"/>
    <entry value="WARNING" type="String" key="java.util.logging.ConsoleHandler.level"/>
    <entry value="true" type="String" key="java.util.logging.FileHandler.append"/>
    <entry value="5" type="String" key="java.util.logging.FileHandler.count"/>
    <entry value="tigase.util.LogFormatter" type="String" key="java.util.logging.FileHandler.formatter"/>
    <entry value="ALL" type="String" key="java.util.logging.FileHandler.level"/>
    <entry value="100000" type="String" key="java.util.logging.FileHandler.limit"/>
    <entry value="logs%2Ftigase.log" type="String" key="java.util.logging.FileHandler.pattern"/>
    <entry value="true" type="String" key="tigase.useParentHandlers"/>
  </map>
</node>

Assuming we make this guide easy and strightforward let me show how this section should look like after modification. So you could just copy and paste it to your config file without going into details. After the configuration code I will briefly explain what each line means so you should be able to further adjust settings for your needs.

<node name="logging">
  <map>
    <entry value="WARNING" type="String" key=".level"/>
    <entry value="java.util.logging.ConsoleHandler+java.util.logging.FileHandler" type="String" key="handlers"/>
    <entry value="tigase.util.LogFormatter" type="String" key="java.util.logging.ConsoleHandler.formatter"/>
    <entry value="tigase.util.LogFormatter" type="String" key="java.util.logging.FileHandler.formatter"/>
    <entry value="OFF" type="String" key="java.util.logging.ConsoleHandler.level"/>
    <entry value="true" type="String" key="java.util.logging.FileHandler.append"/>
    <entry value="5" type="String" key="java.util.logging.FileHandler.count"/>
    <entry value="ALL" type="String" key="java.util.logging.FileHandler.level"/>
    <entry value="10000000" type="String" key="java.util.logging.FileHandler.limit"/>
    <entry value="%2Fvar%2Flog%2Ftigase-server.log" type="String" key="java.util.logging.FileHandler.pattern"/>
    <entry value="true" type="String" key="tigase.useParentHandlers"/>
  </map>
</node>

Each Line Explained:

<entry value="WARNING" type="String" key=".level"/>

Effectively we set WARNING level for all possible logs for all possible components. So more detailed logging information will be discarded. All possible log levels are: OFF, SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL.

<entry value="java.util.logging.ConsoleHandler+java.util.logging.FileHandler" type="String" key="handlers"/>

We set 2 handlers for logging information: console and file handler. As we are going to turn off logging to console we could remove all configuration settings for console handler as well. It would simplify configuration file. I don’t recommend it though. If there are any problems with your installation switching console logging on might be very helpful and if you remove these settings from config file it may be difficult to bring them back. Hm…​ maybe not with such excellent documentation…​. ;-)

<entry value="tigase.util.LogFormatter" type="String" key="java.util.logging.ConsoleHandler.formatter"/>
<entry value="tigase.util.LogFormatter" type="String" key="java.util.logging.FileHandler.formatter"/>

We set here log formatter for console and file handler. Standard Java handlers print each log message in 2 lines. Tigase formatter prints all logging info in 1 line which make it much easier to filter logs by log type, logging component or log level or whatever you wish. You can just use simple sed command and that’s it.

<entry value="OFF" type="String" key="java.util.logging.ConsoleHandler.level"/>

Here we just switch console handler off. To switch it on back set any different level from the list above.

<entry value="true" type="String" key="java.util.logging.FileHandler.append"/>

This settings is to controll whether we want to append logs into old log file or we want to create new log file (removing old content) each time server is restarted.

<entry value="5" type="String" key="java.util.logging.FileHandler.count"/>

Sets number of old log files to preserve to 5.

<entry value="ALL" type="String" key="java.util.logging.FileHandler.level"/>

This line sets the logging level for file handler. Here we set that we want all possible logs to be written to the file. The global level setting however says that only WARNING logs will be generated. So if you want to have more detailed logs you need to adjust global logging level.

<entry value="10000000" type="String" key="java.util.logging.FileHandler.limit"/>

Log file maximum size set to 10MB. After reaching this size the log file is closed and new file is created.

<entry value="%2Fvar%2Flog%2Ftigase-server.log" type="String" key="java.util.logging.FileHandler.pattern"/>

Location of the log file and file name: /var/log/tigase-server.log. Please note %2F instead of \'/' character.

<entry value="true" type="String" key="tigase.useParentHandlers"/>

This setting requires going into more details so it is explained in comprehensive configuration guide.