mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
* implements futures functions and GRPC functions on new branch * lint and test fixes * Fix uneven split pnl. Adds collateral weight test. docs. New clear func * Test protection if someone has zero collateral * Uses string instead of double for accuracy * Fixes old code panic * context, match, docs * Addresses Shazniterinos, var names, expanded tests * Returns subaccount name, provides USD values when offlinecalc * Fixes oopsie * Fixes cool bug which allowed made up subaccount results * Subaccount override on FTX, subaccount results for collateral * Strenghten collateral account info checks. Improve FTX test * English is my first language * Fixes oopsies * Fixes for unrealised PNL & collateral rendering * Fixes lint and tests * Shaznit fixes * Secret Shaznit * Updates account information across wrappers to include more fields * Updates online collateral calculations. Updates RPC data * Accurately calculates collateral offline and online minus testing * Tests and lint chocolate * Simplifies accountinfo results * Fixes shaznits * Adds new func * Increases collateral accuracy again again again x 200 * Increases accuracy of collateral rendering * Fixes minor merge/test issues * Linterino * Fixes ws test. Improves collateral calculations and rendering * Make it prettier * Removes the lock I put on 👀 * Adds `additional_collateral_used` field, renders orig currency * Fixes unrelated test * Fix test * Correctly calculate spot margin borrow collateral * Address fun lint surprise See https://github.com/golangci/golangci-lint/issues/741#issuecomment-1017014331 * Strange lint fixing x2 * Continued lint journey * Nolint the nolint to not lint the lint * Adds two new fields to response * More linting issues arising * fIX3s_c4s|NG * Fixes command flags' incorrect numbering * FairMarket = Won
93 lines
2.4 KiB
Go
93 lines
2.4 KiB
Go
package log
|
|
|
|
import (
|
|
"io"
|
|
"sync"
|
|
)
|
|
|
|
const (
|
|
timestampFormat = " 02/01/2006 15:04:05 "
|
|
spacer = " | "
|
|
// DefaultMaxFileSize for logger rotation file
|
|
DefaultMaxFileSize int64 = 100
|
|
|
|
defaultCapacityForSliceOfBytes = 100
|
|
)
|
|
|
|
var (
|
|
logger = Logger{}
|
|
// FileLoggingConfiguredCorrectly flag set during config check if file logging meets requirements
|
|
FileLoggingConfiguredCorrectly bool
|
|
// GlobalLogConfig holds global configuration options for logger
|
|
GlobalLogConfig = &Config{}
|
|
// GlobalLogFile hold global configuration options for file logger
|
|
GlobalLogFile = &Rotate{}
|
|
|
|
eventPool = &sync.Pool{
|
|
New: func() interface{} {
|
|
sliceOBytes := make([]byte, 0, defaultCapacityForSliceOfBytes)
|
|
return &sliceOBytes
|
|
},
|
|
}
|
|
|
|
// LogPath system path to store log files in
|
|
LogPath string
|
|
|
|
// RWM read/write mutex for logger
|
|
RWM = &sync.RWMutex{}
|
|
)
|
|
|
|
// Config holds configuration settings loaded from bot config
|
|
type Config struct {
|
|
Enabled *bool `json:"enabled"`
|
|
SubLoggerConfig
|
|
LoggerFileConfig *loggerFileConfig `json:"fileSettings,omitempty"`
|
|
AdvancedSettings advancedSettings `json:"advancedSettings"`
|
|
SubLoggers []SubLoggerConfig `json:"subloggers,omitempty"`
|
|
}
|
|
|
|
type advancedSettings struct {
|
|
ShowLogSystemName *bool `json:"showLogSystemName"`
|
|
Spacer string `json:"spacer"`
|
|
TimeStampFormat string `json:"timeStampFormat"`
|
|
Headers headers `json:"headers"`
|
|
}
|
|
|
|
type headers struct {
|
|
Info string `json:"info"`
|
|
Warn string `json:"warn"`
|
|
Debug string `json:"debug"`
|
|
Error string `json:"error"`
|
|
}
|
|
|
|
// SubLoggerConfig holds sub logger configuration settings loaded from bot config
|
|
type SubLoggerConfig struct {
|
|
Name string `json:"name,omitempty"`
|
|
Level string `json:"level"`
|
|
Output string `json:"output"`
|
|
}
|
|
|
|
type loggerFileConfig struct {
|
|
FileName string `json:"filename,omitempty"`
|
|
Rotate *bool `json:"rotate,omitempty"`
|
|
MaxSize int64 `json:"maxsize,omitempty"`
|
|
}
|
|
|
|
// Logger each instance of logger settings
|
|
type Logger struct {
|
|
ShowLogSystemName bool
|
|
Timestamp string
|
|
InfoHeader, ErrorHeader, DebugHeader, WarnHeader string
|
|
Spacer string
|
|
}
|
|
|
|
// Levels flags for each sub logger type
|
|
type Levels struct {
|
|
Info, Debug, Warn, Error bool
|
|
}
|
|
|
|
type multiWriterHolder struct {
|
|
writers []io.Writer
|
|
mu sync.RWMutex
|
|
}
|