Skip to main content

Setting Up Log Rotation in Yocto



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

Popular posts from this blog

Real Time Scheduling Of Threads In Linux

It can be easy to get tripped up when setting up and managing real time threads in linux. In fact, I recently discovered that the thread management calls I was using within the Poco C++ library effectively did nothing. It provides an interface to set a general thread priority, but not its policy and as a result has makes no changes to the thread. Real Time Policies And The Poco ThreadPool Linux supports different thread scheduling types, called policies. For linux kernels with real time functionality, there should be support for both FIFO and round robbin real time scheduling.  SCHED_FIFO requires the thread to yield to the processor, guaranteeing that it completes its operations before another thread takes over.  SCHED_RR uses a specified time slice for the thread. I was using the Poco::ThreadPool library to set priority at thread start. This can be misleading and ineffective because it uses the SCHED_OTHER policy only, which is not a real time policy. Looking at the...

Review: Lenovo Yoga 720

I recently picked up a new Lenovo Yoga 720 15" laptop. When it comes to laptops, everything is a trade-off. You can have small and lightweight with a less powerful processor or get something beefier and sacrifice those things along with battery power. However, this laptop strikes an excellent balance. As far as know, it's the only 2 in 1 on the market with a quad core i7 and a GTX 1050 graphics card. I didn't know how much I would make use of tablet mode, but it is quite handy for watching Netflix in bed or browsing the web sitting on the couch. While it is huge for a tablet, it actually works fine in that role if sitting down with it. My complaints about tablet mode are on the Windows side, MS still has yet to build in critical functionality needed to support 2 in 1s well. I have only done limited gaming on it, but it's great so far. I've played Bioshock Infinite at max 1080p settings and it plays almost flawlessly. It's impressive to see this kind ...