#elasticsearch

stashlog

A minimalistic Rust library for Logstash Event format logging

4 releases

0.0.13 Oct 5, 2024
0.0.12 Oct 5, 2024
0.0.11 Oct 5, 2024
0.0.3 Oct 5, 2024

#530 in Database interfaces

Download history 226/week @ 2024-09-30 110/week @ 2024-10-07

336 downloads per month

MIT license

19KB
154 lines

Rust StashLog

A minimalistic Rust library for Logstash Event format logging.

Release Build

Usage

use medunes::stashlog;
fn main() {
        let logger = stashlog::Logger {
            config: Config {
                version: 1,
                app_name: "my-app".to_string(),
                file_path: "/home/my-app/logs/logstash.log".to_string(),
            },
        };
        logger.info("User Logged in");
        logger.info_extra("User Logged in", &json!({"user_id": user_id}).to_string());
        logger.error_extra("Maximum login attemps reached", &json!({"user_id": user_id}).to_string());

An example of production case scenario

1- Generate with StashLog

Your rust application uses the stashlog package to output logs to a preconfigured file path: for example here /opt/example-app/log-path/logstash.log

2- Push with Filebeat

  • We suppose the app on the server writes logs to /opt/example-app/log-path/logstash.log
  • Here is an example filebeat configuration which keeps pusing the log changes to a Logstash server supposedly at some-server.logstash.com:5044
#/etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /opt/example-app/log-path/logstash.log
  fields:
    log_type: logstash

output.logstash:
  hosts: ["some-server.logstash.com:5044"]
  transport: udp

3- Collect & View with ELK

  • Logstash, if correctly configured, will index the incoming traffic to Elasticsearch
  • You can then use Kibana to search, filter and visualize your application's logs.

ELK Logging Stack

Credits

Dependencies

~3–12MB
~162K SLoC