mirror of
https://github.com/btcsuite/btcd.git
synced 2024-11-19 18:00:11 +01:00
1a69eb0617
This does the minimum work necessary to refactor the CPU miner code into its own package. The idea is that separating this code into its own package will improve its testability and ultimately be useful to other parts of the codebase such as the various tests which currently effectively have their own stripped-down versions of this code. The API will certainly need some additional cleanup and changes to make it more usable outside of the specific circumstances it was originally designed to support (namely the generate RPC), however it is better to do that in future commits in order to keep the changeset as small as possible during this refactor. Overview of the major changes: - Create the new package - Move cpuminer.go -> cpuminer/cpuminer.go - Update mining logging to use the new cpuminer package logger - Rename cpuminerConfig to Config (so it's now cpuminer.Config) - Rename newCPUMiner to New (so it's now cpuminer.New) - Update all references to the cpuminer to use the package - Add a skeleton README.md
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
// Copyright (c) 2016 The btcsuite developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package cpuminer
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
|
|
"github.com/btcsuite/btclog"
|
|
)
|
|
|
|
// log is a logger that is initialized with no output filters. This
|
|
// means the package will not perform any logging by default until the caller
|
|
// requests it.
|
|
var log btclog.Logger
|
|
|
|
// The default amount of logging is none.
|
|
func init() {
|
|
DisableLog()
|
|
}
|
|
|
|
// DisableLog disables all library log output. Logging output is disabled
|
|
// by default until either UseLogger or SetLogWriter are called.
|
|
func DisableLog() {
|
|
log = btclog.Disabled
|
|
}
|
|
|
|
// UseLogger uses a specified Logger to output package logging info.
|
|
// This should be used in preference to SetLogWriter if the caller is also
|
|
// using btclog.
|
|
func UseLogger(logger btclog.Logger) {
|
|
log = logger
|
|
}
|
|
|
|
// SetLogWriter uses a specified io.Writer to output package logging info.
|
|
// This allows a caller to direct package logging output without needing a
|
|
// dependency on seelog. If the caller is also using btclog, UseLogger should
|
|
// be used instead.
|
|
func SetLogWriter(w io.Writer, level string) error {
|
|
if w == nil {
|
|
return errors.New("nil writer")
|
|
}
|
|
|
|
lvl, ok := btclog.LogLevelFromString(level)
|
|
if !ok {
|
|
return errors.New("invalid log level")
|
|
}
|
|
|
|
l, err := btclog.NewLoggerFromWriter(w, lvl)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
UseLogger(l)
|
|
return nil
|
|
}
|