|
24 | 24 |
|
25 | 25 | from rich.logging import RichHandler |
26 | 26 |
|
| 27 | +""" |
| 28 | +HugeGraph Logger Util |
| 29 | +====================== |
| 30 | +
|
| 31 | +A unified logging module that provides consistent logging functionality across the HugeGraph project. |
| 32 | +
|
| 33 | +Key Features: |
| 34 | +- Uses "Rich" library for enhanced console output with proper formatting and colors |
| 35 | +- Provides both console and file logging capabilities with rotation |
| 36 | +- Includes utility functions for controlled logging frequency |
| 37 | +
|
| 38 | +Best Practices: |
| 39 | +- Other modules should reuse this logger instead of creating new logging configurations |
| 40 | +- Use the provided init_logger() function to maintain consistent log formatting |
| 41 | +- If additional functionality is needed, extend this module rather than creating new loggers |
| 42 | +
|
| 43 | +Example Usage: |
| 44 | + from pyhugegraph.utils.log import init_logger |
| 45 | + |
| 46 | + # Initialize logger with both console and file output |
| 47 | + log = init_logger( |
| 48 | + log_output="logs/myapp.log", |
| 49 | + log_level=logging.INFO, |
| 50 | + logger_name="myapp" |
| 51 | + ) |
| 52 | + |
| 53 | + # Use the log/logger |
| 54 | + log.info("Application started") |
| 55 | + log.debug("Processing data...") |
| 56 | + log.error("Error occurred: %s", error_msg) |
| 57 | +""" |
27 | 58 | __all__ = [ |
28 | 59 | "init_logger", |
29 | 60 | "fetch_log_level", |
|
38 | 69 |
|
39 | 70 | @lru_cache() # avoid creating multiple handlers when calling init_logger() |
40 | 71 | def init_logger( |
41 | | - log_output=None, |
42 | | - log_level=logging.INFO, |
43 | | - rank=0, |
44 | | - *, |
45 | | - logger_name="client", # users should set logger name for modules |
46 | | - propagate_logs: bool = False, |
47 | | - stdout_logging: bool = True, |
48 | | - max_log_size=50 * 1024 * 1024, # 50 MB |
49 | | - backup_logs=5, |
| 72 | + log_output=None, |
| 73 | + log_level=logging.INFO, |
| 74 | + rank=0, |
| 75 | + *, |
| 76 | + logger_name="client", # users should set logger name for modules |
| 77 | + propagate_logs: bool = False, |
| 78 | + stdout_logging: bool = True, |
| 79 | + max_log_size=50 * 1024 * 1024, # 50 MB |
| 80 | + backup_logs=5, |
50 | 81 | ): |
51 | 82 | """ |
52 | 83 | Initialize the logger and set its verbosity level to "DEBUG". |
@@ -200,4 +231,5 @@ def fetch_log_level(level_name: str): |
200 | 231 | raise ValueError(f"Invalid log level: {level_name}") |
201 | 232 | return level |
202 | 233 |
|
| 234 | + |
203 | 235 | log = init_logger(log_output="logs/output.log", log_level=logging.INFO) |
0 commit comments