Skip to content

Commit 18293d3

Browse files
authored
Merge pull request #148 from ellemouton/slog
slog: update to use structured logs for hashmail server
2 parents 3a25952 + 71570a0 commit 18293d3

29 files changed

+607
-609
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@ env:
1919

2020
# If you change this value, please change it in the following files as well:
2121
# /Dockerfile
22-
#
23-
# Don't bump this until go 1.19 is out (which should include a fix for
24-
# https://github.com/golang/go/issues/51799). There was a race condition
25-
# introduced with go 1.16.10 that causes the unit tests to fail (could also
26-
# happen in production).
27-
GO_VERSION: 1.22.6
22+
GO_VERSION: 1.23.6
2823

2924
jobs:
3025
########################
@@ -70,7 +65,7 @@ jobs:
7065
fetch-depth: 0
7166

7267
- name: go cache
73-
uses: actions/cache@v1
68+
uses: actions/cache@v4
7469
with:
7570
path: /home/runner/work/go
7671
key: subasta-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}
@@ -107,7 +102,7 @@ jobs:
107102
uses: actions/checkout@v2
108103

109104
- name: go cache
110-
uses: actions/cache@v1
105+
uses: actions/cache@v4
111106
with:
112107
path: /home/runner/work/go
113108
key: subasta-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}

.golangci.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
run:
22
# timeout for analysis
3-
deadline: 4m
3+
timeout: 4m
44

55
# Linting uses a lot of memory. Keep it under control by only running a single
66
# worker.
77
concurrency: 1
88

99
linters-settings:
10-
govet:
11-
# Don't report about shadowed variables
12-
check-shadowing: false
1310
gofmt:
1411
# simplify code: gofmt with `-s` option, true by default
1512
simplify: true
@@ -20,15 +17,14 @@ linters:
2017
# the latest linter includes many sub-linters which do not pass the codebase.
2118
enable:
2219
- bodyclose
20+
- copyloopvar
2321
- dupl
2422
- errcheck
25-
- exportloopref
2623
- goconst
2724
- gocritic
2825
- gocyclo
2926
- gofmt
3027
- goimports
31-
- golint
3228
- gosimple
3329
- govet
3430
- ineffassign

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.22.6-alpine as builder
1+
FROM golang:1.23.6-alpine as builder
22

33
# Force Go to use the cgo based DNS resolver. This is required to ensure DNS
44
# queries required to connect to linked containers succeed.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ build:
5858

5959
install:
6060
@$(call print, "Installing aperture.")
61-
$(GOINSTALL) $(PKG)/cmd/aperture
61+
$(GOINSTALL) -tags="${tags}" $(PKG)/cmd/aperture
6262

6363
docker-tools:
6464
@$(call print, "Building tools docker image.")

aperture.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"sync"
1717
"time"
1818

19+
"github.com/goccy/go-yaml"
1920
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
2021
gateway "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
2122
flags "github.com/jessevdk/go-flags"
@@ -42,7 +43,6 @@ import (
4243
"google.golang.org/grpc/credentials/insecure"
4344
"google.golang.org/grpc/keepalive"
4445
"google.golang.org/protobuf/encoding/protojson"
45-
"gopkg.in/yaml.v2"
4646
)
4747

4848
const (
@@ -202,7 +202,7 @@ func (a *Aperture) Start(errChan chan error) error {
202202

203203
// Enable http profiling and validate profile port number if requested.
204204
if a.cfg.Profile != 0 {
205-
if a.cfg.Profile < 1024 || a.cfg.Profile > 65535 {
205+
if a.cfg.Profile < 1024 {
206206
return fmt.Errorf("the profile port must be between " +
207207
"1024 and 65535")
208208
}
@@ -619,7 +619,10 @@ func setupLogging(cfg *Config, interceptor signal.Interceptor) error {
619619
}
620620

621621
// Now initialize the logger and set the log level.
622-
SetupLoggers(logWriter, interceptor)
622+
sugLogMgr := build.NewSubLoggerManager(
623+
build.NewDefaultLogHandlers(cfg.Logging, logWriter)...,
624+
)
625+
SetupLoggers(sugLogMgr, interceptor)
623626

624627
// Use our default data dir unless a base dir is set.
625628
logFile := filepath.Join(apertureDataDir, defaultLogFilename)
@@ -628,12 +631,13 @@ func setupLogging(cfg *Config, interceptor signal.Interceptor) error {
628631
}
629632

630633
err := logWriter.InitLogRotator(
631-
logFile, defaultMaxLogFileSize, defaultMaxLogFiles,
634+
cfg.Logging.File, logFile,
632635
)
633636
if err != nil {
634637
return err
635638
}
636-
return build.ParseAndSetDebugLevels(cfg.DebugLevel, logWriter)
639+
640+
return build.ParseAndSetDebugLevels(cfg.DebugLevel, sugLogMgr)
637641
}
638642

639643
// getTLSConfig returns a TLS configuration for either a self-signed certificate

aperturedb/log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package aperturedb
22

33
import (
4-
"github.com/btcsuite/btclog"
4+
"github.com/btcsuite/btclog/v2"
55
)
66

77
// Subsystem defines the logging code for this subsystem.

auth/log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package auth
22

33
import (
4-
"github.com/btcsuite/btclog"
4+
"github.com/btcsuite/btclog/v2"
55
"github.com/lightningnetwork/lnd/build"
66
)
77

challenger/log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package challenger
22

33
import (
4-
"github.com/btcsuite/btclog"
4+
"github.com/btcsuite/btclog/v2"
55
"github.com/lightningnetwork/lnd/build"
66
)
77

config.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/btcsuite/btcd/btcutil"
1010
"github.com/lightninglabs/aperture/aperturedb"
1111
"github.com/lightninglabs/aperture/proxy"
12+
"github.com/lightningnetwork/lnd/build"
1213
)
1314

1415
var (
@@ -18,8 +19,6 @@ var (
1819
defaultTLSCertFilename = "tls.cert"
1920
defaultLogLevel = "info"
2021
defaultLogFilename = "aperture.log"
21-
defaultMaxLogFiles = 3
22-
defaultMaxLogFileSize = 10
2322
defaultInvoiceBatchSize = 100000
2423

2524
defaultSqliteDatabaseFileName = "aperture.db"
@@ -224,6 +223,9 @@ type Config struct {
224223
// InvoiceBatchSize is the number of invoices to fetch in a single
225224
// request.
226225
InvoiceBatchSize int `long:"invoicebatchsize" description:"The number of invoices to fetch in a single request."`
226+
227+
// Logging controls various aspects of aperture logging.
228+
Logging *build.LogConfig `group:"logging" namespace:"logging"`
227229
}
228230

229231
func (c *Config) validate() error {
@@ -244,7 +246,7 @@ func (c *Config) validate() error {
244246
return nil
245247
}
246248

247-
// DefaultConfig returns the default configuration for a sqlite backend.
249+
// DefaultSqliteConfig returns the default configuration for a sqlite backend.
248250
func DefaultSqliteConfig() *aperturedb.SqliteConfig {
249251
return &aperturedb.SqliteConfig{
250252
SkipMigrations: false,
@@ -267,5 +269,6 @@ func NewConfig() *Config {
267269
ReadTimeout: defaultReadTimeout,
268270
WriteTimeout: defaultWriteTimeout,
269271
InvoiceBatchSize: defaultInvoiceBatchSize,
272+
Logging: build.DefaultLogConfig(),
270273
}
271274
}

go.mod

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
module github.com/lightninglabs/aperture
22

3-
go 1.22.6
4-
5-
toolchain go1.22.7
3+
go 1.23.6
64

75
require (
8-
github.com/btcsuite/btcd v0.24.3-0.20240921052913-67b8efd3ba53
6+
github.com/btcsuite/btcd v0.24.3-0.20241210095828-e646d437e95b
97
github.com/btcsuite/btcd/btcec/v2 v2.3.4
108
github.com/btcsuite/btcd/btcutil v1.1.5
119
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0
12-
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
13-
github.com/btcsuite/btcwallet/wtxmgr v1.5.3
10+
github.com/btcsuite/btclog/v2 v2.0.1-0.20250110154127-3ae4bf1cb318
11+
github.com/btcsuite/btcwallet/wtxmgr v1.5.4
1412
github.com/fortytw2/leaktest v1.3.0
13+
github.com/goccy/go-yaml v1.15.23
1514
github.com/golang-migrate/migrate/v4 v4.17.0
1615
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
1716
github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.0
@@ -21,12 +20,12 @@ require (
2120
github.com/lib/pq v1.10.9
2221
github.com/lightninglabs/lightning-node-connect v0.2.5-alpha
2322
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2
24-
github.com/lightninglabs/lndclient v0.18.4-0
25-
github.com/lightningnetwork/lnd v0.18.3-beta.rc3.0.20241011124628-ca3bde901eb8
23+
github.com/lightninglabs/lndclient v0.19.0-2
24+
github.com/lightningnetwork/lnd v0.18.0-beta.rc4.0.20250304192711-9feb761b4ec4
2625
github.com/lightningnetwork/lnd/cert v1.2.2
2726
github.com/lightningnetwork/lnd/clock v1.1.1
28-
github.com/lightningnetwork/lnd/tlv v1.2.6
29-
github.com/lightningnetwork/lnd/tor v1.1.2
27+
github.com/lightningnetwork/lnd/tlv v1.3.0
28+
github.com/lightningnetwork/lnd/tor v1.1.4
3029
github.com/mwitkow/grpc-proxy v0.0.0-20230212185441-f345521cb9c9
3130
github.com/ory/dockertest/v3 v3.10.0
3231
github.com/prometheus/client_golang v1.11.1
@@ -40,7 +39,6 @@ require (
4039
google.golang.org/protobuf v1.33.0
4140
gopkg.in/macaroon-bakery.v2 v2.1.0
4241
gopkg.in/macaroon.v2 v2.1.0
43-
gopkg.in/yaml.v2 v2.4.0
4442
modernc.org/sqlite v1.29.10
4543
)
4644

@@ -56,11 +54,12 @@ require (
5654
github.com/aead/siphash v1.0.1 // indirect
5755
github.com/beorn7/perks v1.0.1 // indirect
5856
github.com/btcsuite/btcd/btcutil/psbt v1.1.8 // indirect
59-
github.com/btcsuite/btcwallet v0.16.10-0.20240809133323-7d3434c65ae2 // indirect
60-
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.4 // indirect
61-
github.com/btcsuite/btcwallet/wallet/txrules v1.2.1 // indirect
62-
github.com/btcsuite/btcwallet/wallet/txsizes v1.2.4 // indirect
63-
github.com/btcsuite/btcwallet/walletdb v1.4.2 // indirect
57+
github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c // indirect
58+
github.com/btcsuite/btcwallet v0.16.10-0.20241127094224-93c858b2ad63 // indirect
59+
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.5 // indirect
60+
github.com/btcsuite/btcwallet/wallet/txrules v1.2.2 // indirect
61+
github.com/btcsuite/btcwallet/wallet/txsizes v1.2.5 // indirect
62+
github.com/btcsuite/btcwallet/walletdb v1.4.4 // indirect
6463
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd // indirect
6564
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 // indirect
6665
github.com/btcsuite/winsvc v1.0.0 // indirect
@@ -120,11 +119,11 @@ require (
120119
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd // indirect
121120
github.com/lightninglabs/neutrino/cache v1.1.2 // indirect
122121
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb // indirect
123-
github.com/lightningnetwork/lnd/fn v1.2.1 // indirect
124-
github.com/lightningnetwork/lnd/healthcheck v1.2.5 // indirect
125-
github.com/lightningnetwork/lnd/kvdb v1.4.10 // indirect
122+
github.com/lightningnetwork/lnd/fn/v2 v2.0.8 // indirect
123+
github.com/lightningnetwork/lnd/healthcheck v1.2.6 // indirect
124+
github.com/lightningnetwork/lnd/kvdb v1.4.12 // indirect
126125
github.com/lightningnetwork/lnd/queue v1.1.1 // indirect
127-
github.com/lightningnetwork/lnd/sqldb v1.0.4 // indirect
126+
github.com/lightningnetwork/lnd/sqldb v1.0.7 // indirect
128127
github.com/lightningnetwork/lnd/ticker v1.1.1 // indirect
129128
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796 // indirect
130129
github.com/mattn/go-isatty v0.0.20 // indirect
@@ -160,7 +159,7 @@ require (
160159
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
161160
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
162161
gitlab.com/yawning/bsaes.git v0.0.0-20190805113838-0a714cd429ec // indirect
163-
go.etcd.io/bbolt v1.3.7 // indirect
162+
go.etcd.io/bbolt v1.3.11 // indirect
164163
go.etcd.io/etcd/api/v3 v3.5.7 // indirect
165164
go.etcd.io/etcd/client/pkg/v3 v3.5.7 // indirect
166165
go.etcd.io/etcd/client/v2 v2.305.7 // indirect
@@ -189,6 +188,7 @@ require (
189188
google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 // indirect
190189
gopkg.in/errgo.v1 v1.0.1 // indirect
191190
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
191+
gopkg.in/yaml.v2 v2.4.0 // indirect
192192
gopkg.in/yaml.v3 v3.0.1 // indirect
193193
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
194194
modernc.org/libc v1.49.3 // indirect

0 commit comments

Comments
 (0)