From 4ff8f498ce872020e8d397ff6fc83ee8459c081e Mon Sep 17 00:00:00 2001 From: "Thibault \"bui\" Koechlin" Date: Wed, 3 May 2023 10:07:11 +0200 Subject: [PATCH] add a LogInfo expr helper (#2179) --- pkg/exprhelpers/expr_lib.go | 7 +++++++ pkg/exprhelpers/strings.go | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/exprhelpers/expr_lib.go b/pkg/exprhelpers/expr_lib.go index 13e58b877..f4559157d 100644 --- a/pkg/exprhelpers/expr_lib.go +++ b/pkg/exprhelpers/expr_lib.go @@ -377,6 +377,13 @@ var exprFuncs = []exprCustomFunc{ new(func(string, string) bool), }, }, + { + name: "LogInfo", + function: LogInfo, + signature: []interface{}{ + new(func(string, ...interface{}) bool), + }, + }, } //go 1.20 "CutPrefix": strings.CutPrefix, diff --git a/pkg/exprhelpers/strings.go b/pkg/exprhelpers/strings.go index 81c6776b6..61804bcfa 100644 --- a/pkg/exprhelpers/strings.go +++ b/pkg/exprhelpers/strings.go @@ -1,6 +1,10 @@ package exprhelpers -import "strings" +import ( + "strings" + + log "github.com/sirupsen/logrus" +) //Wrappers for stdlib strings function exposed in expr @@ -67,3 +71,8 @@ func TrimSpace(params ...any) (any, error) { func TrimSuffix(params ...any) (any, error) { return strings.TrimSuffix(params[0].(string), params[1].(string)), nil } + +func LogInfo(params ...any) (any, error) { + log.Infof(params[0].(string), params[1:]...) + return true, nil +}