From 9e71019f2de3407518d1bfabb0d9db6c14113766 Mon Sep 17 00:00:00 2001 From: Cameron Clough Date: Sun, 27 Apr 2025 23:16:27 +0100 Subject: [PATCH 1/2] Switch to logging in `__init__.py`, set load message to debug - Replace print statements with logger.error() and logger.debug() calls. - Follow best practices by using a module-specific logger via getLogger(__name__). - Use parameterized log messages to avoid unnecessary string formatting. - Change the "RAYLIB STATIC x.x.x LOADED" message from direct stderr output to logger debug level. Motivation: In [commaai/openpilot#35076][openpilot-issue], we experienced noisy test outputs because the RAYLIB STATIC message is printed unnecessarily, cluttering stderr. This change allows library consumers to control the visibility of this message. [openpilot-issue]: https://github.com/commaai/openpilot/issues/35076 --- raylib/__init__.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/raylib/__init__.py b/raylib/__init__.py index bee47cb..d3501de 100644 --- a/raylib/__init__.py +++ b/raylib/__init__.py @@ -13,18 +13,22 @@ # SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 import sys +import logging + +logger = logging.getLogger(__name__) + try: from ._raylib_cffi import ffi, lib as rl except ModuleNotFoundError: - print("\n*** ERROR LOADING NATIVE CODE ***\n") - print("See https://github.com/electronstudio/raylib-python-cffi/issues/142\n", file=sys.stderr) - print("Your Python is: "+str(sys.implementation)+"\n", file=sys.stderr) + logger.error("*** ERROR LOADING NATIVE CODE ***") + logger.error("See https://github.com/electronstudio/raylib-python-cffi/issues/142") + logger.error("Your Python is: %s", str(sys.implementation)) raise + from raylib._raylib_cffi.lib import * from raylib.colors import * from raylib.defines import * import cffi from .version import __version__ -print("RAYLIB STATIC "+__version__+" LOADED", file=sys.stderr) - +logger.debug("RAYLIB STATIC %s LOADED", __version__) From 7d6ce1864a021b45666635174838ea080893e536 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 5 May 2025 16:19:59 +0100 Subject: [PATCH 2/2] use warning rather than debug logging --- dynamic/raylib/__init__.py | 7 ++++--- raylib/__init__.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/dynamic/raylib/__init__.py b/dynamic/raylib/__init__.py index a030bf0..75ab2d6 100644 --- a/dynamic/raylib/__init__.py +++ b/dynamic/raylib/__init__.py @@ -22,9 +22,10 @@ import itertools import os import pathlib import platform +import logging from .version import __version__ - +logger = logging.getLogger(__name__) MODULE = pathlib.Path(__file__).parent def raylib_library_path(): @@ -54,9 +55,9 @@ ffi.cdef(open(MODULE / "raylib_modified.h").read().replace('RLAPI ', '')) try: raylib_fname = raylib_library_path() rl = ffi.dlopen(raylib_fname) - print('LOADED DYNAMICALLY SHARED LIB {} {}'.format(__version__, raylib_fname)) + logger.warning('LOADED DYNAMICALLY SHARED LIB {} {}'.format(__version__, raylib_fname)) except Exception as e: - print(e) + logger.exception(e) LIGHTGRAY =( 200, 200, 200, 255 ) GRAY =( 130, 130, 130, 255 ) diff --git a/raylib/__init__.py b/raylib/__init__.py index d3501de..786ad69 100644 --- a/raylib/__init__.py +++ b/raylib/__init__.py @@ -31,4 +31,4 @@ from raylib.defines import * import cffi from .version import __version__ -logger.debug("RAYLIB STATIC %s LOADED", __version__) +logger.warning("RAYLIB STATIC %s LOADED", __version__)