Skip to content

Commit 80aab36

Browse files
author
keijack
committed
You can set your own logger now.
1 parent dd1eaa4 commit 80aab36

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,16 @@ logger.set_level("DEBUG")
417417

418418
This logger will first save all the log record to a global queue, and then output them in a background thread, so it is very suitable for getting several logger with a same handler, especialy the `TimedRotatingFileHandler` which may slice the log files not quite well in a mutiple thread environment.
419419

420+
### Costom Logger
421+
422+
If you want to use your own logger, you can do this:
423+
424+
```python
425+
import py_eureka_client.logger as logger
426+
427+
logger.set_custom_logger(your_logger)
428+
```
429+
420430
## Amazon Data Center Support
421431

422432
This component should support deploying in Amazone EC2, it should automatically load metadata from Amazon metadata service. All the metadata keys come from `com.netflix.appinfo.AmazonInfo` in Netflix's java client. BUT for the reason that I have no amazon environment to test, it may not work. If errors occurs, please submit an issue and provide some detail logs, I will try to fix it as far as I can. If it works, a reply in this [issue](https://github.com/keijack/python-eureka-client/issues/33) is wellcomed.

README.zh_cn.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,16 @@ logger.set_level("DEBUG")
426426

427427
这个日志使用了一个背景线程来输出日志,因此其非常适合使用在多线程的场景,特别你是你有多个 logger 共用一个 `TimedRotatingFileHandler` 的时候。在多线程的场景下,这个日志控制器经常不能正常地按时切割文件。
428428

429+
### 自定义 Logger
430+
431+
你可以通过以下方法来设置自己的 logger:
432+
433+
```python
434+
import py_eureka_client.logger as logger
435+
436+
logger.set_custom_logger(your_logger)
437+
```
438+
429439
## 亚马逊数据中心支持
430440

431441
理论上,这个组件可以正常运行在亚马逊的数据中心。当运行在亚马逊数据中心,会从亚马逊的 metadata 服务中取得相关的元数据并且自动填充到 DataCenterInfo 中,填充的字段信息来源自 Netflix 的 Java 客户端中的 `com.netflix.appinfo.AmazonInfo` 类。**不过**,由于我本人没有亚马逊的相关环境作为测试,所以,在实际的运行当中,可能会发生错误。如果真的发生了错误的话,请提出 ISSUE 并且提供详细的日志,我会尽力支持。如果运行没有问题,如果可以,也欢迎在这个[问题](https://github.com/keijack/python-eureka-client/issues/33)进行回复。

py_eureka_client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
SOFTWARE.
2323
"""
2424

25-
version = "0.11.11"
25+
version = "0.11.12"
2626

2727
"""
2828
Status of instances

py_eureka_client/logger.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ def get_logger(self, tag: str = "pythone-simple-http-server") -> logging.Logger:
168168

169169
_logger_factories: Dict[str, LoggerFactory] = {}
170170

171+
_custom_logger: logging.Logger = None
172+
171173

172174
def get_logger_factory(tag: str = "") -> LoggerFactory:
173175
if not tag:
@@ -193,5 +195,14 @@ def set_handler(handler: logging.Handler) -> None:
193195
_default_logger_factory.set_handler(handler)
194196

195197

196-
def get_logger(tag: str = "pythone-simple-http-server") -> logging.Logger:
198+
def get_logger(tag: str = "python-eureka-client") -> logging.Logger:
199+
global _custom_logger
200+
if _custom_logger:
201+
return _custom_logger
197202
return _default_logger_factory.get_logger(tag)
203+
204+
205+
def set_custom_logger(logger: logging.Logger) -> None:
206+
assert isinstance(logger, logging.Logger)
207+
global _custom_logger
208+
_custom_logger = logger

0 commit comments

Comments
 (0)