From 72057d00e9135f5b2f6b1fd2cf9a92f95118ea62 Mon Sep 17 00:00:00 2001 From: Romain Beauxis Date: Mon, 20 Feb 2023 10:25:44 -0600 Subject: [PATCH 1/4] Add SDL log verbosity conf. --- src/core/tools/sdl_utils.ml | 55 ++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/core/tools/sdl_utils.ml b/src/core/tools/sdl_utils.ml index 8067610fe9..ead2f99bc6 100644 --- a/src/core/tools/sdl_utils.ml +++ b/src/core/tools/sdl_utils.ml @@ -20,10 +20,54 @@ *****************************************************************************) +let log = Log.make ["sdl"] + open Mm open Tsdl module Gen = Image.Generic +let conf_sdl = + Dtools.Conf.void ~p:(Configure.conf#plug "sdl") "SDL configuration" + +let conf_log = Dtools.Conf.void ~p:(conf_sdl#plug "log") "Logging configuration" + +let categories = + [ + ("application", Sdl.Log.category_application); + ("error", Sdl.Log.category_error); + ("system", Sdl.Log.category_system); + ("audio", Sdl.Log.category_audio); + ("video", Sdl.Log.category_video); + ("render", Sdl.Log.category_render); + ("input", Sdl.Log.category_input); + ] + +let priorities = + [ + ("verbose", Sdl.Log.priority_verbose); + ("debug", Sdl.Log.priority_debug); + ("info", Sdl.Log.priority_info); + ("warn", Sdl.Log.priority_warn); + ("error", Sdl.Log.priority_error); + ("critical", Sdl.Log.priority_critical); + ] + +let logging_conf_list = + List.map + (fun (label, category) -> + ( label, + category, + Dtools.Conf.string ~p:(conf_log#plug label) + (label ^ " logging verbosity.") + ~comments: + [ + "Set SDL " ^ label ^ " logging verbosity"; + "One of: \"verbose\", \"debug\", \"info\", \"warn\", \"error\" \ + or \"critical\"."; + ] + ~d:"warn" )) + categories + type event = [ `AUDIO | `CDROM @@ -40,10 +84,19 @@ let check f x = match f x with Error (`Msg err) -> failwith err | Ok ans -> ans let initialized = ref false +let () = Sdl.log_set_all_priority Sdl.Log.priority_warn let init l = if !options = None then options := Some Sdl.Init.nothing; - List.iter (fun e -> options := Some Sdl.Init.(Option.get !options + e)) l + List.iter (fun e -> options := Some Sdl.Init.(Option.get !options + e)) l; + List.iter + (fun (label, category, conf) -> + try + let priority = List.assoc conf#get priorities in + Sdl.log_set_priority category priority + with Not_found -> + log#important "Invalid log priority %S for category %S!" conf#get label) + logging_conf_list let () = Lifecycle.on_start (fun () -> From 773d70a16a8a9758194605344a9ff914b39572ee Mon Sep 17 00:00:00 2001 From: Samuel Mimram Date: Fri, 28 Jul 2023 10:58:43 +0200 Subject: [PATCH 2/4] Remove useless ref. --- src/core/tools/sdl_utils.ml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/tools/sdl_utils.ml b/src/core/tools/sdl_utils.ml index ead2f99bc6..5f975b5fc4 100644 --- a/src/core/tools/sdl_utils.ml +++ b/src/core/tools/sdl_utils.ml @@ -83,7 +83,6 @@ let options : Sdl.Init.t option ref = ref None let check f x = match f x with Error (`Msg err) -> failwith err | Ok ans -> ans -let initialized = ref false let () = Sdl.log_set_all_priority Sdl.Log.priority_warn let init l = From d7af1cdfcb4eb88317cb7634cdb5c882bc2421c1 Mon Sep 17 00:00:00 2001 From: Samuel Mimram Date: Fri, 28 Jul 2023 17:45:21 +0200 Subject: [PATCH 3/4] New library to mute SDL messages. This is linked before sdl-image and sdl-ttf and thus manages to silence their startup message. --- CHANGES.md | 8 ++++++++ src/core/dune | 10 +++++++++- src/core/tools/sdl_log_level.ml | 29 +++++++++++++++++++++++++++++ src/core/tools/sdl_utils.ml | 1 + 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/core/tools/sdl_log_level.ml diff --git a/CHANGES.md b/CHANGES.md index a92eea1837..32f1bb734b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,11 @@ +# 2.2.1 (unreleased) + +New: + +Changed: + +- Mute SDL startup messages (#2913). + # 2.2.0 (2023-07-21) New: diff --git a/src/core/dune b/src/core/dune index 2127d1b917..3788dc1918 100644 --- a/src/core/dune +++ b/src/core/dune @@ -613,9 +613,17 @@ (optional) (modules libsamplerate_converter)) +(library + (name liquidsoap_sdl_log_level) + (libraries tsdl) + (library_flags -linkall) + (wrapped false) + (optional) + (modules sdl_log_level)) + (library (name liquidsoap_sdl) - (libraries tsdl-image tsdl-ttf liquidsoap_core) + (libraries liquidsoap_sdl_log_level tsdl-image tsdl-ttf liquidsoap_core) (library_flags -linkall) (wrapped false) (optional) diff --git a/src/core/tools/sdl_log_level.ml b/src/core/tools/sdl_log_level.ml new file mode 100644 index 0000000000..2adccd8c1f --- /dev/null +++ b/src/core/tools/sdl_log_level.ml @@ -0,0 +1,29 @@ +(***************************************************************************** + + Liquidsoap, a programmable audio stream generator. + Copyright 2003-2023 Savonet team + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details, fully stated in the COPYING + file at the root of the liquidsoap distribution. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + *****************************************************************************) + +(* We have to do a separate library here do lower the log level before + tsdl-image or tsdl-ttf module perform their side-effects and print an + obnoxious startup message. *) + +open Tsdl + +let () = Sdl.log_set_all_priority Sdl.Log.priority_warn diff --git a/src/core/tools/sdl_utils.ml b/src/core/tools/sdl_utils.ml index 5f975b5fc4..4aca7f3cff 100644 --- a/src/core/tools/sdl_utils.ml +++ b/src/core/tools/sdl_utils.ml @@ -83,6 +83,7 @@ let options : Sdl.Init.t option ref = ref None let check f x = match f x with Error (`Msg err) -> failwith err | Ok ans -> ans +(* This is also done is sdl_log_level, but just in case... *) let () = Sdl.log_set_all_priority Sdl.Log.priority_warn let init l = From 0128cadf1f61901daaf7fd746bd9825365920d8b Mon Sep 17 00:00:00 2001 From: Romain Beauxis Date: Fri, 28 Jul 2023 10:51:51 -0500 Subject: [PATCH 4/4] Update src/core/tools/sdl_utils.ml --- src/core/tools/sdl_utils.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/tools/sdl_utils.ml b/src/core/tools/sdl_utils.ml index 4aca7f3cff..27bffb30d4 100644 --- a/src/core/tools/sdl_utils.ml +++ b/src/core/tools/sdl_utils.ml @@ -83,7 +83,7 @@ let options : Sdl.Init.t option ref = ref None let check f x = match f x with Error (`Msg err) -> failwith err | Ok ans -> ans -(* This is also done is sdl_log_level, but just in case... *) +(* This is also done in sdl_log_level, but just in case... *) let () = Sdl.log_set_all_priority Sdl.Log.priority_warn let init l =