# August 19, 2024

## Things That I Discovered

### 1. Logging in Caddy Server

* It's been a long since I've run [Caddy Server](https://caddyserver.com/), but hardly used any logging, thought of exploring logs which is easy to setup.
* **Logging in Caddyfile**:

  ```
  example.domain.com {
      reverse_proxy localhost:8080
      log {
          output file /var/log/caddy/example.domain.com-access.log
      }
  }
  ```
* **Reference**: [Log Caddyfile Directive - Caddy Server Documentation](https://caddyserver.com/docs/caddyfile/directives/log)
* To avoid repeating the same log block again, and we can use snippets instead.
* **Logging using Snippets in Caddyfile**:

  ```
  (logging) {
      log {
          output file /var/log/{args[0]}-access.log
      }
  }
  example.domain.com {
      reverse_proxy localhost:8080
      import logging example.domain.com
  }
  ```
* **Reference**: [Snippets Caddyfile Directive - Caddy Server Documentation](https://caddyserver.com/docs/caddyfile/concepts#snippets)

### 2. Getting Started with Grafana Loki & Promtail

* Today I explored [Grafana Loki](https://grafana.com/docs/loki/latest/) and [Promtail](https://grafana.com/docs/loki/latest/send-data/promtail/) as part of my effort to streamline log access from my remote servers.
* **Grafana Loki**: A horizontally scalable, highly available, multi-tenant log aggregation system inspired by Prometheus.
* **Promtail**: An agent that ships the contents of local logs to a private Loki instance, scraping logs and labeling them for efficient querying.
* This setup will significantly improve my ability to monitor and analyze logs from various servers in a centralized and organized manner.
