func initLogRotator(logFile string, logSize int64) {
	logDir, _ := filepath.Split(logFile)
	err := os.MkdirAll(logDir, 0700)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to create log directory: %v\n", err)
		os.Exit(1)
	}
	r, err := rotator.New(logFile, logSize, false, 0)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to create file rotator: %v\n", err)
		os.Exit(1)
	}
	logRotator = r
}
initLogRotator initializes the logging rotater to write logs to logFile and
create roll files in the same directory.  logSize is the size in KiB after
which a log file will be rotated and compressed.

This function must be called before the package-global log rotater variables
are used.
package main
import (
	"fmt"
	"os"
	"path/filepath"
	"decred.org/dcrwallet/v2/chain"
	"decred.org/dcrwallet/v2/internal/loader"
	"decred.org/dcrwallet/v2/internal/rpc/jsonrpc"
	"decred.org/dcrwallet/v2/internal/rpc/rpcserver"
	"decred.org/dcrwallet/v2/internal/vsp"
	"decred.org/dcrwallet/v2/p2p"
	"decred.org/dcrwallet/v2/spv"
	"decred.org/dcrwallet/v2/ticketbuyer"
	"decred.org/dcrwallet/v2/wallet"
	"decred.org/dcrwallet/v2/wallet/udb"
	"github.com/decred/dcrd/connmgr/v3"
	"github.com/decred/slog"
	"github.com/jrick/logrotate/rotator"
)
type logWriter struct{}
func (logWriter) Write(p []byte) (n int, err error) {
	os.Stdout.Write(p)
	if logRotator != nil {
		logRotator.Write(p)
	}
	return len(p), nil
}
var (
	backendLog = slog.NewBackend(logWriter{})
	logRotator *rotator.Rotator
	log        = backendLog.Logger("DCRW")
	loaderLog  = backendLog.Logger("LODR")
	walletLog  = backendLog.Logger("WLLT")
	tkbyLog    = backendLog.Logger("TKBY")
	syncLog    = backendLog.Logger("SYNC")
	grpcLog    = backendLog.Logger("GRPC")
	jsonrpcLog = backendLog.Logger("RPCS")
	cmgrLog    = backendLog.Logger("CMGR")
	vspcLog    = backendLog.Logger("VSPC")
)
func init() {
	loader.UseLogger(loaderLog)
	wallet.UseLogger(walletLog)
	udb.UseLogger(walletLog)
	ticketbuyer.UseLogger(tkbyLog)
	chain.UseLogger(syncLog)
	spv.UseLogger(syncLog)
	p2p.UseLogger(syncLog)
	rpcserver.UseLogger(grpcLog)
	jsonrpc.UseLogger(jsonrpcLog)
	connmgr.UseLogger(cmgrLog)
	vsp.UseLogger(vspcLog)
}
var subsystemLoggers = map[string]slog.Logger{
	"DCRW": log,
	"LODR": loaderLog,
	"WLLT": walletLog,
	"TKBY": tkbyLog,
	"SYNC": syncLog,
	"GRPC": grpcLog,
	"RPCS": jsonrpcLog,
	"CMGR": cmgrLog,
	"VSPC": vspcLog,
}