Introduce new logging API, fixes #858
PiperOrigin-RevId: 930744288 Change-Id: I6ec1203b55c031390f3eef23192e2337508ce886
This commit is contained in:
committed by
Copybara-Service
parent
a2abaf7aef
commit
58f6d52491
@@ -609,6 +609,29 @@ ENUMS: Mapping[str, EnumDecl] = dict([
|
||||
('mjS_AWAKE', 1),
|
||||
]),
|
||||
)),
|
||||
('mjtLogLevel',
|
||||
EnumDecl(
|
||||
name='mjtLogLevel',
|
||||
declname='enum mjtLogLevel_',
|
||||
values=dict([
|
||||
('mjLOG_DEBUG', 0),
|
||||
('mjLOG_INFO', 1),
|
||||
('mjLOG_WARNING', 2),
|
||||
('mjLOG_ERROR', 3),
|
||||
]),
|
||||
)),
|
||||
('mjtLogTopic',
|
||||
EnumDecl(
|
||||
name='mjtLogTopic',
|
||||
declname='enum mjtLogTopic_',
|
||||
values=dict([
|
||||
('mjTOPIC_NONE', 0),
|
||||
('mjTOPIC_TIME_STP', 1),
|
||||
('mjTOPIC_TIME_CMP', 2),
|
||||
('mjTOPIC_SLEEP', 3),
|
||||
('mjNTOPIC', 3),
|
||||
]),
|
||||
)),
|
||||
('mjtGeomInertia',
|
||||
EnumDecl(
|
||||
name='mjtGeomInertia',
|
||||
|
||||
@@ -6309,6 +6309,69 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
|
||||
parameters=(),
|
||||
doc='Clear user error and memory handlers.',
|
||||
)),
|
||||
('mju_setLogHandler',
|
||||
FunctionDecl(
|
||||
name='mju_setLogHandler',
|
||||
return_type=ValueType(name='mjfLogHandler'),
|
||||
parameters=(
|
||||
FunctionParameterDecl(
|
||||
name='handler',
|
||||
type=ValueType(name='mjfLogHandler'),
|
||||
),
|
||||
),
|
||||
doc='Set the active log handler; return the previous handler. If handler is NULL, restore the default handler.', # pylint: disable=line-too-long
|
||||
)),
|
||||
('mju_getLogConfig',
|
||||
FunctionDecl(
|
||||
name='mju_getLogConfig',
|
||||
return_type=ValueType(name='mjLogConfig'),
|
||||
parameters=(),
|
||||
doc='Get default handler configuration.',
|
||||
)),
|
||||
('mju_setLogConfig',
|
||||
FunctionDecl(
|
||||
name='mju_setLogConfig',
|
||||
return_type=ValueType(name='void'),
|
||||
parameters=(
|
||||
FunctionParameterDecl(
|
||||
name='config',
|
||||
type=ValueType(name='mjLogConfig'),
|
||||
),
|
||||
),
|
||||
doc='Set default handler configuration.',
|
||||
)),
|
||||
('mju_info',
|
||||
FunctionDecl(
|
||||
name='mju_info',
|
||||
return_type=ValueType(name='void'),
|
||||
parameters=(
|
||||
FunctionParameterDecl(
|
||||
name='topic',
|
||||
type=ValueType(name='int'),
|
||||
),
|
||||
FunctionParameterDecl(
|
||||
name='msg',
|
||||
type=PointerType(
|
||||
inner_type=ValueType(name='char', is_const=True),
|
||||
),
|
||||
),
|
||||
),
|
||||
doc='Log an info message with optional topic filtering.',
|
||||
)),
|
||||
('mju_message',
|
||||
FunctionDecl(
|
||||
name='mju_message',
|
||||
return_type=ValueType(name='void'),
|
||||
parameters=(
|
||||
FunctionParameterDecl(
|
||||
name='msg',
|
||||
type=PointerType(
|
||||
inner_type=ValueType(name='mjLogMessage', is_const=True),
|
||||
),
|
||||
),
|
||||
),
|
||||
doc='Dispatch a structured log message to the active handler.',
|
||||
)),
|
||||
('mju_malloc',
|
||||
FunctionDecl(
|
||||
name='mju_malloc',
|
||||
|
||||
@@ -28,6 +28,92 @@ from .ast_nodes import StructFieldDecl
|
||||
from .ast_nodes import ValueType
|
||||
|
||||
STRUCTS: Mapping[str, StructDecl] = dict([
|
||||
('mjLogMessage',
|
||||
StructDecl(
|
||||
name='mjLogMessage',
|
||||
declname='struct mjLogMessage_',
|
||||
fields=(
|
||||
StructFieldDecl(
|
||||
name='level',
|
||||
type=ValueType(name='int'),
|
||||
doc='mjtLogLevel',
|
||||
),
|
||||
StructFieldDecl(
|
||||
name='topic',
|
||||
type=ValueType(name='int'),
|
||||
doc='mjtLogTopic (0 for error/warning/user)',
|
||||
),
|
||||
StructFieldDecl(
|
||||
name='subject',
|
||||
type=ArrayType(
|
||||
inner_type=ValueType(name='char'),
|
||||
extents=(1024,),
|
||||
),
|
||||
doc='message subject (one-liner, printf-formatted)',
|
||||
),
|
||||
StructFieldDecl(
|
||||
name='body',
|
||||
type=PointerType(
|
||||
inner_type=ValueType(name='char', is_const=True),
|
||||
),
|
||||
doc='message body (multi-line detail, or NULL)',
|
||||
),
|
||||
StructFieldDecl(
|
||||
name='func',
|
||||
type=PointerType(
|
||||
inner_type=ValueType(name='char', is_const=True),
|
||||
),
|
||||
doc='__func__ or NULL',
|
||||
),
|
||||
StructFieldDecl(
|
||||
name='file',
|
||||
type=PointerType(
|
||||
inner_type=ValueType(name='char', is_const=True),
|
||||
),
|
||||
doc='__FILE__ or NULL',
|
||||
),
|
||||
StructFieldDecl(
|
||||
name='line',
|
||||
type=ValueType(name='int'),
|
||||
doc='__LINE__ or 0',
|
||||
),
|
||||
StructFieldDecl(
|
||||
name='timestamp',
|
||||
type=ValueType(name='mjtBool'),
|
||||
doc='prepend timestamp to output',
|
||||
),
|
||||
),
|
||||
)),
|
||||
('mjLogConfig',
|
||||
StructDecl(
|
||||
name='mjLogConfig',
|
||||
declname='struct mjLogConfig_',
|
||||
fields=(
|
||||
StructFieldDecl(
|
||||
name='logto_console',
|
||||
type=ValueType(name='mjtBool'),
|
||||
doc='print to console (default: true)',
|
||||
),
|
||||
StructFieldDecl(
|
||||
name='logto_file',
|
||||
type=ValueType(name='mjtBool'),
|
||||
doc='print to log file (default: true)',
|
||||
),
|
||||
StructFieldDecl(
|
||||
name='logfile',
|
||||
type=ArrayType(
|
||||
inner_type=ValueType(name='char'),
|
||||
extents=(1024,),
|
||||
),
|
||||
doc='log file path (default: "MUJOCO_LOG.TXT")',
|
||||
),
|
||||
StructFieldDecl(
|
||||
name='topics',
|
||||
type=ValueType(name='int'),
|
||||
doc='enabled info topic bitmask (default: 0)',
|
||||
),
|
||||
),
|
||||
)),
|
||||
('mjLROpt',
|
||||
StructDecl(
|
||||
name='mjLROpt',
|
||||
|
||||
Reference in New Issue
Block a user