mirror of
https://github.com/pikami/cosmium.git
synced 2025-02-08 08:56:01 +00:00
Added setting for LogLevel
This commit is contained in:
parent
c2c9dc03b3
commit
8b8b087aab
@ -78,7 +78,7 @@ To disable SSL and run Cosmium on HTTP instead, you can use the `-DisableTls` fl
|
||||
- **-InitialData**: Path to JSON containing initial state
|
||||
- **-Persist**: Saves data to the given path on application exit (When `-InitialData` argument is not supplied, it will try to load data from path supplied in `-Persist`)
|
||||
- **-Port**: Listen port (default 8081)
|
||||
- **-Debug**: Runs application in debug mode, this provides additional logging
|
||||
- **-LogLevel**: Sets the logging level (one of: debug, info, error, silent) (default info)
|
||||
|
||||
These arguments allow you to configure various aspects of Cosmium's behavior according to your requirements.
|
||||
|
||||
@ -90,7 +90,7 @@ All mentioned arguments can also be set using environment variables:
|
||||
- **COSMIUM_INITIALDATA** for `-InitialData`
|
||||
- **COSMIUM_PERSIST** for `-Persist`
|
||||
- **COSMIUM_PORT** for `-Port`
|
||||
- **COSMIUM_DEBUG** for `-Debug`
|
||||
- **COSMIUM_LOGLEVEL** for `-LogLevel`
|
||||
|
||||
# License
|
||||
|
||||
|
@ -26,7 +26,8 @@ func ParseFlags() ServerConfig {
|
||||
disableAuthentication := flag.Bool("DisableAuth", false, "Disable authentication")
|
||||
disableTls := flag.Bool("DisableTls", false, "Disable TLS, serve over HTTP")
|
||||
persistDataPath := flag.String("Persist", "", "Saves data to given path on application exit")
|
||||
debug := flag.Bool("Debug", false, "Runs application in debug mode, this provides additional logging")
|
||||
logLevel := NewEnumValue("info", []string{"debug", "info", "error", "silent"})
|
||||
flag.Var(logLevel, "LogLevel", fmt.Sprintf("Sets the logging level %s", logLevel.AllowedValuesList()))
|
||||
|
||||
flag.Parse()
|
||||
setFlagsFromEnvironment()
|
||||
@ -41,8 +42,8 @@ func ParseFlags() ServerConfig {
|
||||
config.PersistDataFilePath = *persistDataPath
|
||||
config.DisableAuth = *disableAuthentication
|
||||
config.DisableTls = *disableTls
|
||||
config.Debug = *debug
|
||||
config.AccountKey = *accountKey
|
||||
config.LogLevel = logLevel.value
|
||||
|
||||
config.PopulateCalculatedFields()
|
||||
|
||||
@ -54,7 +55,19 @@ func (c *ServerConfig) PopulateCalculatedFields() {
|
||||
c.DatabaseDomain = c.Host
|
||||
c.DatabaseEndpoint = fmt.Sprintf("https://%s:%d/", c.Host, c.Port)
|
||||
c.ExplorerBaseUrlLocation = ExplorerBaseUrlLocation
|
||||
logger.EnableDebugOutput = c.Debug
|
||||
|
||||
switch c.LogLevel {
|
||||
case "debug":
|
||||
logger.LogLevel = logger.LogLevelDebug
|
||||
case "info":
|
||||
logger.LogLevel = logger.LogLevelInfo
|
||||
case "error":
|
||||
logger.LogLevel = logger.LogLevelError
|
||||
case "silent":
|
||||
logger.LogLevel = logger.LogLevelSilent
|
||||
default:
|
||||
logger.LogLevel = logger.LogLevelInfo
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ServerConfig) ApplyDefaultsToEmptyFields() {
|
||||
|
36
api/config/enumFlag.go
Normal file
36
api/config/enumFlag.go
Normal file
@ -0,0 +1,36 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type EnumValue struct {
|
||||
allowedValues []string
|
||||
value string
|
||||
}
|
||||
|
||||
func (e *EnumValue) String() string {
|
||||
return e.value
|
||||
}
|
||||
|
||||
func (e *EnumValue) Set(v string) error {
|
||||
for _, allowed := range e.allowedValues {
|
||||
if v == allowed {
|
||||
e.value = v
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("invalid value %q, must be one of: %s", v, strings.Join(e.allowedValues, ", "))
|
||||
}
|
||||
|
||||
func NewEnumValue(defaultValue string, allowedValues []string) *EnumValue {
|
||||
return &EnumValue{
|
||||
allowedValues: allowedValues,
|
||||
value: defaultValue,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *EnumValue) AllowedValuesList() string {
|
||||
return fmt.Sprintf("(one of: %s)", strings.Join(e.allowedValues, ", "))
|
||||
}
|
@ -15,6 +15,6 @@ type ServerConfig struct {
|
||||
PersistDataFilePath string `json:"persistDataFilePath"`
|
||||
DisableAuth bool `json:"disableAuth"`
|
||||
DisableTls bool `json:"disableTls"`
|
||||
Debug bool `json:"debug"`
|
||||
LogLevel string `json:"logLevel"`
|
||||
ExplorerBaseUrlLocation string `json:"explorerBaseUrlLocation"`
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ func (h *Handlers) PatchDocument(c *gin.Context) {
|
||||
|
||||
currentDocumentBytes, err := json.Marshal(document)
|
||||
if err != nil {
|
||||
logger.Error("Failed to marshal existing document:", err)
|
||||
logger.ErrorLn("Failed to marshal existing document:", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"message": "Failed to marshal existing document"})
|
||||
return
|
||||
}
|
||||
@ -149,7 +149,7 @@ func (h *Handlers) PatchDocument(c *gin.Context) {
|
||||
var modifiedDocument map[string]interface{}
|
||||
err = json.Unmarshal(modifiedDocumentBytes, &modifiedDocument)
|
||||
if err != nil {
|
||||
logger.Error("Failed to unmarshal modified document:", err)
|
||||
logger.ErrorLn("Failed to unmarshal modified document:", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"message": "Failed to unmarshal modified document"})
|
||||
return
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ func RequestLogger() gin.HandlerFunc {
|
||||
|
||||
bodyStr := readBody(rdr1)
|
||||
if bodyStr != "" {
|
||||
logger.Debug(bodyStr)
|
||||
logger.DebugLn(bodyStr)
|
||||
}
|
||||
|
||||
c.Request.Body = rdr2
|
||||
|
@ -16,7 +16,10 @@ import (
|
||||
func (s *ApiServer) CreateRouter(repository *repositories.DataRepository) {
|
||||
routeHandlers := handlers.NewHandlers(repository, s.config)
|
||||
|
||||
if !s.config.Debug {
|
||||
gin.DefaultWriter = logger.InfoWriter()
|
||||
gin.DefaultErrorWriter = logger.ErrorWriter()
|
||||
|
||||
if s.config.LogLevel != "debug" {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
|
||||
@ -24,7 +27,7 @@ func (s *ApiServer) CreateRouter(repository *repositories.DataRepository) {
|
||||
e.RedirectTrailingSlash = false
|
||||
})
|
||||
|
||||
if s.config.Debug {
|
||||
if s.config.LogLevel == "debug" {
|
||||
router.Use(middleware.RequestLogger())
|
||||
}
|
||||
|
||||
@ -89,10 +92,10 @@ func (s *ApiServer) Start() {
|
||||
|
||||
go func() {
|
||||
<-s.stopServer
|
||||
logger.Info("Shutting down server...")
|
||||
logger.InfoLn("Shutting down server...")
|
||||
err := server.Shutdown(context.TODO())
|
||||
if err != nil {
|
||||
logger.Error("Failed to shutdown server:", err)
|
||||
logger.ErrorLn("Failed to shutdown server:", err)
|
||||
}
|
||||
}()
|
||||
|
||||
@ -101,7 +104,7 @@ func (s *ApiServer) Start() {
|
||||
logger.Infof("Listening and serving HTTP on %s\n", server.Addr)
|
||||
err := server.ListenAndServe()
|
||||
if err != nil {
|
||||
logger.Error("Failed to start HTTP server:", err)
|
||||
logger.ErrorLn("Failed to start HTTP server:", err)
|
||||
}
|
||||
s.isActive = false
|
||||
} else if s.config.TLS_CertificatePath != "" && s.config.TLS_CertificateKey != "" {
|
||||
@ -110,7 +113,7 @@ func (s *ApiServer) Start() {
|
||||
s.config.TLS_CertificatePath,
|
||||
s.config.TLS_CertificateKey)
|
||||
if err != nil {
|
||||
logger.Error("Failed to start HTTPS server:", err)
|
||||
logger.ErrorLn("Failed to start HTTPS server:", err)
|
||||
}
|
||||
s.isActive = false
|
||||
} else {
|
||||
@ -120,7 +123,7 @@ func (s *ApiServer) Start() {
|
||||
logger.Infof("Listening and serving HTTPS on %s\n", server.Addr)
|
||||
err := server.ListenAndServeTLS("", "")
|
||||
if err != nil {
|
||||
logger.Error("Failed to start HTTPS server:", err)
|
||||
logger.ErrorLn("Failed to start HTTPS server:", err)
|
||||
}
|
||||
s.isActive = false
|
||||
}
|
||||
|
@ -5,36 +5,100 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
var EnableDebugOutput = false
|
||||
type LogLevelType int
|
||||
|
||||
var (
|
||||
LogLevelDebug LogLevelType = 0
|
||||
LogLevelInfo LogLevelType = 1
|
||||
LogLevelError LogLevelType = 2
|
||||
LogLevelSilent LogLevelType = 10
|
||||
)
|
||||
|
||||
type LogWriter struct {
|
||||
WriterLevel LogLevelType
|
||||
}
|
||||
|
||||
var LogLevel = LogLevelInfo
|
||||
|
||||
var DebugLogger = log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile)
|
||||
var InfoLogger = log.New(os.Stdout, "", log.Ldate|log.Ltime)
|
||||
var ErrorLogger = log.New(os.Stderr, "", log.Ldate|log.Ltime|log.Lshortfile)
|
||||
|
||||
func Debug(v ...any) {
|
||||
if EnableDebugOutput {
|
||||
func DebugLn(v ...any) {
|
||||
if LogLevel <= LogLevelDebug {
|
||||
DebugLogger.Println(v...)
|
||||
}
|
||||
}
|
||||
|
||||
func Debug(v ...any) {
|
||||
if LogLevel <= LogLevelDebug {
|
||||
DebugLogger.Print(v...)
|
||||
}
|
||||
}
|
||||
|
||||
func Debugf(format string, v ...any) {
|
||||
if EnableDebugOutput {
|
||||
if LogLevel <= LogLevelDebug {
|
||||
DebugLogger.Printf(format, v...)
|
||||
}
|
||||
}
|
||||
|
||||
func InfoLn(v ...any) {
|
||||
if LogLevel <= LogLevelInfo {
|
||||
InfoLogger.Println(v...)
|
||||
}
|
||||
}
|
||||
|
||||
func Info(v ...any) {
|
||||
InfoLogger.Println(v...)
|
||||
if LogLevel <= LogLevelInfo {
|
||||
InfoLogger.Print(v...)
|
||||
}
|
||||
}
|
||||
|
||||
func Infof(format string, v ...any) {
|
||||
InfoLogger.Printf(format, v...)
|
||||
if LogLevel <= LogLevelInfo {
|
||||
InfoLogger.Printf(format, v...)
|
||||
}
|
||||
}
|
||||
|
||||
func ErrorLn(v ...any) {
|
||||
if LogLevel <= LogLevelError {
|
||||
ErrorLogger.Println(v...)
|
||||
}
|
||||
}
|
||||
|
||||
func Error(v ...any) {
|
||||
ErrorLogger.Println(v...)
|
||||
if LogLevel <= LogLevelError {
|
||||
ErrorLogger.Print(v...)
|
||||
}
|
||||
}
|
||||
|
||||
func Errorf(format string, v ...any) {
|
||||
ErrorLogger.Printf(format, v...)
|
||||
if LogLevel <= LogLevelError {
|
||||
ErrorLogger.Printf(format, v...)
|
||||
}
|
||||
}
|
||||
|
||||
func (lw *LogWriter) Write(p []byte) (n int, err error) {
|
||||
switch lw.WriterLevel {
|
||||
case LogLevelDebug:
|
||||
Debug(string(p))
|
||||
case LogLevelInfo:
|
||||
Info(string(p))
|
||||
case LogLevelError:
|
||||
Error(string(p))
|
||||
}
|
||||
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
func ErrorWriter() *LogWriter {
|
||||
return &LogWriter{WriterLevel: LogLevelError}
|
||||
}
|
||||
|
||||
func InfoWriter() *LogWriter {
|
||||
return &LogWriter{WriterLevel: LogLevelInfo}
|
||||
}
|
||||
|
||||
func DebugWriter() *LogWriter {
|
||||
return &LogWriter{WriterLevel: LogLevelDebug}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ func (r *DataRepository) InitializeRepository() {
|
||||
}
|
||||
|
||||
if stat.IsDir() {
|
||||
logger.Error("Argument '-Persist' must be a path to file, not a directory.")
|
||||
logger.ErrorLn("Argument '-Persist' must be a path to file, not a directory.")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ func (r *DataRepository) LoadStateJSON(jsonData string) error {
|
||||
|
||||
r.ensureStoreStateNoNullReferences()
|
||||
|
||||
logger.Info("Loaded state:")
|
||||
logger.InfoLn("Loaded state:")
|
||||
logger.Infof("Databases: %d\n", getLength(r.storeState.Databases))
|
||||
logger.Infof("Collections: %d\n", getLength(r.storeState.Collections))
|
||||
logger.Infof("Documents: %d\n", getLength(r.storeState.Documents))
|
||||
@ -83,7 +83,7 @@ func (r *DataRepository) SaveStateFS(filePath string) {
|
||||
|
||||
os.WriteFile(filePath, data, os.ModePerm)
|
||||
|
||||
logger.Info("Saved state:")
|
||||
logger.InfoLn("Saved state:")
|
||||
logger.Infof("Databases: %d\n", getLength(r.storeState.Databases))
|
||||
logger.Infof("Collections: %d\n", getLength(r.storeState.Collections))
|
||||
logger.Infof("Documents: %d\n", getLength(r.storeState.Documents))
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
func GetDefaultTlsConfig() *tls.Config {
|
||||
cert, err := tls.X509KeyPair([]byte(certificate), []byte(certificateKey))
|
||||
if err != nil {
|
||||
logger.Error("Failed to parse certificate and key:", err)
|
||||
logger.ErrorLn("Failed to parse certificate and key:", err)
|
||||
return &tls.Config{}
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ func (r rowContext) array_Contains(arguments []interface{}) bool {
|
||||
if boolValue, ok := boolExpr.(bool); ok {
|
||||
partialSearch = boolValue
|
||||
} else {
|
||||
logger.Error("array_Contains - got parameters of wrong type")
|
||||
logger.ErrorLn("array_Contains - got parameters of wrong type")
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -116,13 +116,13 @@ func (r rowContext) array_Slice(arguments []interface{}) []interface{} {
|
||||
lengthEx := r.resolveSelectItem(arguments[2].(parsers.SelectItem))
|
||||
|
||||
if length, ok = lengthEx.(int); !ok {
|
||||
logger.Error("array_Slice - got length parameters of wrong type")
|
||||
logger.ErrorLn("array_Slice - got length parameters of wrong type")
|
||||
return []interface{}{}
|
||||
}
|
||||
}
|
||||
|
||||
if start, ok = startEx.(int); !ok {
|
||||
logger.Error("array_Slice - got start parameters of wrong type")
|
||||
logger.ErrorLn("array_Slice - got start parameters of wrong type")
|
||||
return []interface{}{}
|
||||
}
|
||||
|
||||
@ -197,7 +197,7 @@ func (r rowContext) parseArray(argument interface{}) []interface{} {
|
||||
|
||||
arrValue := reflect.ValueOf(ex)
|
||||
if arrValue.Kind() != reflect.Slice {
|
||||
logger.Error("parseArray got parameters of wrong type")
|
||||
logger.ErrorLn("parseArray got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -215,7 +215,7 @@ func (r rowContext) partialMatch(item interface{}, exprToSearch interface{}) boo
|
||||
exprValue := reflect.ValueOf(exprToSearch)
|
||||
|
||||
if itemValue.Kind() != reflect.Map || exprValue.Kind() != reflect.Map {
|
||||
logger.Error("partialMatch got parameters of wrong type")
|
||||
logger.ErrorLn("partialMatch got parameters of wrong type")
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ func (r rowContext) math_Abs(arguments []interface{}) interface{} {
|
||||
}
|
||||
return val
|
||||
default:
|
||||
logger.Debug("math_Abs - got parameters of wrong type")
|
||||
logger.DebugLn("math_Abs - got parameters of wrong type")
|
||||
return 0
|
||||
}
|
||||
}
|
||||
@ -32,12 +32,12 @@ func (r rowContext) math_Acos(arguments []interface{}) interface{} {
|
||||
|
||||
val, valIsNumber := numToFloat64(ex)
|
||||
if !valIsNumber {
|
||||
logger.Debug("math_Acos - got parameters of wrong type")
|
||||
logger.DebugLn("math_Acos - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
if val < -1 || val > 1 {
|
||||
logger.Debug("math_Acos - value out of domain for acos")
|
||||
logger.DebugLn("math_Acos - value out of domain for acos")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -50,12 +50,12 @@ func (r rowContext) math_Asin(arguments []interface{}) interface{} {
|
||||
|
||||
val, valIsNumber := numToFloat64(ex)
|
||||
if !valIsNumber {
|
||||
logger.Debug("math_Asin - got parameters of wrong type")
|
||||
logger.DebugLn("math_Asin - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
if val < -1 || val > 1 {
|
||||
logger.Debug("math_Asin - value out of domain for acos")
|
||||
logger.DebugLn("math_Asin - value out of domain for acos")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ func (r rowContext) math_Atan(arguments []interface{}) interface{} {
|
||||
|
||||
val, valIsNumber := numToFloat64(ex)
|
||||
if !valIsNumber {
|
||||
logger.Debug("math_Atan - got parameters of wrong type")
|
||||
logger.DebugLn("math_Atan - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ func (r rowContext) math_Ceiling(arguments []interface{}) interface{} {
|
||||
case int:
|
||||
return val
|
||||
default:
|
||||
logger.Debug("math_Ceiling - got parameters of wrong type")
|
||||
logger.DebugLn("math_Ceiling - got parameters of wrong type")
|
||||
return 0
|
||||
}
|
||||
}
|
||||
@ -96,7 +96,7 @@ func (r rowContext) math_Cos(arguments []interface{}) interface{} {
|
||||
|
||||
val, valIsNumber := numToFloat64(ex)
|
||||
if !valIsNumber {
|
||||
logger.Debug("math_Cos - got parameters of wrong type")
|
||||
logger.DebugLn("math_Cos - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -109,12 +109,12 @@ func (r rowContext) math_Cot(arguments []interface{}) interface{} {
|
||||
|
||||
val, valIsNumber := numToFloat64(ex)
|
||||
if !valIsNumber {
|
||||
logger.Debug("math_Cot - got parameters of wrong type")
|
||||
logger.DebugLn("math_Cot - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
if val == 0 {
|
||||
logger.Debug("math_Cot - cotangent undefined for zero")
|
||||
logger.DebugLn("math_Cot - cotangent undefined for zero")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ func (r rowContext) math_Degrees(arguments []interface{}) interface{} {
|
||||
|
||||
val, valIsNumber := numToFloat64(ex)
|
||||
if !valIsNumber {
|
||||
logger.Debug("math_Degrees - got parameters of wrong type")
|
||||
logger.DebugLn("math_Degrees - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -140,7 +140,7 @@ func (r rowContext) math_Exp(arguments []interface{}) interface{} {
|
||||
|
||||
val, valIsNumber := numToFloat64(ex)
|
||||
if !valIsNumber {
|
||||
logger.Debug("math_Exp - got parameters of wrong type")
|
||||
logger.DebugLn("math_Exp - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ func (r rowContext) math_Floor(arguments []interface{}) interface{} {
|
||||
case int:
|
||||
return val
|
||||
default:
|
||||
logger.Debug("math_Floor - got parameters of wrong type")
|
||||
logger.DebugLn("math_Floor - got parameters of wrong type")
|
||||
return 0
|
||||
}
|
||||
}
|
||||
@ -170,7 +170,7 @@ func (r rowContext) math_IntBitNot(arguments []interface{}) interface{} {
|
||||
case int:
|
||||
return ^val
|
||||
default:
|
||||
logger.Debug("math_IntBitNot - got parameters of wrong type")
|
||||
logger.DebugLn("math_IntBitNot - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -181,12 +181,12 @@ func (r rowContext) math_Log10(arguments []interface{}) interface{} {
|
||||
|
||||
val, valIsNumber := numToFloat64(ex)
|
||||
if !valIsNumber {
|
||||
logger.Debug("math_Log10 - got parameters of wrong type")
|
||||
logger.DebugLn("math_Log10 - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
if val <= 0 {
|
||||
logger.Debug("math_Log10 - value must be greater than 0")
|
||||
logger.DebugLn("math_Log10 - value must be greater than 0")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -199,7 +199,7 @@ func (r rowContext) math_Radians(arguments []interface{}) interface{} {
|
||||
|
||||
val, valIsNumber := numToFloat64(ex)
|
||||
if !valIsNumber {
|
||||
logger.Debug("math_Radians - got parameters of wrong type")
|
||||
logger.DebugLn("math_Radians - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -216,7 +216,7 @@ func (r rowContext) math_Round(arguments []interface{}) interface{} {
|
||||
case int:
|
||||
return val
|
||||
default:
|
||||
logger.Debug("math_Round - got parameters of wrong type")
|
||||
logger.DebugLn("math_Round - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -243,7 +243,7 @@ func (r rowContext) math_Sign(arguments []interface{}) interface{} {
|
||||
return 0
|
||||
}
|
||||
default:
|
||||
logger.Debug("math_Sign - got parameters of wrong type")
|
||||
logger.DebugLn("math_Sign - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -254,7 +254,7 @@ func (r rowContext) math_Sin(arguments []interface{}) interface{} {
|
||||
|
||||
val, valIsNumber := numToFloat64(ex)
|
||||
if !valIsNumber {
|
||||
logger.Debug("math_Sin - got parameters of wrong type")
|
||||
logger.DebugLn("math_Sin - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -267,7 +267,7 @@ func (r rowContext) math_Sqrt(arguments []interface{}) interface{} {
|
||||
|
||||
val, valIsNumber := numToFloat64(ex)
|
||||
if !valIsNumber {
|
||||
logger.Debug("math_Sqrt - got parameters of wrong type")
|
||||
logger.DebugLn("math_Sqrt - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -280,7 +280,7 @@ func (r rowContext) math_Square(arguments []interface{}) interface{} {
|
||||
|
||||
val, valIsNumber := numToFloat64(ex)
|
||||
if !valIsNumber {
|
||||
logger.Debug("math_Square - got parameters of wrong type")
|
||||
logger.DebugLn("math_Square - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -293,7 +293,7 @@ func (r rowContext) math_Tan(arguments []interface{}) interface{} {
|
||||
|
||||
val, valIsNumber := numToFloat64(ex)
|
||||
if !valIsNumber {
|
||||
logger.Debug("math_Tan - got parameters of wrong type")
|
||||
logger.DebugLn("math_Tan - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -310,7 +310,7 @@ func (r rowContext) math_Trunc(arguments []interface{}) interface{} {
|
||||
case int:
|
||||
return float64(val)
|
||||
default:
|
||||
logger.Debug("math_Trunc - got parameters of wrong type")
|
||||
logger.DebugLn("math_Trunc - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -325,7 +325,7 @@ func (r rowContext) math_Atn2(arguments []interface{}) interface{} {
|
||||
x, xIsNumber := numToFloat64(ex2)
|
||||
|
||||
if !yIsNumber || !xIsNumber {
|
||||
logger.Debug("math_Atn2 - got parameters of wrong type")
|
||||
logger.DebugLn("math_Atn2 - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -342,7 +342,7 @@ func (r rowContext) math_IntAdd(arguments []interface{}) interface{} {
|
||||
ex2Number, ex2IsNumber := numToInt(ex2)
|
||||
|
||||
if !ex1IsNumber || !ex2IsNumber {
|
||||
logger.Debug("math_IntAdd - got parameters of wrong type")
|
||||
logger.DebugLn("math_IntAdd - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -359,7 +359,7 @@ func (r rowContext) math_IntBitAnd(arguments []interface{}) interface{} {
|
||||
ex2Int, ex2IsInt := numToInt(ex2)
|
||||
|
||||
if !ex1IsInt || !ex2IsInt {
|
||||
logger.Debug("math_IntBitAnd - got parameters of wrong type")
|
||||
logger.DebugLn("math_IntBitAnd - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -376,7 +376,7 @@ func (r rowContext) math_IntBitLeftShift(arguments []interface{}) interface{} {
|
||||
num2, num2IsInt := numToInt(ex2)
|
||||
|
||||
if !num1IsInt || !num2IsInt {
|
||||
logger.Debug("math_IntBitLeftShift - got parameters of wrong type")
|
||||
logger.DebugLn("math_IntBitLeftShift - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -393,7 +393,7 @@ func (r rowContext) math_IntBitOr(arguments []interface{}) interface{} {
|
||||
num2, num2IsInt := ex2.(int)
|
||||
|
||||
if !num1IsInt || !num2IsInt {
|
||||
logger.Debug("math_IntBitOr - got parameters of wrong type")
|
||||
logger.DebugLn("math_IntBitOr - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -410,7 +410,7 @@ func (r rowContext) math_IntBitRightShift(arguments []interface{}) interface{} {
|
||||
num2, num2IsInt := numToInt(ex2)
|
||||
|
||||
if !num1IsInt || !num2IsInt {
|
||||
logger.Debug("math_IntBitRightShift - got parameters of wrong type")
|
||||
logger.DebugLn("math_IntBitRightShift - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -427,7 +427,7 @@ func (r rowContext) math_IntBitXor(arguments []interface{}) interface{} {
|
||||
num2, num2IsInt := ex2.(int)
|
||||
|
||||
if !num1IsInt || !num2IsInt {
|
||||
logger.Debug("math_IntBitXor - got parameters of wrong type")
|
||||
logger.DebugLn("math_IntBitXor - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -444,7 +444,7 @@ func (r rowContext) math_IntDiv(arguments []interface{}) interface{} {
|
||||
num2, num2IsInt := ex2.(int)
|
||||
|
||||
if !num1IsInt || !num2IsInt || num2 == 0 {
|
||||
logger.Debug("math_IntDiv - got parameters of wrong type or divide by zero")
|
||||
logger.DebugLn("math_IntDiv - got parameters of wrong type or divide by zero")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -461,7 +461,7 @@ func (r rowContext) math_IntMul(arguments []interface{}) interface{} {
|
||||
num2, num2IsInt := ex2.(int)
|
||||
|
||||
if !num1IsInt || !num2IsInt {
|
||||
logger.Debug("math_IntMul - got parameters of wrong type")
|
||||
logger.DebugLn("math_IntMul - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -478,7 +478,7 @@ func (r rowContext) math_IntSub(arguments []interface{}) interface{} {
|
||||
num2, num2IsInt := ex2.(int)
|
||||
|
||||
if !num1IsInt || !num2IsInt {
|
||||
logger.Debug("math_IntSub - got parameters of wrong type")
|
||||
logger.DebugLn("math_IntSub - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -495,7 +495,7 @@ func (r rowContext) math_IntMod(arguments []interface{}) interface{} {
|
||||
num2, num2IsInt := ex2.(int)
|
||||
|
||||
if !num1IsInt || !num2IsInt || num2 == 0 {
|
||||
logger.Debug("math_IntMod - got parameters of wrong type or divide by zero")
|
||||
logger.DebugLn("math_IntMod - got parameters of wrong type or divide by zero")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -512,7 +512,7 @@ func (r rowContext) math_Power(arguments []interface{}) interface{} {
|
||||
exponent, exponentIsNumber := numToFloat64(ex2)
|
||||
|
||||
if !baseIsNumber || !exponentIsNumber {
|
||||
logger.Debug("math_Power - got parameters of wrong type")
|
||||
logger.DebugLn("math_Power - got parameters of wrong type")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -530,21 +530,21 @@ func (r rowContext) math_Log(arguments []interface{}) interface{} {
|
||||
baseValue, baseValueIsNumber := numToFloat64(baseValueObject)
|
||||
|
||||
if !baseValueIsNumber {
|
||||
logger.Debug("math_Log - base parameter must be a numeric value")
|
||||
logger.DebugLn("math_Log - base parameter must be a numeric value")
|
||||
return nil
|
||||
}
|
||||
|
||||
if baseValue > 0 && baseValue != 1 {
|
||||
base = baseValue
|
||||
} else {
|
||||
logger.Debug("math_Log - base must be greater than 0 and not equal to 1")
|
||||
logger.DebugLn("math_Log - base must be greater than 0 and not equal to 1")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
num, numIsNumber := numToFloat64(ex)
|
||||
if !numIsNumber || num <= 0 {
|
||||
logger.Debug("math_Log - parameter must be a positive numeric value")
|
||||
logger.DebugLn("math_Log - parameter must be a positive numeric value")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -563,21 +563,21 @@ func (r rowContext) math_NumberBin(arguments []interface{}) interface{} {
|
||||
binSizeValue, binSizeValueIsNumber := numToFloat64(binSizeValueObject)
|
||||
|
||||
if !binSizeValueIsNumber {
|
||||
logger.Debug("math_NumberBin - base parameter must be a numeric value")
|
||||
logger.DebugLn("math_NumberBin - base parameter must be a numeric value")
|
||||
return nil
|
||||
}
|
||||
|
||||
if binSizeValue != 0 {
|
||||
binSize = binSizeValue
|
||||
} else {
|
||||
logger.Debug("math_NumberBin - base must not be equal to 0")
|
||||
logger.DebugLn("math_NumberBin - base must not be equal to 0")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
num, numIsNumber := numToFloat64(ex)
|
||||
if !numIsNumber {
|
||||
logger.Debug("math_NumberBin - parameter must be a numeric value")
|
||||
logger.DebugLn("math_NumberBin - parameter must be a numeric value")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -172,7 +172,7 @@ func (r rowContext) filters_ComparisonExpression(expression parsers.ComparisonEx
|
||||
rightExpression, rightExpressionOk := expression.Right.(parsers.SelectItem)
|
||||
|
||||
if !leftExpressionOk || !rightExpressionOk {
|
||||
logger.Error("ComparisonExpression has incorrect Left or Right type")
|
||||
logger.ErrorLn("ComparisonExpression has incorrect Left or Right type")
|
||||
return false
|
||||
}
|
||||
|
||||
@ -351,7 +351,7 @@ func (r rowContext) resolveSelectItem(selectItem parsers.SelectItem) interface{}
|
||||
return r.selectItem_SelectItemTypeFunctionCall(typedFunctionCall)
|
||||
}
|
||||
|
||||
logger.Error("parsers.SelectItem has incorrect Value type (expected parsers.FunctionCall)")
|
||||
logger.ErrorLn("parsers.SelectItem has incorrect Value type (expected parsers.FunctionCall)")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -379,7 +379,7 @@ func (r rowContext) selectItem_SelectItemTypeConstant(selectItem parsers.SelectI
|
||||
var ok bool
|
||||
if typedValue, ok = selectItem.Value.(parsers.Constant); !ok {
|
||||
// TODO: Handle error
|
||||
logger.Error("parsers.Constant has incorrect Value type")
|
||||
logger.ErrorLn("parsers.Constant has incorrect Value type")
|
||||
}
|
||||
|
||||
if typedValue.Type == parsers.ConstantTypeParameterConstant &&
|
||||
|
@ -119,7 +119,7 @@ func (r rowContext) strings_Left(arguments []interface{}) string {
|
||||
lengthEx := r.resolveSelectItem(arguments[1].(parsers.SelectItem))
|
||||
|
||||
if length, ok = lengthEx.(int); !ok {
|
||||
logger.Error("strings_Left - got parameters of wrong type")
|
||||
logger.ErrorLn("strings_Left - got parameters of wrong type")
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -158,7 +158,7 @@ func (r rowContext) strings_Replicate(arguments []interface{}) string {
|
||||
timesEx := r.resolveSelectItem(arguments[1].(parsers.SelectItem))
|
||||
|
||||
if times, ok = timesEx.(int); !ok {
|
||||
logger.Error("strings_Replicate - got parameters of wrong type")
|
||||
logger.ErrorLn("strings_Replicate - got parameters of wrong type")
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -191,7 +191,7 @@ func (r rowContext) strings_Right(arguments []interface{}) string {
|
||||
lengthEx := r.resolveSelectItem(arguments[1].(parsers.SelectItem))
|
||||
|
||||
if length, ok = lengthEx.(int); !ok {
|
||||
logger.Error("strings_Right - got parameters of wrong type")
|
||||
logger.ErrorLn("strings_Right - got parameters of wrong type")
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -220,11 +220,11 @@ func (r rowContext) strings_Substring(arguments []interface{}) string {
|
||||
lengthEx := r.resolveSelectItem(arguments[2].(parsers.SelectItem))
|
||||
|
||||
if startPos, ok = startPosEx.(int); !ok {
|
||||
logger.Error("strings_Substring - got start parameters of wrong type")
|
||||
logger.ErrorLn("strings_Substring - got start parameters of wrong type")
|
||||
return ""
|
||||
}
|
||||
if length, ok = lengthEx.(int); !ok {
|
||||
logger.Error("strings_Substring - got length parameters of wrong type")
|
||||
logger.ErrorLn("strings_Substring - got length parameters of wrong type")
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -264,7 +264,7 @@ func (r rowContext) parseString(argument interface{}) string {
|
||||
return str1
|
||||
}
|
||||
|
||||
logger.Error("StringEquals got parameters of wrong type")
|
||||
logger.ErrorLn("StringEquals got parameters of wrong type")
|
||||
return ""
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user