|
1 | | -## Usage of my_logger |
| 1 | +# my-logger |
2 | 2 |
|
| 3 | +A logger for Rust applications. Every record is printed to the console and handed to the plugged consumers. The Seq logger is such a consumer: it sends the records to [Seq](https://datalust.co/seq) or to my-logger-server. |
3 | 4 |
|
4 | | -### How to use it in your application |
5 | | - |
6 | | - |
7 | | -Plug it |
| 5 | +## Plug it |
8 | 6 |
|
9 | 7 | ```toml |
10 | 8 | [dependencies] |
11 | | -my-logger = { tag = "max_version", git = "https://github.com/MyJetTools/my-logger.git" } |
| 9 | +my-logger = { tag = "x.x.x", git = "https://github.com/MyJetTools/my-logger.git" } |
12 | 10 | ``` |
13 | 11 |
|
| 12 | +`tag` is the latest of [the tags](https://github.com/MyJetTools/my-logger/tags). |
14 | 13 |
|
15 | | -Put one of these lines at any place in your code |
16 | | -```rust |
17 | | - |
18 | | -// writing information line |
19 | | -my_logger::LOGGER.write_info("process_name", |
20 | | - "message", |
21 | | - LogEventCtx::new() |
22 | | - .add("field1","value1") |
23 | | - .add("field2","value2") |
24 | | - .add("field3","value3") |
25 | | -); |
26 | | - |
27 | | -// writing warning line |
28 | | -my_logger::LOGGER.write_warning("process_name", |
29 | | - "message", |
30 | | - LogEventCtx::new() |
31 | | - .add("field1","value1") |
32 | | - .add("field2","value2") |
33 | | - .add("field3","value3") |
34 | | -); |
| 14 | +Write a record at any place of the code: |
35 | 15 |
|
36 | | -// writing error line |
37 | | -my_logger::LOGGER.write_error("process_name", |
38 | | - "message", |
39 | | - LogEventCtx::new() |
40 | | - .add("field1","value1") |
41 | | - .add("field2","value2") |
42 | | - .add("field3","value3") |
| 16 | +```rust |
| 17 | +use my_logger::LogEventCtx; |
| 18 | + |
| 19 | +my_logger::LOGGER.write_info( |
| 20 | + "process_name", |
| 21 | + "message", |
| 22 | + LogEventCtx::new() |
| 23 | + .add("field1", "value1") |
| 24 | + .add("field2", "value2"), |
43 | 25 | ); |
| 26 | +``` |
44 | 27 |
|
45 | | -// writing fatal error line |
46 | | -my_logger::LOGGER.write_fatal_error("process_name", |
47 | | - "message", |
48 | | - LogEventCtx::new() |
49 | | - .add("field1","value1") |
50 | | - .add("field2","value2") |
51 | | - .add("field3","value3") |
52 | | -); |
| 28 | +## Plug the Seq logger |
53 | 29 |
|
54 | | -// writing fatal debug error line |
55 | | -my_logger::LOGGER.write_fatal_debug("process_name", |
56 | | - "message", |
57 | | - LogEventCtx::new() |
58 | | - .add("field1","value1") |
59 | | - .add("field2","value2") |
60 | | - .add("field3","value3") |
61 | | -); |
| 30 | +To send the records to Seq or to my-logger-server, turn the `my-seq-logger` feature on: |
62 | 31 |
|
| 32 | +```toml |
| 33 | +[dependencies] |
| 34 | +my-logger = { tag = "x.x.x", git = "https://github.com/MyJetTools/my-logger.git", features = [ |
| 35 | + "my-seq-logger", |
| 36 | +] } |
| 37 | +async-trait = "*" |
| 38 | +tokio = { version = "*", features = ["full"] } |
63 | 39 | ``` |
64 | 40 |
|
65 | | -### How to configure |
66 | | -Some context values can be pre-populated by adding the line in the **fn main()** |
| 41 | +Give it the connection string and enable it once, at the start of the application: |
| 42 | + |
67 | 43 | ```rust |
68 | | -#[tokio::main] |
69 | | -async fn main() { |
70 | | - my_logger::LOGGER.populate_params("key","value"); |
71 | | - my_logger::LOGGER.populate_params("key2","value2"); |
| 44 | +use std::sync::Arc; |
| 45 | + |
| 46 | +use my_logger::my_seq_logger::{SeqLogger, SeqSettings}; |
| 47 | + |
| 48 | +pub struct SettingsReader; |
| 49 | + |
| 50 | +#[async_trait::async_trait] |
| 51 | +impl SeqSettings for SettingsReader { |
| 52 | + async fn get_conn_string(&self) -> String { |
| 53 | + "url=http://127.0.0.1:5341;apikey=my-api-key;product=my-product".to_string() |
| 54 | + } |
72 | 55 | } |
73 | | -``` |
74 | | -To configure application name and version method can be used |
75 | | -```rust |
| 56 | + |
76 | 57 | #[tokio::main] |
77 | 58 | async fn main() { |
78 | | - my_logger::LOGGER.populate_app_and_version(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); |
| 59 | + my_logger::LOGGER.populate_app_and_version(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); |
| 60 | + |
| 61 | + SeqLogger::enable_from_connection_string(Arc::new(SettingsReader)).await; |
79 | 62 | } |
80 | 63 | ``` |
81 | 64 |
|
82 | | -# my-seq-logger |
83 | | -Seq Logger |
84 | | - |
85 | | -Please Use wiki to read documentation |
86 | | -https://github.com/MyJetTools/my-seq-logger/wiki |
| 65 | +A service built on service-sdk needs none of this: `ServiceContext::new` makes both calls itself and takes the connection string from `seq_conn_string` of the settings. |
87 | 66 |
|
| 67 | +## Features |
88 | 68 |
|
89 | | -### 0.2.1 |
90 | | -* Settings now are read each fail case |
| 69 | +| Feature | In short | |
| 70 | +|---|---| |
| 71 | +| [Levels, context and macros](docs/writing-logs.md) | `write_info`, `write_warning`, `write_error`, `write_fatal_error` and `write_debug`, each with a context of keys and values; the `write_log_*!` macros. | |
| 72 | +| [Parameters of every record](docs/populated-params.md) | `Application`, `Version`, `EnvInfo` and the ones of your own, added to each record which is sent. | |
| 73 | +| [Console and counters](docs/console-and-counters.md) | Every record is printed to the console and counted by its level. | |
| 74 | +| [Consumers](docs/consumers.md) | A destination of your own for the records. | |
| 75 | +| [Seq logger](docs/seq-logger.md) | Sends the records to Seq or to my-logger-server in the background and writes a panic as a fatal error. | |
| 76 | +| [Connection string](docs/seq-connection-string.md) | `url`, `apikey`, `product`, `timeout` and `queuesize` of the Seq logger, read again before every request. | |
| 77 | +| [Product scope](docs/seq-connection-string.md#product-scope) | `product=my-product` names the product scope of my-logger-server the records go to. | |
0 commit comments