From 43ff653cf3f4ace1dcd66efff73a9ecd3e7bdd54 Mon Sep 17 00:00:00 2001 From: Leandro Moreira Date: Tue, 27 Feb 2024 07:56:18 -0300 Subject: [PATCH 1/7] add string representation to log level --- log.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/log.go b/log.go index 481f7ed..d7aa6b6 100644 --- a/log.go +++ b/log.go @@ -37,6 +37,11 @@ import "unsafe" type LogLevel int +// https://github.com/FFmpeg/FFmpeg/blob/release/5.1/libavutil/log.c#L268 +func (l LogLevel) String() { + return C.GoString(C.get_level_str(C.int(l))) +} + // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavutil/log.h#L162 const ( LogLevelQuiet = LogLevel(C.AV_LOG_QUIET) From 7f7c02755d75fc784e605e180f041dfb60264f95 Mon Sep 17 00:00:00 2001 From: Leandro Moreira Date: Tue, 27 Feb 2024 08:00:55 -0300 Subject: [PATCH 2/7] Add tests for log level string representation --- log_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/log_test.go b/log_test.go index 6651246..3f1b789 100644 --- a/log_test.go +++ b/log_test.go @@ -19,6 +19,7 @@ func TestLog(t *testing.T) { lis = append(lis, logItem{ fmt: fmt, l: l, + lString: l.String(), msg: msg, }) }) @@ -31,16 +32,19 @@ func TestLog(t *testing.T) { { fmt: "warning", l: astiav.LogLevelWarning, + lString: "warning", msg: "warning", }, { fmt: "error", l: astiav.LogLevelError, + lString: "error", msg: "error", }, { fmt: "fatal", l: astiav.LogLevelFatal, + lString: "fatal", msg: "fatal", }, }, lis) From 19b2fbe8db7e76ab840f08073e459c7f6ad450c3 Mon Sep 17 00:00:00 2001 From: Leandro Moreira Date: Tue, 27 Feb 2024 14:02:53 -0300 Subject: [PATCH 3/7] move String method down --- log.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/log.go b/log.go index d7aa6b6..dd059d2 100644 --- a/log.go +++ b/log.go @@ -37,11 +37,6 @@ import "unsafe" type LogLevel int -// https://github.com/FFmpeg/FFmpeg/blob/release/5.1/libavutil/log.c#L268 -func (l LogLevel) String() { - return C.GoString(C.get_level_str(C.int(l))) -} - // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavutil/log.h#L162 const ( LogLevelQuiet = LogLevel(C.AV_LOG_QUIET) @@ -54,6 +49,10 @@ const ( LogLevelDebug = LogLevel(C.AV_LOG_DEBUG) ) +func (l LogLevel) String() { + return C.GoString(C.get_level_str(C.int(l))) +} + func SetLogLevel(l LogLevel) { C.av_log_set_level(C.int(l)) } From 682804bac1bdb31127321ea00ad1b11635a1ba2e Mon Sep 17 00:00:00 2001 From: Leandro Moreira Date: Tue, 27 Feb 2024 14:06:18 -0300 Subject: [PATCH 4/7] improve lot tester --- log_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/log_test.go b/log_test.go index 3f1b789..89bfc32 100644 --- a/log_test.go +++ b/log_test.go @@ -19,10 +19,12 @@ func TestLog(t *testing.T) { lis = append(lis, logItem{ fmt: fmt, l: l, - lString: l.String(), msg: msg, }) }) + + require.Equal(t, "error", astiav.LogLevelError.String()) + astiav.SetLogLevel(astiav.LogLevelWarning) astiav.Log(astiav.LogLevelInfo, "info") astiav.Log(astiav.LogLevelWarning, "warning") @@ -32,19 +34,16 @@ func TestLog(t *testing.T) { { fmt: "warning", l: astiav.LogLevelWarning, - lString: "warning", msg: "warning", }, { fmt: "error", l: astiav.LogLevelError, - lString: "error", msg: "error", }, { fmt: "fatal", l: astiav.LogLevelFatal, - lString: "fatal", msg: "fatal", }, }, lis) From 8f4db840150b855c3e4a2e6de708404dbdba8bd5 Mon Sep 17 00:00:00 2001 From: Leandro Moreira Date: Tue, 27 Feb 2024 14:15:14 -0300 Subject: [PATCH 5/7] declare unexposed c function --- log.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/log.go b/log.go index dd059d2..67929bf 100644 --- a/log.go +++ b/log.go @@ -7,6 +7,8 @@ package astiav /* extern void goAstiavLogCallback(int level, char* fmt, char* msg, char* parent); +char *get_level_str(int level); + static inline void astiavLogCallback(void *avcl, int level, const char *fmt, va_list vl) { if (level > av_log_get_level()) return; From c95e576c1d3953a60f5b3ea4d0397a9816cd766a Mon Sep 17 00:00:00 2001 From: Leandro Moreira Date: Tue, 27 Feb 2024 14:20:36 -0300 Subject: [PATCH 6/7] expose log.c function symbol --- log.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log.go b/log.go index 67929bf..7fd5fdd 100644 --- a/log.go +++ b/log.go @@ -7,7 +7,7 @@ package astiav /* extern void goAstiavLogCallback(int level, char* fmt, char* msg, char* parent); -char *get_level_str(int level); +extern const char *get_level_str(int level); static inline void astiavLogCallback(void *avcl, int level, const char *fmt, va_list vl) { From 32af09015e6e48e8ca1f037f03c78e3d9e3743b6 Mon Sep 17 00:00:00 2001 From: Leandro Moreira Date: Tue, 27 Feb 2024 14:31:44 -0300 Subject: [PATCH 7/7] return proper type --- log.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log.go b/log.go index 7fd5fdd..53aea5f 100644 --- a/log.go +++ b/log.go @@ -51,7 +51,7 @@ const ( LogLevelDebug = LogLevel(C.AV_LOG_DEBUG) ) -func (l LogLevel) String() { +func (l LogLevel) String() string { return C.GoString(C.get_level_str(C.int(l))) }