This is an automated email from the ASF dual-hosted git repository.

laiyingchun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git


The following commit(s) were added to refs/heads/master by this push:
     new 46b019830 fix(Python-client):prevent logger override and migrate 
config to YAML (#2303)
46b019830 is described below

commit 46b019830b75bd62147164511852eeacebbf3d5e
Author: Jun 11 <[email protected]>
AuthorDate: Tue Nov 4 18:09:39 2025 +0800

    fix(Python-client):prevent logger override and migrate config to YAML 
(#2303)
    
    * Changed the configuration format from .conf to YAML.
    * Replaced logging.config.fileConfig with logging.config.dictConfig for log 
initialization.
---
 .../pypegasus/{logger.conf => logger.yaml}         | 42 +++++++++++++---------
 python-client/pypegasus/pgclient.py                | 10 +++++-
 python-client/requirement.txt                      |  1 +
 python-client/setup.py                             |  4 +--
 4 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/python-client/pypegasus/logger.conf 
b/python-client/pypegasus/logger.yaml
similarity index 58%
rename from python-client/pypegasus/logger.conf
rename to python-client/pypegasus/logger.yaml
index de3a85f41..25d8e74f9 100644
--- a/python-client/pypegasus/logger.conf
+++ b/python-client/pypegasus/logger.yaml
@@ -17,20 +17,28 @@
 # under the License.
 #
 
-[loggers]
-keys=root
-[logger_root]
-level=INFO
-handlers=hand01
-propagate=0
-[handlers]
-keys=hand01
-[handler_hand01]
-class=handlers.RotatingFileHandler
-formatter=form01
-args=('pegasus.log', 'a', 100*1024*1024, 10)
-[formatters]
-keys=form01
-[formatter_form01]
-format=%(asctime)s [%(thread)d] [%(levelname)s] %(filename)s:%(lineno)d 
%(message)s
-datefmt=%Y-%m-%d %H:%M:%S
+version: 1
+disable_existing_loggers: false
+
+formatters:
+  pegasus_formatter:
+    format: "%(asctime)s [%(thread)d] [%(levelname)s] %(filename)s:%(lineno)d 
%(message)s"
+    datefmt: "%Y-%m-%d %H:%M:%S"
+
+handlers:
+  pegasus_file_handler:
+    class: logging.handlers.RotatingFileHandler
+    level: INFO
+    formatter: pegasus_formatter
+    filename: pegasus.log
+    mode: a
+    maxBytes: 104857600  # 100 * 1024 * 1024
+    backupCount: 10
+    encoding: utf8
+
+loggers:
+  pgclient:
+    level: INFO
+    handlers: [pegasus_file_handler]
+    propagate: false
+    
\ No newline at end of file
diff --git a/python-client/pypegasus/pgclient.py 
b/python-client/pypegasus/pgclient.py
index 2438483ba..9960f44c2 100644
--- a/python-client/pypegasus/pgclient.py
+++ b/python-client/pypegasus/pgclient.py
@@ -21,6 +21,7 @@ from __future__ import with_statement
 import os
 import logging.config
 import six
+import yaml
 
 from thrift.Thrift import TMessageType, TApplicationException
 from twisted.internet import defer
@@ -43,8 +44,15 @@ try:
 except:
     fastbinary = None
 
+try:
+    with open(os.path.join(os.path.dirname(__file__), "logger.yaml"), 'r', 
encoding='utf-8') as f:
+        config = yaml.safe_load(f)
+        logging.config.dictConfig(config)
+        logging.getLogger("pgclient").debug("Logging config loaded 
successfully.")
+except Exception as e:
+    logging.basicConfig(level=logging.INFO)
+    logging.getLogger("pgclient").warning("Failed to load pgclient logging 
config: %s", e)
 
-logging.config.fileConfig(os.path.dirname(__file__)+"/logger.conf")
 logger = logging.getLogger("pgclient")
 
 DEFAULT_TIMEOUT = 2000               # ms
diff --git a/python-client/requirement.txt b/python-client/requirement.txt
index e785a8c16..b9b3ddcfe 100644
--- a/python-client/requirement.txt
+++ b/python-client/requirement.txt
@@ -3,3 +3,4 @@ aenum==3.0.0
 thrift==0.13.0
 pyOpenSSL==24.2.1
 cryptography==43.0.1
+PyYAML>=5.1
\ No newline at end of file
diff --git a/python-client/setup.py b/python-client/setup.py
index 44553ce8a..7aed44303 100644
--- a/python-client/setup.py
+++ b/python-client/setup.py
@@ -21,9 +21,9 @@ import pypegasus
 setup(
     name='pypegasus3',
     version=pypegasus.__version__,
-    install_requires=['Twisted==21.2.0', 'aenum==3.0.0', 'thrift==0.13.0', 
'pyOpenSSL==24.2.1','cryptography==43.0.1'],
+    install_requires=['Twisted==21.2.0', 'aenum==3.0.0', 'thrift==0.13.0', 
'pyOpenSSL==24.2.1', 'cryptography==43.0.1', 'PyYAML>=5.1'],
     packages=find_packages(),
-    package_data={'': ['logger.conf']},
+    package_data={'': ['logger.yaml']},
     platforms='any',
     url='https://github.com/apache/incubator-pegasus/python-client',
     license='Apache License 2.0',


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to