Skip to content

Commit 6223984

Browse files
committed
README: update
1 parent 1bba6e6 commit 6223984

File tree

1 file changed

+60
-19
lines changed

1 file changed

+60
-19
lines changed

README.md

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,79 @@
11
btclog
22
======
33

4-
[![Build Status](http://img.shields.io/travis/btcsuite/btclog.svg)](https://travis-ci.org/btcsuite/btclog)
5-
[![ISC License](http://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org)
6-
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](http://godoc.org/github.com/btcsuite/btclog)
4+
Forked and adapted from https://github.com/btcsuite/btclog.
75

86
Package btclog defines a logger interface and provides a default implementation
97
of a subsystem-aware leveled logger implementing the same interface.
108

119
## Installation
1210

1311
```bash
14-
$ go get github.com/btcsuite/btclog
12+
$ go get github.com/lightninglabs/btclog
1513
```
1614

17-
## GPG Verification Key
15+
## Usage
1816

19-
All official release tags are signed by Conformal so users can ensure the code
20-
has not been tampered with and is coming from the btcsuite developers. To
21-
verify the signature perform the following:
17+
`btclog.NewSLogger` can be used to construct a new `btclog.Logger` type which
18+
can then be used for logging calls. The `NewSLogger` function expects to be
19+
initialised with a type that implements the `btclog.Handler` interface which is
20+
responsible for writing logging records to a backend writer. Callers may provide
21+
their own `Handler` implementations (for example, the standard library `slog`
22+
package provides some handler implementations such as a JSON Handler and a Text
23+
Handler) or else they may use the default one provided with this package:
24+
`DefaultHandler`.
2225

23-
- Download the public key from the Conformal website at
24-
https://opensource.conformal.com/GIT-GPG-KEY-conformal.txt
26+
Example Usage:
2527

26-
- Import the public key into your GPG keyring:
27-
```bash
28-
gpg --import GIT-GPG-KEY-conformal.txt
29-
```
28+
```
29+
// Create a new DefaultHandler that writes to stdout and set the
30+
// logging level to Trace.
31+
handler := btclog.NewDefaultHandler(os.Stdout)
32+
handler.SetLevel(btclog.LevelTrace)
33+
34+
// Use the above handler to construct a new logger.
35+
log := btclog.NewSLogger(handler)
36+
37+
/*
38+
2024-09-18 11:53:03.287 [INF]: An info level log
39+
*/
40+
log.Info("An info level log")
41+
42+
// Create a subsystem logger with no timestamps.
43+
handler = btclog.NewDefaultHandler(os.Stdout, btclog.WithNoTimestamp())
44+
log = btclog.NewSLogger(handler.SubSystem("SUBS"))
45+
46+
/*
47+
[INF] SUBS: An info level log
48+
*/
49+
log.Info("An info level log")
3050
31-
- Verify the release tag with the following command where `TAG_NAME` is a
32-
placeholder for the specific tag:
33-
```bash
34-
git tag -v TAG_NAME
35-
```
51+
// Include log source.
52+
handler = btclog.NewDefaultHandler(
53+
os.Stdout,
54+
btclog.WithCallerFlags(btclog.Lshortfile),
55+
btclog.WithNoTimestamp(),
56+
)
57+
log = btclog.NewSLogger(handler.SubSystem("SUBS"))
58+
59+
/*
60+
[INF] SUBS main.go:36: An info level log
61+
*/
62+
log.Info("An info level log")
63+
64+
// Attach attributes to a context. This will result in log lines
65+
// including these attributes if the context is passed to them. Also
66+
// pass in an attribute at log time.
67+
log = btclog.NewSLogger(btclog.NewDefaultHandler(
68+
os.Stdout, btclog.WithNoTimestamp(),
69+
).SubSystem("SUBS"))
70+
ctx := btclog.WithCtx(context.Background(), "request_id", 5)
71+
72+
/*
73+
[INF] SUBS: A log line with context values request_id=5 another_key=another_value
74+
*/
75+
log.InfoS(ctx, "A log line with context values", "another_key", "another_value")
76+
```
3677

3778
## License
3879

0 commit comments

Comments
 (0)