Skip to content

Commit ea9c2a4

Browse files
committed
Update readme and examples
1 parent 1b0f2f1 commit ea9c2a4

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

README.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# Deno Structured Logging (currently unstable)
22

3+
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/raw.githubusercontent.com/Yamboy1/deno-structured-logging/master/mod.ts)
4+
[![deno.land](https://img.shields.io/badge/deno.land-0.3.0-blue)](https://deno.land/x/deno_structured_logging@0.3.0)
5+
36
A better logger for deno, with support for structured logging.
47

58
## Simple Example
69
```ts
7-
import { createLogger } from "https://deno.land/x/deno_structured_logging/mod.ts";
10+
// Copyright 2020 Yamboy1. All rights reserved. MIT license.
11+
12+
import { createLogger, consoleSink } from "https://deno.land/x/deno_structured_logging/mod.ts";
813

9-
const logger = createLogger();
14+
const logger = createLogger().addSink(consoleSink());
1015

1116
logger.debug("Debug");
1217
logger.info("Info");
@@ -18,13 +23,24 @@ logger.critical("Critical");
1823

1924
## More complex example
2025
```ts
21-
import { createLogger, LogLevel } from "https://deno.land/x/deno_structured_logging/mod.ts";
22-
import { consoleSink, fileSink } from "https://deno.land/x/deno_structured_logging/sinks/mod.ts"
26+
import { green } from "https://deno.land/std@0.51.0/fmt/colors.ts";
27+
import {
28+
createLogger,
29+
LogLevel,
30+
consoleSink,
31+
fileSink,
32+
jsonFormat,
33+
textFormat,
34+
} from "https://deno.lan/x/deno_structured_logging/mod.ts";
2335

2436
const logger = createLogger({
2537
minimumLevel: LogLevel.INFO,
26-
sinks: [consoleSink(), fileSink("test.log")],
27-
});
38+
outputFormat: textFormat, // You can customise the default output format
39+
})
40+
.addSink(consoleSink({
41+
colorOptions: { info: green } // You can customise the log level colors
42+
}))
43+
.addSink(fileSink("log.ndjson"), jsonFormat); // You can set a custom format per sink
2844

2945
logger.debug("Debug"); // Ignored due to the minimumLevel
3046
logger.info("This is {type} logging in {program}", "Structured", "Deno");
@@ -34,7 +50,6 @@ const num = 1;
3450
const array = ["a", "b", "c"];
3551

3652
logger.warn("Numbers work: {number} as well as arrays: {arr}", num, array);
37-
3853
```
3954
![Complex Example](./assets/complex.png)
4055

@@ -44,7 +59,7 @@ DSL uses it's own form of string formatting, similar to Serilog in C#. The synta
4459
```ts
4560
logger.info("Hello {name}, this is another {variable}", "First", 2);
4661
```
47-
where `"First"` and `2` are substituted into `{name}` and `{variable}` respectively. With the default console sink, the names don't really matter however they help readability of the format and with more complex sinks, for example a JSON sink, they could be used as property names.
62+
where `"First"` and `2` are substituted into `{name}` and `{variable}` respectively. With the default console sink, the names don't really matter however they help readability of the format and with more complex formats, for example a JSON format, they could be used as property names.
4863

4964
## Available sinks
5065

assets/complex.png

34.2 KB
Loading

assets/simple.png

2.59 KB
Loading

examples/complex.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import {
1212

1313
const logger = createLogger({
1414
minimumLevel: LogLevel.INFO,
15-
outputFormat: textFormat, // A custom output format
15+
outputFormat: textFormat, // You can customise the default output format
1616
})
1717
.addSink(consoleSink({
1818
colorOptions: { info: green } // You can customise the log level colors
1919
}))
20-
.addSink(fileSink("file.ndjson"), jsonFormat); // You can set a custom format per sink
20+
.addSink(fileSink("log.ndjson"), jsonFormat); // You can set a custom format per sink
2121

2222
logger.debug("Debug"); // Ignored due to the minimumLevel
2323
logger.info("This is {type} logging in {program}", "Structured", "Deno");
@@ -26,6 +26,4 @@ logger.info("This is {type} logging in {program}", "Structured", "Deno");
2626
const num = 1;
2727
const array = ["a", "b", "c"];
2828

29-
logger.warn("Numbers work: {number} as well as arrays: {arr}", num, array);
30-
31-
logger.info("Object: {object}", () => {})
29+
logger.warn("Numbers work: {number} as well as arrays: {arr}", num, array);

0 commit comments

Comments
 (0)