Moonlogs Documentation
website·Indexed 30 days ago
https://moonlogs.pages.dev/A specialized logging solution focused on capturing business events. Moonlogs features a built-in web interface, supports various DB adapters for data storage, and provides SDKs for TypeScript and Ruby on Rails.
What's inside Moonlogs
- Moonlogs is a specialized logging solution focused on capturing business-event logs, such as user interactions, transactions, and custom application events. It is designed to provide transparency into complex business processes and is intended to complement (not replace) traditional knowledge bases, system logging, or Application Performance Monitoring (APM) tools. It includes a built-in web interface for searching and analyzing events.
Use MongoDB for high-performance and scalable workloads
MongoDB is recommended for the following scenarios:
- High loads (hundreds of thousands to millions of requests per minute).
- Strict latency requirements (average write response times of 5-15ms).
- Requirement to horizontally scale the database across one or multiple servers.
- High spikes in requests that significantly exceed average load (e.g., mass mailings, notifications, or SMS logging).
Get started with Moonlogs
To start submitting records (events) to Moonlogs, follow these four basic steps:
- Create an API token for authentication.
- Install a supported SDK (Ruby on Rails or Typescript) or use the REST API directly.
- Create domain schemas to act as containers for your records.
- Send records to the created schemas.
Use SQLite for low to moderate workloads
SQLite is the default adapter and is recommended for the following scenarios:
- Low to moderate loads (0 to tens of thousands of requests per minute).
- Average write response times of 60-90ms are acceptable.
- No requirement for horizontal scaling across multiple servers.
- Fast-paced logs with short retention periods (a few days).
- No expected burst spikes reaching hundreds of thousands of requests per minute.
Organize event schemas by business domains
To facilitate efficient event retrieval and better categorization, create separate event schemas based on specific business domain areas. This ensures that events within each domain are recorded independently.Create a Moonlogs API token
API tokens are required to authenticate requests to the Moonlogs API. To create one:
- Log into the Moonlogs Web interface.
- Navigate to the
API tokentab on the left sidebar. - Click the plus (+) icon next to the
API tokensheader. - Enter a name for the token and click
Create. - Copy the token immediately; it will not be displayed again.
Install Moonlogs using Docker Compose
Deploy Moonlogs using Docker Compose. This method requires Docker and Docker Compose to be installed. The configuration maps port 4200 and creates persistent volumes for configuration and data. After starting the container, access the UI at http://localhost:4200 to create the initial administrator account.version: '3' services: moonlogs: image: pijng/moonlogs restart: always ports: - "4200:4200" volumes: - moonlogs-config:/etc/moonlogs - moonlogs-data:/var/lib/moonlogs command: --port=4200 volumes: moonlogs-config: moonlogs-data:# Build and run the Docker containers in detached mode docker-compose up -dChoose a database adapter for Moonlogs
Moonlogs does not store data internally; it uses database adapters for persistent storage. The choice of adapter depends on your load requirements, latency needs, and scaling strategy. Moonlogs currently supports two adapters: SQLite (default) and MongoDB.Install Moonlogs using the APT Repository
Install Moonlogs on Linux systems by adding the official APT repository. Once installed, Moonlogs runs as a systemd service. After installation, access the UI at http://localhost:4200 to create the initial administrator account.# Add APT Repository sudo add-apt-repository "deb [trusted=yes] https://apt.fury.io/pijng/ /" sudo apt-get update # Install moonlogs package apt-get install moonlogs # Check the status of the service service moonlogs statusConfigure Moonlogs using config.yaml
Moonlogs can be configured using aconfig.yamlfile located by default at/etc/moonlogs/config.yaml. After modifying this file, the service must be restarted for changes to take effect.port: 4200 db_adapter: mongodb db_path: 'mongodb://127.0.0.1:27017' async_record_creation: false read_timeout: 1s write_timeout: 15sservice moonlogs restartMoonlogs configuration options reference
Moonlogs uses the following configuration options. If a value is unspecified, the default is used.port: 4200 # int: Port to listen for incoming connections db_adapter: sqlite # sqlite | mongodb: Database driver to use db_path: /var/lib/moonlogs/database.sqlite # string: Absolute path for SQLite or connection URL for MongoDB read_timeout: 5s # duration: Max duration to wait for reading data from request write_timeout: 1s # duration: Max duration to wait for writing data to client (also the Web UI response deadline) async_record_creation: false # bool: Whether to create records asynchronouslyEnable asynchronous record creation
Set
async_record_creationtotrueto perform record creation operations asynchronously. This improves performance and prevents blocking code execution when sending logs if the client cannot handle async requests.Important: Asynchronous creation does not guarantee that logs will be stored in the order they were sent. To maintain consistent log ordering, it is highly recommended to provide a
created_atparameter for your logs on the client side.