# Service logs retention

**URL:** <https://forums.balena.io/t/service-logs-retention/319572>\
**Category:** balenaOS\
**Created:** [May 21, 2021, 8:21am UTC](https://forums.balena.io/t/service-logs-retention/319572 "2021-05-21T08:21:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mathroc](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mathroc/32/5033_2.png) [@mathroc](https://forums.balena.io/u/mathroc)\
**Post date:** [May 21, 2021, 8:21am UTC](https://forums.balena.io/t/service-logs-retention/319572/1 "2021-05-21T08:21:04Z")

</div>

Hi,

I’d like to know more about how log retention works. Most of the time I can’t find the logs I’m looking for if it’s not something that happened very recently.

On the device logs are available a bit longer but they disappear when a container is recreated (eg: new deploy, service is restarted manualy or because it crashed). Sometime I’m able to find more logs in journald but it’s not really handy

On [balena-cloud.com](http://balena-cloud.com) logs are disappearing after some time limit I think but I’m not sure

The most important thing for me would be to have reliable access to the logs from [balena-cloud.com](http://balena-cloud.com) for at least a few days.

thank you

---

<div class="post-metadata">

**Author:** ![vipulgupta2048](https://avatars.discourse-cdn.com/v4/letter/v/a183cd/32.png) [@vipulgupta2048](https://forums.balena.io/u/vipulgupta2048)\
**Post date:** [May 21, 2021, 9:30am UTC](https://forums.balena.io/t/service-logs-retention/319572/4 "2021-05-21T09:30:25Z")

</div>

Hello  
Thanks for reaching out, have you tried using persistent logging. Here’s more information about it, [Configuration - Balena Documentation](https://www.balena.io/docs/reference/OS/configuration/#persistentlogging)  
You can toggle persistent logging from the dashboard under the device/fleet configuration menu. Also, you can try downloading the logs to get all the logs available. Hopefully these help, let me know if these solve your problem.

---

<div class="post-metadata">

**Author:** ![mathroc](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mathroc/32/5033_2.png) [@mathroc](https://forums.balena.io/u/mathroc)\
**Post date:** [May 21, 2021, 9:50am UTC](https://forums.balena.io/t/service-logs-retention/319572/5 "2021-05-21T09:50:56Z")

</div>

Hi @vipulgupta2048,

yes, persistent logging is already enabled at the fleet level. I tried downloading the logs but I only ha ve a few minutes of history (it’s even worst than I expected 😆 )

I downloaded the logs a few times, I notice that they are always 999 lines long. Is this the limit I’m hitting ?

---

<div class="post-metadata">

**Author:** ![vipulgupta2048](https://avatars.discourse-cdn.com/v4/letter/v/a183cd/32.png) [@vipulgupta2048](https://forums.balena.io/u/vipulgupta2048)\
**Post date:** [May 21, 2021, 11:26am UTC](https://forums.balena.io/t/service-logs-retention/319572/8 "2021-05-21T11:26:56Z")

</div>

Hello,  
Thanks for reaching back. Here’s some information regarding logs retention that might be helpful context.

- Persistent logging is designed for it be a debugging feature, and not a way to store logs on device permanently.

- If you are dealing with lot of logs over the course of days, then persistent logging might not be a good long term solution as it will wear your storage media incrementally. What you could try is streaming the logs using the supervisor API. Check: [Interacting with the balena Supervisor - Balena Documentation](https://www.balena.io/docs/reference/supervisor/supervisor-api/#journald-logs). You can stream logs using this endpoint to whatever platform you use to store logs reliably over the course of time. For example, Datadog: [IoT fleet monitoring with Datadog and balenaCloud: How small agent containers make a big impact](https://www.balena.io/blog/iot-fleet-monitoring-with-datadog-and-balenacloud-how-small-agent-containers-make-a-big-impact/)

- The persistent logging when enabled stores logs inside the device and makes sure logs persist between reboots. As part of the data partition on the device either on SD card, eMMC, hard-disk, etc. The limit you are hitting here might be the `RuntimeMaxUse=` in `/etc/systemd/journald.conf` which can be much larger than the default. You can increase the limit to potentially increase the logs being stored. Let us know if this works out. We have an issue open already to make this configurable using a variable here [Allow users to configure the retention limit on persistent logs for OS versions where persistent logs are on the data partition · Issue #1310 · balena-os/balena-supervisor · GitHub](https://github.com/balena-os/balena-supervisor/issues/1310)

> SystemMaxUse= and RuntimeMaxUse= control how much disk space the journal may use up at most. SystemKeepFree= and RuntimeKeepFree= control how much disk space systemd-journald shall leave free for other uses. systemd-journald will respect both limits and use the smaller of the two values. From, [journald.conf](https://www.freedesktop.org/software/systemd/man/journald.conf.html)

- The limit is indeed 1000 lines when the log file is downloaded. As that is the number of logs stored in the API, and viewable from the dashboard. The reason is similar as the current solution isn’t meant to be used for long-term, reliable storage of logs. It’s designed to provide the latest logs from the device for direct debugging purposes. We do plan on expanding our logging solution to offer long-term storage and search.

Thanks for bringing this up, let us know if this helps you out or what worked for you. It will go on to help other folks on the forums!

---

<div class="post-metadata">

**Author:** ![mathroc](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mathroc/32/5033_2.png) [@mathroc](https://forums.balena.io/u/mathroc)\
**Post date:** [May 21, 2021, 12:00pm UTC](https://forums.balena.io/t/service-logs-retention/319572/10 "2021-05-21T12:00:01Z")

</div>

ok I understand the situation much better now.

Indeed I’ll switch back off the persistance logs to avoid damagind the sd cards. For now I’ll try to reduce the log output. It’s something I should have done either way

> We do plan on expanding our logging solution to offer long-term storage and search.

that would be amazing ! 🙂

thank you @vipulgupta2048

---

<div class="post-metadata">

**Author:** ![fisehara](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/fisehara/32/6290_2.png) [@fisehara](https://forums.balena.io/u/fisehara)\
**Post date:** [January 28, 2022, 4:56pm UTC](https://forums.balena.io/t/service-logs-retention/319572/12 "2022-01-28T16:56:14Z")

</div>

Hi, just a note to inform you that we now have some documentation about device logs at [Device Logs - Balena Documentation](https://www.balena.io/docs/learn/manage/device-logs/).
