The Yocto build platform is very powerful, with many options and the ability to quickly incorporate new packages into an embedded linux distribution via bitbake recipes. If you are building up a system for deployment, you'll find that there are several packages you'll need that may not be readily available out of the box. In my case, I am using the builder supplied by Phytec, an embedded hardware manufacturer. Their default package didn't include the system logger, which I find to be crucial for any moderately complex system.
No worries, with a little effort this can be added to the system. Another key function is log management. A deployed system cannot have files which grow in size indefinitely. Logrotate is a handy utility for managing this.
Installing The Syslog Plus A Log Rotation Service
In my example, I'm using Arch Linux with systemd for service management. The builder toolkit comes with the rsyslog recipe. I'm appending to this recipe in my own meta-layer, which I will explain in further detail:
What is happening here? First, the default rsyslog.conf is being replaced with my own, just to configure the log how I would like. This is not necessary if the default configuration works for your application. The same is true for the rsyslog.service file.
Next, I'm adding a simple logrotate.service file which simply allows the rotation to be called by the systemd timer logrotate.timer:
The timer service will run 1 minute after boot and every 24 hours thereafter.
Configuring The Log Rotation
Logrotate will run any configurations placed in /etc/logrotate.d. In my case, I am most concerned with the syslog, which can sometimes get heavy logging and I restrict it:
A Note About Embedded Logging
For my application I'm logging to nonvolatile storage. By default, the logger would have logged to /var/log which resides in ram. If logging to an sd card or usb stick, be careful. If you are logging a decent amount of data over time you will destroy the media. In testing I managed to destroy a 1GB sd card within a week.
Comments
Post a Comment