Record Logs

Function Description

When user-compiled scripts are running on a device, some information is recorded in the device's log.

Command Prototype

opsObj.syslog(content, severity="informational", logtype="syslog")

Parameter Description

Table 1 describes the parameters supported by APIs for recording logs.
Table 1 Parameters supported by APIs for recording logs

Method

Description

opsObj

Specifies an OPS object. It is obtained through ops.ops() instantiation.

content

Specifies the log content. The maximum length of the character string is 512 bytes. If the length exceeds 512 bytes, the log fails to be recorded.

severity

Specifies a log level, which can be CRITICAL, ERROR, WARNING, or INFORMATIONAL (in descending order). The default level is INFORMATIONAL.

logtype

Specifies a log type, which can be syslog or diagnose. If syslog is specified, information is recorded in the syslog. After a syslog server is configured, the syslog is uploaded to the syslog server. If diagnose is specified, information is recorded in the diagnostic log on the device. The default value is syslog.

Description of Return Values

  • First return value: The value 0 indicates a success, and the value 1 indicates a failure.
  • Second return value: This value describes success or failure reasons, expressed in a character string.

Example

test.py

import ops

opsObj = ops.ops()
opsObj.syslog("Record an informational syslog.")

After the script is run, information is recorded in the syslog.

Copyright © Huawei Technologies Co., Ltd.
Copyright © Huawei Technologies Co., Ltd.
< Previous topic Next topic >