Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slog: update to use structured logs for hashmail server #148

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ env:

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

jobs:
########################
Expand Down
8 changes: 2 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
run:
# timeout for analysis
deadline: 4m
timeout: 4m

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

linters-settings:
govet:
# Don't report about shadowed variables
check-shadowing: false
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
Expand All @@ -20,15 +17,14 @@ linters:
# the latest linter includes many sub-linters which do not pass the codebase.
enable:
- bodyclose
- copyloopvar
- dupl
- errcheck
- exportloopref
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- golint
- gosimple
- govet
- ineffassign
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22.6-alpine as builder
FROM golang:1.23.6-alpine as builder

# Force Go to use the cgo based DNS resolver. This is required to ensure DNS
# queries required to connect to linked containers succeed.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ build:

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

docker-tools:
@$(call print, "Building tools docker image.")
Expand Down
12 changes: 8 additions & 4 deletions aperture.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (a *Aperture) Start(errChan chan error) error {

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

// Now initialize the logger and set the log level.
SetupLoggers(logWriter, interceptor)
sugLogMgr = build.NewSubLoggerManager(
build.NewDefaultLogHandlers(cfg.Logging, logWriter)...,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SetupLoggers also assigns global sugLogMgr variable. So we assign it twice: here and inside SetupLoggers. Does it make sense to create a local variable here and to pass it to SetupLoggers and let it assign the global variable there?

Also, can we just remove sugLogMgr (global var)? It seems that it is not used anywhere, only assigned to.

SetupLoggers(sugLogMgr, interceptor)

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

err := logWriter.InitLogRotator(
logFile, defaultMaxLogFileSize, defaultMaxLogFiles,
cfg.Logging.File, logFile,
)
if err != nil {
return err
}
return build.ParseAndSetDebugLevels(cfg.DebugLevel, logWriter)

return build.ParseAndSetDebugLevels(cfg.DebugLevel, sugLogMgr)
}

// getTLSConfig returns a TLS configuration for either a self-signed certificate
Expand Down
2 changes: 1 addition & 1 deletion aperturedb/log.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aperturedb

import (
"github.com/btcsuite/btclog"
"github.com/btcsuite/btclog/v2"
)

// Subsystem defines the logging code for this subsystem.
Expand Down
2 changes: 1 addition & 1 deletion auth/log.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package auth

import (
"github.com/btcsuite/btclog"
"github.com/btcsuite/btclog/v2"
"github.com/lightningnetwork/lnd/build"
)

Expand Down
2 changes: 1 addition & 1 deletion challenger/log.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package challenger

import (
"github.com/btcsuite/btclog"
"github.com/btcsuite/btclog/v2"
"github.com/lightningnetwork/lnd/build"
)

Expand Down
9 changes: 6 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/btcsuite/btcd/btcutil"
"github.com/lightninglabs/aperture/aperturedb"
"github.com/lightninglabs/aperture/proxy"
"github.com/lightningnetwork/lnd/build"
)

var (
Expand All @@ -18,8 +19,6 @@ var (
defaultTLSCertFilename = "tls.cert"
defaultLogLevel = "info"
defaultLogFilename = "aperture.log"
defaultMaxLogFiles = 3
defaultMaxLogFileSize = 10
defaultInvoiceBatchSize = 100000

defaultSqliteDatabaseFileName = "aperture.db"
Expand Down Expand Up @@ -224,6 +223,9 @@ type Config struct {
// InvoiceBatchSize is the number of invoices to fetch in a single
// request.
InvoiceBatchSize int `long:"invoicebatchsize" description:"The number of invoices to fetch in a single request."`

// Logging controls various aspects of aperture logging.
Logging *build.LogConfig `group:"logging" namespace:"logging"`
}

func (c *Config) validate() error {
Expand All @@ -244,7 +246,7 @@ func (c *Config) validate() error {
return nil
}

// DefaultConfig returns the default configuration for a sqlite backend.
// DefaultSqliteConfig returns the default configuration for a sqlite backend.
func DefaultSqliteConfig() *aperturedb.SqliteConfig {
return &aperturedb.SqliteConfig{
SkipMigrations: false,
Expand All @@ -267,5 +269,6 @@ func NewConfig() *Config {
ReadTimeout: defaultReadTimeout,
WriteTimeout: defaultWriteTimeout,
InvoiceBatchSize: defaultInvoiceBatchSize,
Logging: build.DefaultLogConfig(),
}
}
39 changes: 19 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
module github.com/lightninglabs/aperture

go 1.22.6

toolchain go1.22.7
go 1.23.6

require (
github.com/btcsuite/btcd v0.24.3-0.20240921052913-67b8efd3ba53
github.com/btcsuite/btcd v0.24.3-0.20241210095828-e646d437e95b
github.com/btcsuite/btcd/btcec/v2 v2.3.4
github.com/btcsuite/btcd/btcutil v1.1.5
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/btcsuite/btcwallet/wtxmgr v1.5.3
github.com/btcsuite/btclog/v2 v2.0.1-0.20250110154127-3ae4bf1cb318
github.com/btcsuite/btcwallet/wtxmgr v1.5.4
github.com/fortytw2/leaktest v1.3.0
github.com/golang-migrate/migrate/v4 v4.17.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
Expand All @@ -21,12 +19,12 @@ require (
github.com/lib/pq v1.10.9
github.com/lightninglabs/lightning-node-connect v0.2.5-alpha
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2
github.com/lightninglabs/lndclient v0.18.4-0
github.com/lightningnetwork/lnd v0.18.3-beta.rc3.0.20241011124628-ca3bde901eb8
github.com/lightninglabs/lndclient v0.19.0-1
github.com/lightningnetwork/lnd v0.18.0-beta.rc4.0.20250225070045-5d3680a6f6d6
github.com/lightningnetwork/lnd/cert v1.2.2
github.com/lightningnetwork/lnd/clock v1.1.1
github.com/lightningnetwork/lnd/tlv v1.2.6
github.com/lightningnetwork/lnd/tor v1.1.2
github.com/lightningnetwork/lnd/tlv v1.3.0
github.com/lightningnetwork/lnd/tor v1.1.4
github.com/mwitkow/grpc-proxy v0.0.0-20230212185441-f345521cb9c9
github.com/ory/dockertest/v3 v3.10.0
github.com/prometheus/client_golang v1.11.1
Expand Down Expand Up @@ -56,11 +54,12 @@ require (
github.com/aead/siphash v1.0.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcutil/psbt v1.1.8 // indirect
github.com/btcsuite/btcwallet v0.16.10-0.20240809133323-7d3434c65ae2 // indirect
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.4 // indirect
github.com/btcsuite/btcwallet/wallet/txrules v1.2.1 // indirect
github.com/btcsuite/btcwallet/wallet/txsizes v1.2.4 // indirect
github.com/btcsuite/btcwallet/walletdb v1.4.2 // indirect
github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c // indirect
github.com/btcsuite/btcwallet v0.16.10-0.20241127094224-93c858b2ad63 // indirect
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.5 // indirect
github.com/btcsuite/btcwallet/wallet/txrules v1.2.2 // indirect
github.com/btcsuite/btcwallet/wallet/txsizes v1.2.5 // indirect
github.com/btcsuite/btcwallet/walletdb v1.4.4 // indirect
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd // indirect
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 // indirect
github.com/btcsuite/winsvc v1.0.0 // indirect
Expand Down Expand Up @@ -120,11 +119,11 @@ require (
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd // indirect
github.com/lightninglabs/neutrino/cache v1.1.2 // indirect
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb // indirect
github.com/lightningnetwork/lnd/fn v1.2.1 // indirect
github.com/lightningnetwork/lnd/healthcheck v1.2.5 // indirect
github.com/lightningnetwork/lnd/kvdb v1.4.10 // indirect
github.com/lightningnetwork/lnd/fn/v2 v2.0.8 // indirect
github.com/lightningnetwork/lnd/healthcheck v1.2.6 // indirect
github.com/lightningnetwork/lnd/kvdb v1.4.12 // indirect
github.com/lightningnetwork/lnd/queue v1.1.1 // indirect
github.com/lightningnetwork/lnd/sqldb v1.0.4 // indirect
github.com/lightningnetwork/lnd/sqldb v1.0.7 // indirect
github.com/lightningnetwork/lnd/ticker v1.1.1 // indirect
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand Down Expand Up @@ -160,7 +159,7 @@ require (
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
gitlab.com/yawning/bsaes.git v0.0.0-20190805113838-0a714cd429ec // indirect
go.etcd.io/bbolt v1.3.7 // indirect
go.etcd.io/bbolt v1.3.11 // indirect
go.etcd.io/etcd/api/v3 v3.5.7 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.7 // indirect
go.etcd.io/etcd/client/v2 v2.305.7 // indirect
Expand Down
Loading
Loading