mirror of
https://github.com/PeernetOfficial/Cmd.git
synced 2026-07-16 18:37:51 +01:00
Update core. Refactor error logging code.
This commit is contained in:
8
API.go
8
API.go
@@ -164,7 +164,7 @@ func apiShutdown(backend *core.Backend) func(w http.ResponseWriter, r *http.Requ
|
||||
if action == 0 {
|
||||
// Later: Initiate shutdown signal to core library and wait for all requests to complete.
|
||||
|
||||
backend.Filters.LogError("apiShutdown", "graceful shutdown via API requested from '%s'\n", r.RemoteAddr)
|
||||
backend.LogError("apiShutdown", "graceful shutdown via API requested from '%s'\n", r.RemoteAddr)
|
||||
|
||||
EncodeJSONFlush(backend, w, r, &apiShutdownStatus{Status: 0})
|
||||
|
||||
@@ -181,7 +181,7 @@ type apiShutdownStatus struct {
|
||||
func EncodeJSONFlush(backend *core.Backend, w http.ResponseWriter, r *http.Request, data interface{}) (err error) {
|
||||
response, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
backend.Filters.LogError("EncodeJSONFlush", "error marshalling data for route '%s': %v\n", r.URL.Path, err)
|
||||
backend.LogError("EncodeJSONFlush", "error marshalling data for route '%s': %v\n", r.URL.Path, err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -211,13 +211,13 @@ func processExitMonitor(backend *core.Backend, watchPID int) {
|
||||
// monitor the process
|
||||
process, err := os.FindProcess(watchPID)
|
||||
if err != nil {
|
||||
backend.Filters.LogError("processExitMonitor", "error finding monitored process ID %d: %v\n", watchPID, err)
|
||||
backend.LogError("processExitMonitor", "error finding monitored process ID %d: %v\n", watchPID, err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = process.Wait()
|
||||
if err == nil {
|
||||
backend.Filters.LogError("processExitMonitor", "graceful shutdown via exit signal from process ID %d\n", watchPID)
|
||||
backend.LogError("processExitMonitor", "graceful shutdown via exit signal from process ID %d\n", watchPID)
|
||||
|
||||
// Later: Initiate shutdown signal to core library and wait for all requests to complete.
|
||||
|
||||
|
||||
@@ -264,7 +264,7 @@ func userCommands(backend *core.Backend, input io.Reader, output io.Writer, term
|
||||
case "log error":
|
||||
fmt.Fprintf(output, "Please choose the target output of error messages:\n0 = Log file (default)\n1 = Command line\n2 = Log file + command line\n3 = None\n")
|
||||
if number, valid, terminate := getUserOptionInt(reader, terminateSignal); valid && number >= 0 && number <= 3 {
|
||||
config.ErrorOutput = number
|
||||
backend.Config.LogTarget = number
|
||||
} else if terminate {
|
||||
return
|
||||
} else {
|
||||
@@ -444,7 +444,7 @@ func userCommands(backend *core.Backend, input io.Reader, output io.Writer, term
|
||||
go blockTransfer(peer, uint64(blockNumber), output)
|
||||
|
||||
case "exit":
|
||||
backend.Filters.LogError("userCommands", "graceful exit via user terminal command\n")
|
||||
backend.LogError("userCommands", "graceful exit via user terminal command\n")
|
||||
os.Exit(core.ExitGraceful)
|
||||
|
||||
case "search file":
|
||||
@@ -642,21 +642,6 @@ func GetPeerlistSorted(backend *core.Backend) (peers []*core.PeerInfo) {
|
||||
return peers
|
||||
}
|
||||
|
||||
// logError handles error messages from core
|
||||
func logError(function, format string, v ...interface{}) {
|
||||
switch config.ErrorOutput {
|
||||
case 0:
|
||||
core.DefaultLogError(function, format, v...)
|
||||
|
||||
case 1:
|
||||
fmt.Printf("["+function+"] "+format, v...)
|
||||
|
||||
case 2:
|
||||
core.DefaultLogError(function, format, v...)
|
||||
fmt.Printf("["+function+"] "+format, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// ---- command-line helper functions ----
|
||||
|
||||
// timeRetryUserInput defines how long the code waits for user input from reader before trying again
|
||||
|
||||
6
Main.go
6
Main.go
@@ -21,10 +21,6 @@ var config struct {
|
||||
// Warning: These settings are currently overwritten (deleted) when the config file is updated by core.
|
||||
// In the future the core package will consider custom config fields.
|
||||
|
||||
// Log settings
|
||||
ErrorOutput int `yaml:"ErrorOutput"` // 0 = Log file (default), 1 = Command line, 2 = Log file + command line, 3 = None
|
||||
DebugAPI bool `yaml:"DebugAPI"` // Enables the debug API which allows profiling. Do not enable in production. Only available if compiled with debug tag.
|
||||
|
||||
// API settings
|
||||
APIListen []string `yaml:"APIListen"` // WebListen is in format IP:Port and declares where the web-interface should listen on. IP can also be ommitted to listen on any.
|
||||
APIUseSSL bool `yaml:"APIUseSSL"` // Enables SSL.
|
||||
@@ -33,6 +29,7 @@ var config struct {
|
||||
APITimeoutRead string `yaml:"APITimeoutRead"` // The maximum duration for reading the entire request, including the body.
|
||||
APITimeoutWrite string `yaml:"APITimeoutWrite"` // The maximum duration before timing out writes of the response. This includes processing time and is therefore the max time any HTTP function may take.
|
||||
APIKey uuid.UUID `yaml:"APIKey"` // API key. Empty UUID 00000000-0000-0000-0000-000000000000 = not used.
|
||||
DebugAPI bool `yaml:"DebugAPI"` // Enables the debug API which allows profiling. Do not enable in production. Only available if compiled with debug tag.
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -57,7 +54,6 @@ func main() {
|
||||
userAgent := appName + "/" + core.Version
|
||||
|
||||
filters := &core.Filters{
|
||||
LogError: logError,
|
||||
DHTSearchStatus: filterSearchStatus,
|
||||
IncomingRequest: filterIncomingRequest,
|
||||
MessageIn: filterMessageIn,
|
||||
|
||||
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module github.com/PeernetOfficial/Cmd
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/PeernetOfficial/core v0.0.0-20220106031128-5c8b8eb94bd7
|
||||
github.com/PeernetOfficial/core v0.0.0-20220112211834-6a5312d83433
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/gorilla/websocket v1.4.3-0.20210424162022-e8629af678b7
|
||||
)
|
||||
|
||||
4
go.sum
4
go.sum
@@ -1,7 +1,7 @@
|
||||
github.com/IncSW/geoip2 v0.1.1 h1:afzzYF7n9JbdcPy8aiBSgBJuXi4mTWXZ3z6V3o6Vg34=
|
||||
github.com/IncSW/geoip2 v0.1.1/go.mod h1:adcasR40vXiUBjtzdaTTKL/6wSf+fgO4M8Gve/XzPUk=
|
||||
github.com/PeernetOfficial/core v0.0.0-20220106031128-5c8b8eb94bd7 h1:Bb6UCVLSriUYZs5UBO6CtjY98IHAlaGquFSppXmSygE=
|
||||
github.com/PeernetOfficial/core v0.0.0-20220106031128-5c8b8eb94bd7/go.mod h1:VNhfwAZqya5JDZTS/ffa8Shof0OmQCx025CQMieGB7o=
|
||||
github.com/PeernetOfficial/core v0.0.0-20220112211834-6a5312d83433 h1:p2PXBpPvIlilShSHGG8rozGFRlhcyQNchcyZj2sph0s=
|
||||
github.com/PeernetOfficial/core v0.0.0-20220112211834-6a5312d83433/go.mod h1:VNhfwAZqya5JDZTS/ffa8Shof0OmQCx025CQMieGB7o=
|
||||
github.com/akrylysov/pogreb v0.10.1 h1:FqlR8VR7uCbJdfUob916tPM+idpKgeESDXOA1K0DK4w=
|
||||
github.com/akrylysov/pogreb v0.10.1/go.mod h1:pNs6QmpQ1UlTJKDezuRWmaqkgUE2TuU0YTWyqJZ7+lI=
|
||||
github.com/enfipy/locker v1.1.0 h1:2zVJ0ky7cS1Vjs0x6OQWFiT2dSEiHrI5/O2KCz1fgGc=
|
||||
|
||||
Reference in New Issue
Block a user