mirror of
https://github.com/rclone/rclone.git
synced 2024-12-23 07:29:35 +01:00
Audit use of log.Print and change to Debug, Log, or ErrorLog as appropriate
This commit is contained in:
parent
4882b8ba67
commit
67d0375b98
@ -6,7 +6,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -147,7 +146,7 @@ Elapsed time: %10v
|
|||||||
|
|
||||||
// Log outputs the StatsInfo to the log
|
// Log outputs the StatsInfo to the log
|
||||||
func (s *StatsInfo) Log() {
|
func (s *StatsInfo) Log() {
|
||||||
log.Printf("%v\n", s)
|
Log(nil, "%v\n", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bytes updates the stats for bytes bytes
|
// Bytes updates the stats for bytes bytes
|
||||||
|
18
fs/config.go
18
fs/config.go
@ -292,10 +292,10 @@ func configHome() string {
|
|||||||
if home != "" {
|
if home != "" {
|
||||||
return home
|
return home
|
||||||
}
|
}
|
||||||
log.Printf("Couldn't find home directory or read HOME environment variable.")
|
ErrorLog(nil, "Couldn't find home directory or read HOME environment variable.")
|
||||||
log.Printf("Defaulting to storing config in current directory.")
|
ErrorLog(nil, "Defaulting to storing config in current directory.")
|
||||||
log.Printf("Use -config flag to workaround.")
|
ErrorLog(nil, "Use -config flag to workaround.")
|
||||||
log.Printf("Error was: %v", err)
|
ErrorLog(nil, "Error was: %v", err)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,7 +379,7 @@ func LoadConfig() {
|
|||||||
func loadConfigFile() (*goconfig.ConfigFile, error) {
|
func loadConfigFile() (*goconfig.ConfigFile, error) {
|
||||||
b, err := ioutil.ReadFile(ConfigPath)
|
b, err := ioutil.ReadFile(ConfigPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to load config file \"%v\" - using defaults: %v", ConfigPath, err)
|
Log(nil, "Failed to load config file \"%v\" - using defaults: %v", ConfigPath, err)
|
||||||
return goconfig.LoadFromReader(&bytes.Buffer{})
|
return goconfig.LoadFromReader(&bytes.Buffer{})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,7 +450,7 @@ func loadConfigFile() (*goconfig.ConfigFile, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Retry
|
// Retry
|
||||||
log.Println("Couldn't decrypt configuration, most likely wrong password.")
|
ErrorLog(nil, "Couldn't decrypt configuration, most likely wrong password.")
|
||||||
configKey = nil
|
configKey = nil
|
||||||
envpw = ""
|
envpw = ""
|
||||||
}
|
}
|
||||||
@ -509,7 +509,7 @@ func SaveConfig() {
|
|||||||
}
|
}
|
||||||
err = os.Chmod(ConfigPath, 0600)
|
err = os.Chmod(ConfigPath, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to set permissions on config file: %v", err)
|
ErrorLog(nil, "Failed to set permissions on config file: %v", err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -556,7 +556,7 @@ func SaveConfig() {
|
|||||||
|
|
||||||
err = os.Chmod(ConfigPath, 0600)
|
err = os.Chmod(ConfigPath, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to set permissions on config file: %v", err)
|
ErrorLog(nil, "Failed to set permissions on config file: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -712,7 +712,7 @@ func OkRemote(name string) bool {
|
|||||||
ConfigFile.DeleteSection(name)
|
ConfigFile.DeleteSection(name)
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
log.Printf("Bad choice %d", i)
|
ErrorLog(nil, "Bad choice %d", i)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
package fs
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
)
|
)
|
||||||
@ -35,7 +34,7 @@ func (t *LoggedTransport) CancelRequest(req *http.Request) {
|
|||||||
if wrapped, ok := t.wrapped.(interface {
|
if wrapped, ok := t.wrapped.(interface {
|
||||||
CancelRequest(*http.Request)
|
CancelRequest(*http.Request)
|
||||||
}); ok {
|
}); ok {
|
||||||
log.Printf("CANCEL REQUEST %v", req)
|
Debug(nil, "CANCEL REQUEST %v", req)
|
||||||
wrapped.CancelRequest(req)
|
wrapped.CancelRequest(req)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,19 +42,19 @@ func (t *LoggedTransport) CancelRequest(req *http.Request) {
|
|||||||
// RoundTrip implements the RoundTripper interface.
|
// RoundTrip implements the RoundTripper interface.
|
||||||
func (t *LoggedTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
|
func (t *LoggedTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
|
||||||
buf, _ := httputil.DumpRequestOut(req, t.logBody)
|
buf, _ := httputil.DumpRequestOut(req, t.logBody)
|
||||||
log.Println(separatorReq)
|
Debug(nil, "%s", separatorReq)
|
||||||
log.Println("HTTP REQUEST")
|
Debug(nil, "%s", "HTTP REQUEST")
|
||||||
log.Println(string(buf))
|
Debug(nil, "%s", string(buf))
|
||||||
log.Println(separatorReq)
|
Debug(nil, "%s", separatorReq)
|
||||||
resp, err = t.wrapped.RoundTrip(req)
|
resp, err = t.wrapped.RoundTrip(req)
|
||||||
log.Println(separatorResp)
|
Debug(nil, "%s", separatorResp)
|
||||||
log.Println("HTTP RESPONSE")
|
Debug(nil, "%s", "HTTP RESPONSE")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error: %v\n", err)
|
Debug(nil, "Error: %v", err)
|
||||||
} else {
|
} else {
|
||||||
buf, _ = httputil.DumpResponse(resp, t.logBody)
|
buf, _ = httputil.DumpResponse(resp, t.logBody)
|
||||||
log.Println(string(buf))
|
Debug(nil, "%s", string(buf))
|
||||||
}
|
}
|
||||||
log.Println(separatorResp)
|
Debug(nil, "%s", separatorResp)
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -69,7 +68,7 @@ func TestInit(t *testing.T) {
|
|||||||
if RemoteName == "" {
|
if RemoteName == "" {
|
||||||
RemoteName, err = fstest.LocalRemote()
|
RemoteName, err = fstest.LocalRemote()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to create tmp dir: %v", err)
|
t.Fatalf("Failed to create tmp dir: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
subRemoteName, subRemoteLeaf, err = fstest.RandomRemoteName(RemoteName)
|
subRemoteName, subRemoteLeaf, err = fstest.RandomRemoteName(RemoteName)
|
||||||
@ -79,7 +78,7 @@ func TestInit(t *testing.T) {
|
|||||||
|
|
||||||
remote, err = fs.NewFs(subRemoteName)
|
remote, err = fs.NewFs(subRemoteName)
|
||||||
if err == fs.ErrorNotFoundInConfigFile {
|
if err == fs.ErrorNotFoundInConfigFile {
|
||||||
log.Printf("Didn't find %q in config file - skipping tests", RemoteName)
|
t.Logf("Didn't find %q in config file - skipping tests", RemoteName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -668,7 +667,7 @@ func TestFinalise(t *testing.T) {
|
|||||||
// Remove temp directory
|
// Remove temp directory
|
||||||
err := os.Remove(RemoteName)
|
err := os.Remove(RemoteName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to remove %q: %v\n", RemoteName, err)
|
t.Logf("Failed to remove %q: %v\n", RemoteName, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -408,7 +408,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
_, err = f.Seek(0, os.SEEK_END)
|
_, err = f.Seek(0, os.SEEK_END)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to seek log file to end: %v", err)
|
fs.ErrorLog(nil, "Failed to seek log file to end: %v", err)
|
||||||
}
|
}
|
||||||
log.SetOutput(f)
|
log.SetOutput(f)
|
||||||
fs.DebugLogger.SetOutput(f)
|
fs.DebugLogger.SetOutput(f)
|
||||||
@ -423,7 +423,7 @@ func main() {
|
|||||||
|
|
||||||
// Setup CPU profiling if desired
|
// Setup CPU profiling if desired
|
||||||
if *cpuProfile != "" {
|
if *cpuProfile != "" {
|
||||||
log.Printf("Creating CPU profile %q\n", *cpuProfile)
|
fs.Log(nil, "Creating CPU profile %q\n", *cpuProfile)
|
||||||
f, err := os.Create(*cpuProfile)
|
f, err := os.Create(*cpuProfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Stats.Error()
|
fs.Stats.Error()
|
||||||
@ -440,7 +440,7 @@ func main() {
|
|||||||
// Setup memory profiling if desired
|
// Setup memory profiling if desired
|
||||||
if *memProfile != "" {
|
if *memProfile != "" {
|
||||||
defer func() {
|
defer func() {
|
||||||
log.Printf("Saving Memory profile %q\n", *memProfile)
|
fs.Log(nil, "Saving Memory profile %q\n", *memProfile)
|
||||||
f, err := os.Create(*memProfile)
|
f, err := os.Create(*memProfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Stats.Error()
|
fs.Stats.Error()
|
||||||
@ -500,7 +500,7 @@ func main() {
|
|||||||
log.Fatalf("Failed to %s: %v", command.Name, err)
|
log.Fatalf("Failed to %s: %v", command.Name, err)
|
||||||
}
|
}
|
||||||
if !command.NoStats && (!fs.Config.Quiet || fs.Stats.Errored() || *statsInterval > 0) {
|
if !command.NoStats && (!fs.Config.Quiet || fs.Stats.Errored() || *statsInterval > 0) {
|
||||||
fmt.Fprintln(os.Stderr, fs.Stats)
|
fs.Log(nil, "%s", fs.Stats)
|
||||||
}
|
}
|
||||||
if fs.Config.Verbose {
|
if fs.Config.Verbose {
|
||||||
fs.Debug(nil, "Go routines at exit %d\n", runtime.NumGoroutine())
|
fs.Debug(nil, "Go routines at exit %d\n", runtime.NumGoroutine())
|
||||||
|
@ -5,11 +5,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/ncw/rclone/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// redirectStderr to the file passed in
|
// redirectStderr to the file passed in
|
||||||
func redirectStderr(f *os.File) {
|
func redirectStderr(f *os.File) {
|
||||||
log.Printf("Can't redirect stderr to file")
|
fs.ErrorLog(nil, "Can't redirect stderr to file")
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/ncw/rclone/fs"
|
"github.com/ncw/rclone/fs"
|
||||||
"github.com/ncw/rclone/oauthutil"
|
"github.com/ncw/rclone/oauthutil"
|
||||||
yandex "github.com/ncw/rclone/yandex/api"
|
yandex "github.com/ncw/rclone/yandex/api"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -553,8 +554,7 @@ func mkDirExecute(client *yandex.Client, path string) (int, string, error) {
|
|||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// error creating directory
|
// error creating directory
|
||||||
log.Printf("Failed to create folder: %v", err)
|
return statusCode, jsonErrorString, errors.Wrap(err, "failed to create folder")
|
||||||
return statusCode, jsonErrorString, err
|
|
||||||
}
|
}
|
||||||
return 0, "", nil
|
return 0, "", nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user