logtea/lib.rs
1/*!
2# logtea
3This is a generic log file Fill Ingredient crate for use with `rettle` ETL. This crate uses [nom](https://docs.rs/nom/) as the parser library to allow any project to define how it wants to parse logs by supplying a custom built parser.
4
5## Data Structures
6- FillLogArg: Ingredient params for FillLogTea
7- FillLogTea: Wrapper to simplifiy the creation of the Fill Ingredient to be used in the rettle Pot.
8
9## Example
10```ignore
11#[derive(Default, Clone, Debug)]
12struct LogTea {
13 log_type: String,
14 datetime: String,
15 msg: String,
16}
17
18impl Tea for LogTea {
19 fn as_any(&self) -> &dyn Any {
20 self
21 }
22}
23
24// Custom parser setup.
25fn log_type(input: &str) -> IResult<&str, &str> {
26 delimited(char('['), is_not("]"), char(']'))(input)
27}
28
29fn datetime(input: &str) -> IResult<&str, &str> {
30 take(19u8)(input)
31}
32
33fn msg(input: &str) -> IResult<&str, &str> {
34 not_line_ending(input)
35}
36
37fn parse_log(input: &str) -> IResult<&str, LogTea> {
38 // Parse log attributes.
39 let (input, log_type) = log_type(input)?;
40 let (input, _) = tag(" - ")(input)?;
41 let (input, datetime) = datetime(input)?;
42 let (input, _) = space1(input)?;
43 let (input, msg) = msg(input)?;
44
45 // Convert &str to String
46 let log_type = String::from(log_type);
47 let datetime = String::from(datetime);
48 let msg = String::from(msg);
49 Ok((input, LogTea { log_type, datetime, msg }))
50}
51
52fn main() {
53 let test_fill_logarg = FillLogArg::new("fixtures/log.LOG", 50, parse_log);
54
55 let brewery = Brewery::new(4, Instant::now());
56 let fill_logtea = FillLogTea::new::<LogTea>("log_tea_source", "log_fixture", test_fill_logarg);
57
58 let new_pot = Pot::new()
59 .add_source(fill_logtea);
60
61 // Steep/Pour operations of choice
62
63 new_pot.brew(&brewery);
64}
65```
66*/
67
68pub mod fill;
69
70// Re-exports
71pub use self::fill::{FillLogArg, FillLogTea};