# Watch your logs using a Machine + SQLite + (Optional) LiteFS for UI

**URL:** <https://community.fly.io/t/watch-your-logs-using-a-machine-sqlite-optional-litefs-for-ui/18758>\
**Category:** Show & Tell\
**Created:** [March 14, 2024, 8:43pm UTC](https://community.fly.io/t/watch-your-logs-using-a-machine-sqlite-optional-litefs-for-ui/18758 "2024-03-14T20:43:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lubien](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/lubien/32/41919_2.png) [@lubien](https://community.fly.io/u/lubien)\
**Post date:** [March 14, 2024, 8:43pm UTC](https://community.fly.io/t/watch-your-logs-using-a-machine-sqlite-optional-litefs-for-ui/18758/1 "2024-03-14T20:43:17Z")

</div>

![LiteFS Cloud explorer with a query 'select id, app_name, message from app_logs limit 10;'](https://global.discourse-cdn.com/fly1/original/3X/c/4/c4f1d5117d46b687c97615e90d3c568832296250.jpeg)

I’ve created a simple way to store all your organization logs in a SQLite DB.

- Longer than 2 days retention to logs.
- Easy to query, its just SQLite.
- (Optional) Sync to LiteFS Cloud so you can have backups and you can also query them anytime from our UI.
- It only costs a shared-cpu-1x@256MB machine (~$1.94/mo) + Volume Size ($0.15/GB) + (Optional) LiteFS Cluster ($5 for 10GB + $0.5/extra GB).

Elixir source code: [GitHub - lubien/fly-organization-logs-watcher](https://github.com/lubien/fly-organization-logs-watcher)

## How to deploy

1. Create a folder with this fly.toml

Feel free to change `primary_region` and change `ORGANIZATION_SLUG` to the slug you see when navigating `https://fly.io/dashboard/YOUR_SLUG_HERE`

> ⚠ “personal” does not work as slug you need to find the real slug for your personal organization. Tip: go to the billing page on the dashboard and look at the URL

```auto
primary_region = 'gru'

[build]
  image = 'lubien/fly-organization-logs-watcher:v0.1.0'

[env]
  DATABASE_PATH = '/litefs/app_logs.db'
  ORGANIZATION_SLUG = 'lubien'

[[mounts]]
  source = 'db_data'
  destination = '/data'
  initial_size = '1GB'
  auto_extend_size_threshold = 80
  auto_extend_size_increment = '1'

[[vm]]
  size = 'shared-cpu-1x'
  memory_mb = 256

```

1. Dry-launch it

Change the app name to whatever you like.

```auto
fly launch --copy-config --auto-confirm --no-deploy --name lubien-logs

```

1. (Optional) Go to LiteFS Cloud and create a new cluster

 ![new LiteFS cluster UI](https://global.discourse-cdn.com/fly1/original/3X/a/d/ad61eaea952dc8ae6373880ef6273f096c78a8cf.png)

 ![modal with a LiteFS cluster token](https://global.discourse-cdn.com/fly1/original/3X/4/9/49e8ef8717fbb40cef3de5b2c59b640770fd0f19.png)

```sh
fly secrets set LITEFS_CLOUD_TOKEN="FlyV1 fm2_lJPEC..."

```

1. Add a token to be able to watch logs

```auto
fly secrets set FLY_API_TOKEN="$(fly tokens create org YOUR_ORGANIZATION_SLUG)"

```

1. Deploy

```sh
fly deploy --ha=false

```

1. You’re done!

* * *

## How to see my logs?

If you enabled LiteFS cloud, on our dashboard go to your [LiteFS Cloud] → Choose your cluster → Click on the ‘Explore’ button in the ‘app\_logs.db’ row. Run:

```auto
select * from app_logs limit 10;

```

If you chose not to use LiteFS cloud:

```auto
$ fly ssh console
$ sqlite3 /litefs/app_logs.db "select * from app_logs limit 10"

```

---

<div class="post-metadata">

**Author:** ![christopher-fly](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/christopher-fly/32/42799_2.png) [@christopher-fly](https://community.fly.io/u/christopher-fly)\
**Post date:** [March 15, 2024, 10:05am UTC](https://community.fly.io/t/watch-your-logs-using-a-machine-sqlite-optional-litefs-for-ui/18758/2 "2024-03-15T10:05:48Z")

</div>

I wanted to give this app a whirl but then I saw this:

> [@lubien](#):
>
> “personal” does not work as slug

Does that mean it won’t work if I only have a personal org?

---

<div class="post-metadata">

**Author:** ![lubien](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/lubien/32/41919_2.png) [@lubien](https://community.fly.io/u/lubien)\
**Post date:** [March 15, 2024, 11:55am UTC](https://community.fly.io/t/watch-your-logs-using-a-machine-sqlite-optional-litefs-for-ui/18758/3 "2024-03-15T11:55:47Z")

</div>

It works, you just have to use the real slug for your personal org. Mine is “lubien” for example.

I’ve edited the post for clarity
