Files
gocryptotrader/log/loggers.go
Ryan O'Hara-Reid a2381310da GCT: general updates across codebase (#699)
* orderbook: export orderbook nodes for external strategy inspection

* orderbook: Add in methods for locking and unlocking multiple books at the same time e.g. book1.LockWith(book2); defer book1.UnlockWith(book2)

* include waiting functionality for depth change alert

* backtester: add word.

* log: include logger changes to impl with downstream integration

* engine: reduce params for loading exchange

* assort: rm verbose in tests, change wording in ob, expose sync.waitgroup for ext. sync options

* ticker: reduce map look ups and contention when using RW mutex when there are over 80% writes adds find last function to get the latest rate

* engine/syncmanager: add in waitgroup for step over for external package calls

* cleaup

* engine: linter fix

* currency/fx: include all references to fiat currencies to default

* orderbook: Add in fields to Unsafe type for strategies to detect potential out of sync book operations

* syncmanager: changed config variable to display correct time

* ordermanager: Add time when none provided

* currency/manager: update getasset param to get enabled assets for minor optimizations

* ftx: use get all wallet balances for a better accounts breakdown

* orderbook: unlock in reverse order

* bithumb: fixes bug on market buy and sell orders

* bithumb: fix bug for nonce is also time window sensitive

* bithumb: get orders add required parameter

* bithumb: Add asset type to account struct

* currency: improve log output when checking currency and it fails

* bithumb: Add error return on incomplete pair

* ticker:unexport all service related methods

* ticker/currency: fixes

* orderbook: fix comment

* engine: revert variable name in LoadExchange method

* sync_manager: fix panic when enabling disabling manager

* engine: fix naming convention of exported function and comments

* engine: update comment

* orderbook: fix comment for unsafe type
2021-07-29 14:42:28 +10:00

169 lines
4.0 KiB
Go

package log
import (
"fmt"
"log"
)
// Info takes a pointer subLogger struct and string sends to newLogEvent
func Info(sl *SubLogger, data string) {
fields := getFields(sl)
if fields == nil {
return
}
if !fields.info {
return
}
displayError(fields.logger.newLogEvent(data, fields.logger.InfoHeader, fields.name, fields.output))
}
// Infoln takes a pointer subLogger struct and interface sends to newLogEvent
func Infoln(sl *SubLogger, v ...interface{}) {
fields := getFields(sl)
if fields == nil {
return
}
if !fields.info {
return
}
displayError(fields.logger.newLogEvent(fmt.Sprintln(v...), fields.logger.InfoHeader, fields.name, fields.output))
}
// Infof takes a pointer subLogger struct, string & interface formats and sends to Info()
func Infof(sl *SubLogger, data string, v ...interface{}) {
Info(sl, fmt.Sprintf(data, v...))
}
// Debug takes a pointer subLogger struct and string sends to multiwriter
func Debug(sl *SubLogger, data string) {
fields := getFields(sl)
if fields == nil {
return
}
if !fields.debug {
return
}
displayError(fields.logger.newLogEvent(data, fields.logger.DebugHeader, fields.name, fields.output))
}
// Debugln takes a pointer subLogger struct, string and interface sends to newLogEvent
func Debugln(sl *SubLogger, v ...interface{}) {
fields := getFields(sl)
if fields == nil {
return
}
if !fields.debug {
return
}
displayError(fields.logger.newLogEvent(fmt.Sprintln(v...), fields.logger.DebugHeader, fields.name, fields.output))
}
// Debugf takes a pointer subLogger struct, string & interface formats and sends to Info()
func Debugf(sl *SubLogger, data string, v ...interface{}) {
Debug(sl, fmt.Sprintf(data, v...))
}
// Warn takes a pointer subLogger struct & string and sends to newLogEvent()
func Warn(sl *SubLogger, data string) {
fields := getFields(sl)
if fields == nil {
return
}
if !fields.warn {
return
}
displayError(fields.logger.newLogEvent(data, fields.logger.WarnHeader, fields.name, fields.output))
}
// Warnln takes a pointer subLogger struct & interface formats and sends to newLogEvent()
func Warnln(sl *SubLogger, v ...interface{}) {
fields := getFields(sl)
if fields == nil {
return
}
if !fields.warn {
return
}
displayError(fields.logger.newLogEvent(fmt.Sprintln(v...), fields.logger.WarnHeader, fields.name, fields.output))
}
// Warnf takes a pointer subLogger struct, string & interface formats and sends to Warn()
func Warnf(sl *SubLogger, data string, v ...interface{}) {
Warn(sl, fmt.Sprintf(data, v...))
}
// Error takes a pointer subLogger struct & interface formats and sends to newLogEvent()
func Error(sl *SubLogger, data ...interface{}) {
fields := getFields(sl)
if fields == nil {
return
}
if !fields.error {
return
}
displayError(fields.logger.newLogEvent(fmt.Sprint(data...), fields.logger.ErrorHeader, fields.name, fields.output))
}
// Errorln takes a pointer subLogger struct, string & interface formats and sends to newLogEvent()
func Errorln(sl *SubLogger, v ...interface{}) {
fields := getFields(sl)
if fields == nil {
return
}
if !fields.error {
return
}
displayError(fields.logger.newLogEvent(fmt.Sprintln(v...), fields.logger.ErrorHeader, fields.name, fields.output))
}
// Errorf takes a pointer subLogger struct, string & interface formats and sends to Debug()
func Errorf(sl *SubLogger, data string, v ...interface{}) {
Error(sl, fmt.Sprintf(data, v...))
}
func displayError(err error) {
if err != nil {
log.Printf("Logger write error: %v\n", err)
}
}
func enabled() bool {
RWM.Lock()
defer RWM.Unlock()
if GlobalLogConfig == nil || GlobalLogConfig.Enabled == nil {
return false
}
if *GlobalLogConfig.Enabled {
return true
}
return false
}
func getFields(sl *SubLogger) *logFields {
if !enabled() {
return nil
}
if sl == nil {
return nil
}
RWM.RLock()
defer RWM.RUnlock()
return &logFields{
info: sl.Info,
warn: sl.Warn,
debug: sl.Debug,
error: sl.Error,
name: sl.name,
output: sl.output,
logger: *logger,
}
}