https://github.com/medunes/stashlog
A Rust Library for Logstash format logging.
https://github.com/medunes/stashlog
crate elasticsearch elk elk-stack filebeat kibana libraries library logger logging logs logstash monolog rust rust-lang
Last synced: about 1 month ago
JSON representation
A Rust Library for Logstash format logging.
- Host: GitHub
- URL: https://github.com/medunes/stashlog
- Owner: MedUnes
- License: mit
- Created: 2024-10-04T22:10:33.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-10-05T20:01:40.000Z (about 1 year ago)
- Last Synced: 2025-07-08T00:18:47.066Z (3 months ago)
- Topics: crate, elasticsearch, elk, elk-stack, filebeat, kibana, libraries, library, logger, logging, logs, logstash, monolog, rust, rust-lang
- Language: Rust
- Homepage:
- Size: 42 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rust StashLog
A minimalistic Rust library for [Logstash Event](https://github.com/elastic/logstash/blob/main/logstash-core/src/main/java/org/logstash/Event.java) format logging.
[](https://github.com/MedUnes/stashlog/actions/workflows/publish.yml) [](https://github.com/MedUnes/stashlog/actions/workflows/test.yml)
### Usage
```rust
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](https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-overview.html) configuration which keeps pusing the log changes to a [Logstash](https://www.elastic.co/logstash) server supposedly at ```some-server.logstash.com:5044``````yaml
#/etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /opt/example-app/log-path/logstash.log
fields:
log_type: logstashoutput.logstash:
hosts: ["some-server.logstash.com:5044"]
transport: udp
```#### 3- Collect & View with ```ELK```
* [Logstash](https://www.elastic.co/logstash), if correctly configured, will index the incoming traffic to [Elasticsearch](https://www.elastic.co/elasticsearch)
* You can then use [Kibana](https://www.elastic.co/kibana) to search, filter and visualize your application's logs.
### Credits
* Inspired from [Monolog](https://github.com/Seldaek/monolog/blob/main/src/Monolog/Formatter/LogstashFormatter.php)