Observed since 20 Oct, 15:04 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
A Python logging library compatible with NETSTARS log specification v1.3
Python implementation of structured logging compatible with NETSTARS log specification v1.3
logx is a universal logging library that conforms to the NETSTARS log specification requirements. By default, it supports NETSTARS Log Specification v1.3. Under specification v1.3, logx outputs logs in JSON format, as shown in the following example:
{"compliance":"1.3","log_app_id":"test_app_id","log_app_version":"0.1","log_category":"srv-exception-log","log_event_id":"","log_event_time":"2022-01-21T10:53:21.774+09:00","log_level":"fatal","log_time":"2022-01-21T10:53:21.774+09:00","message":"this is a test message"}
JSON format logs can nest JSON, and newlines and double quotes in key-value content are automatically escaped.
During development and debugging, you can set the compliance level to "0" to output simple semicolon-separated log information:
2022-01-21T10:56:43.901+09:00 [INF] item_1: 23; log_event_time: 2022-01-21T10:56:43.901+09:00; message: this is a test message
Note: Specification v1.3 meets SLA requirements and can be parsed by Elasticsearch; specification 0 is only recommended for development and testing phases.
Log levels in logx are integers conforming to the v1.3 log specification. Valid range is [0,6], where 0 means no log output, and 1-6 correspond to fatal, error, warn, info, debug, trace respectively. Larger values provide richer output information. The maximum output log level can be specified in the logx.init() initialization method to control the level of detail. You can also dynamically adjust the maximum log output level using the logx.set_max_level() method.
from logx import init, errorf, Log, InfoLvl, New, CustomItem, DebugLvl
# Initialize logging
init(DebugLvl, "my_app", "1.0.0", "1.3") # Set to debug level to show all logs
# Simple log output
errorf("用户登录失败: %s", "密码错误")
# Custom log items
Log(InfoLvl, "用户操作",
CustomItem("user_id", "12345"),
CustomItem("action", "login"))
# Use Loggerz object
logger = New(
CustomItem("service", "user-service"),
CustomItem("version", "1.0.0"),
)
logger.printf("处理用户请求: %s", "GET /api/users")
Running the above code will output the following JSON formatted logs:
{"compliance":"1.3","log_app_id":"my_app","log_app_version":"1.0.0","log_category":"srv-exception-log","log_event_id":"","log_event_time":"2025-10-22T19:58:30.785+08:00","log_level":"error","log_time":"2025-10-22T19:58:30.785+08:00","message":"用户登录失败: 密码错误"}
{"compliance":"1.3","log_app_id":"my_app","log_app_version":"1.0.0","log_category":"srv-biz-process-log","log_event_id":"","log_event_time":"2025-10-22T19:58:30.785+08:00","log_level":"info","log_time":"2025-10-22T19:58:30.785+08:00","message":"用户操作","user_id":"12345","action":"login"}
{"compliance":"1.3","log_app_id":"my_app","log_app_version":"1.0.0","log_category":"srv-biz-process-log","log_event_id":"","log_event_time":"2025-10-22T19:58:30.785+08:00","log_level":"info","log_time":"2025-10-22T19:58:30.785+08:00","message":"处理用户请求: GET /api/users","service":"user-service","version":"1.0.0"}
Initialization: Call the logx.init() method at program startup to set the maximum output log level. Usually this method is called in the main() function, and the parameter values can be provided through the application's configuration file.
DebugLvl: Sets the log level to debug, which outputs all level logs"my_app": Application ID"1.0.0": Application version number"1.3": Log specification version number. If "0" is specified, simple information is output, recommended only during debuggingSimple log output: Use methods like logx.printf(), logx.errorf() to output simple log information:
logx.errorf("用户登录失败: %s", "密码错误")
logx.log() and logx.CustomItem() methods to achieve maximum flexibility in log information customization:logx.Log(InfoLvl, "用户操作",
CustomItem("user_id", "12345"),
CustomItem("action", "login"))
logx.new() method to create a new Loggerz object and save some common log information, so you don't have to manually pass this information each time:logger = logx.new(
CustomItem("service", "user-service"),
CustomItem("version", "1.0.0"),
)
logger.printf("处理用户请求: %s", "GET /api/users")
pip install 0xnetx-logx
pip install git+https://github.com/0xNetx/logx.git
If you've cloned the repository:
cd logx
pip install -e .
Or install directly:
pip install -e /path/to/logx
DisabledLvl = 0: No log outputFatalLvl = 1: Fatal errorErrorLvl = 2: General errorWarnLvl = 3: WarningInfoLvl = 4: General infoDebugLvl = 5: Debug informationTraceLvl = 6: Trace informationinit(level, app_id, app_version, compliance): Initialize log configurationset_max_level(level): Set maximum log output levelget_max_level(): Get maximum log output levellog(level, message, *log_items): Log a message with specified levelfatal(*args): Log fatal messageerror(*args): Log error messagewarn(*args): Log warning messageprint(*args): Log info messagedebug(*args): Log debug messagetrace(*args): Log trace messageEach level also has *f (formatted) and *ln (with newline) variants.
CustomItem(key, value): Add custom log itemCompliance(version): Set compliance versionLogTime(time): Set log timeEventTime(time): Set event timeLevel(level): Set log levelCategory(category): Set log categoryAppId(app_id): Set application IDAppVersion(version): Set application versionEventId(event_id): Set event IDnew(*items) -> Loggerz: Create a new logger objectThe Loggerz class provides all the functionality of the global functions plus:
enable_log_elapsed_time(): Enable elapsed time trackingget_items(): Get all log itemsset_items(*items): Update log itemsadd_hook(hook): Add a hook functionDownload counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.0.2 | 3 Nov 2025 | 0 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 15:04 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:d7c5866dd42ec7923601b4aaecb02fa683b6721c6feb358dea1b9e6e71e149e0