Kamailio, the open-source SIP server, is renowned for its robustness and flexibility. One of the many tasks that administrators frequently encounter is the effective management of logs. By default, Kamailio logs are directed to syslog. However, there may be scenarios where redirecting these logs to a separate file could facilitate easier management, analysis, or archiving. In this blog post, we’ll guide you through the steps to accomplish this.
1. Understanding Kamailio’s Default Logging
By default, Kamailio utilizes the syslog facility for logging. This means that on most systems, Kamailio logs can be found in either /var/log/syslog or /var/log/messages. While convenient for some, this can pose a challenge when dealing with high volumes of SIP traffic, as Kamailio logs can quickly overwhelm your general syslog.
Kamailio uses the LOG_LOCAL0 log facility by default. To check your Kamailio log facility, look for the “log_facility” parameter in the Kamailio configuration file, as shown below:
log_facility=LOG_LOCAL0
2. Setting Up a Dedicated Kamailio Log File
To redirect Kamailio logs to a separate file:
a. First, create a log file for Kamailio using the command below:
sudo touch /var/log/kamailio.log
b. Set proper permissions for the kamailio.log file:
sudo chown syslog:adm /var/log/kamailio.log
c. Open the rsyslog configuration (or syslog configuration, depending on your system):
sudo vim /etc/rsyslog.conf
d. Add the following line at the bottom to create a dedicated log file for Kamailio:
local0.* /var/log/kamailio.log
This configuration instructs rsyslog to redirect all logs from the LOG_LOCAL0 facility to /var/log/kamailio.log.
e. Save and close the file.
f. Restart the rsyslog service:
sudo service rsyslog restart
g. To test if the configuration is working, you can generate a test log message:
logger -p local0.notice "This is a test log message"
Then, check the /var/log/kamailio.log file to see if the test log message appears:
cat /var/log/kamailio.log
Note: If you are using systemd (like systemctl) to manage kamailio, make sure to disable logging (like remove -E) from the ExecStart parameter in the configuration file of systemd ( like kamailio.service). This will disable log management using systemd.
3. Configuring Kamailio’s Logging Level
Now that you’ve redirected the logs, you might want to adjust the logging level. Kamailio’s verbosity can be controlled using the debug parameter in the kamailio.cfg file.
Open the Kamailio configuration:
sudo vim /etc/kamailio/kamailio.cfg
Find the debug parameter and set it to your desired level. The default level in kamailio.cfg is 2, which prints messages up to the INFO level. To enable debug logs (more verbose logging), set the debug parameter to 3, as shown below:
debug=3
Save and close the file, then restart Kamailio:
sudo service kamailio restart
or
sudo systemctl restart kamailio
4. Managing Log Rotation
Over time, the Kamailio log file can grow significantly in size. It’s good practice to set up log rotation.
a. Create a new configuration file for kamailio.log under the /etc/logrotate.d/ directory. You’ll need root permissions to create this file:
sudo vim /etc/logrotate.d/kamailio
b. Add the following content:
/var/log/kamailio.log {
daily
rotate 7
compress
delaycompress
missingok
notifempty
create 0640 root adm
postrotate
invoke-rc.d rsyslog rotate > /dev/null
endscript
}
This configuration will rotate the log daily, retain the last seven logs, and compress older ones.
c. Save and close the file.
d. To test your new configuration immediately, you can manually run logrotate with the -f (force) option:
sudo logrotate -f /etc/logrotate.d/kamailio
Conclusion
Managing Kamailio logs effectively is crucial for system administrators, especially when troubleshooting or monitoring SIP traffic. By redirecting logs to a separate file and setting up log rotation, you can ensure that your logs are both accessible and manageable. Happy logging!
Akash Gupta
Senior VoIP Engineer and AI Enthusiast

AI and VoIP Blog
Thank you for visiting the Blog. Hit the subscribe button to receive the next post right in your inbox. If you find this article helpful don't forget to share your feedback in the comments and hit the like/clap button. This will helps in knowing what topics resonate with you, allowing me to create more that keeps you informed.
Thank you for reading, and stay tuned for more insights and guides!

Leave a Reply