Difference between revisions of "Program Examples:sys log/zh-hans"

From SoftMC-Wiki
Jump to: navigation, search
(Created page with "{{Languages}} 'sys.log' is a Linux logger that allows the programmer to document strings while his program is running. We've enabled this feature in MC-Basic context as well. ...")
 
 
Line 1: Line 1:
{{Languages}}
+
{{Languages|Program_Examples:sys_log}}
'sys.log' is a Linux logger that allows the programmer to document strings while his program is running.
+
'sys.log'是一个Linux记录器,允许程序员在程序运行时对其进行文档化。 我们已经在MC-Basic中启用了此功能。
We've enabled this feature in MC-Basic context as well.
 
  
==Printing sys.log==
+
==打印sys.log==
To print sys.log do the following:<br/>
+
要打印sys.log,请执行以下操作:<br/>
1. Connect to the softMC using ssh or serial console.<br/>
+
1. 使用ssh或串口控制台连接到softMC。<br/>
2. To print the entire log, type in the Linux terminal:
+
2. 要打印整个日志,在Linux终端键入:
 
<pre>
 
<pre>
 
-bash-3.2$ cat /var/sys.log
 
-bash-3.2$ cat /var/sys.log
 
</pre>
 
</pre>
 
or<br/>
 
or<br/>
3. To print the last few lines, type in the Linux terminal:
+
3. 要打印最后几行,在Linux终端键入:
 
<pre>
 
<pre>
 
-bash-3.2$ tail -50 /var/sys.log
 
-bash-3.2$ tail -50 /var/sys.log
 
</pre>
 
</pre>
where '50' is the number of lines that will be printed from the end of the file.<br/><br/>
+
其中'50'是从文件末尾打印的行数。<br/><br/>
 
[[Image:sys_log.PNG||display last 20 lines of sys.log]]
 
[[Image:sys_log.PNG||display last 20 lines of sys.log]]
==Sending strings to sys.log from MC-Basic context==
+
==从MC-Basic发送字符串到sys.log==
Globally load the MC library SYSLOG.LIB.<br/>
+
全局加载MC库SYSLOG.LIB<br/>
Invoke the function<br/>
+
调用函数<br/>
 
log_msg(byval debug_level as long, byval log_str as string, byval arg1 as long, arg2, arg3..., arg10) as long<br/>
 
log_msg(byval debug_level as long, byval log_str as string, byval arg1 as long, arg2, arg3..., arg10) as long<br/>
 
<br/>
 
<br/>
Where the arguments are:<br/>
+
这里参数是:<br/>
  
<u>debug_level</u> - Use one of the following constants:
+
<u>debug_level</u> - 使用以下常量之一:
  
 
MC_BASIC_LOG_LEVEL_NON = 0<br/>
 
MC_BASIC_LOG_LEVEL_NON = 0<br/>
Line 33: Line 32:
 
MC_BASIC_LOG_LEVEL_ALL = 5<br/>
 
MC_BASIC_LOG_LEVEL_ALL = 5<br/>
 
<br/>
 
<br/>
{{Note/Important|Debug level can be set by using telnet}}
+
{{Note/Important|可以使用telnet设置调试级别}}
 
<br/>
 
<br/>
A log message at debug level MC_BASIC_LOG_LEVEL_ERROR will always be displayed in sys.log.<br/>
+
调试级别MC_BASIC_LOG_LEVEL_ERROR中的日志消息将始终显示在sys.log中<br/>
A log message at debug level MC_BASIC_LOG_LEVEL_DEBUG will be displayed in sys.log if the debug level of MC-BASIC in softMC is set to DEBUG.<br/>
+
如果softMC中MC-BASIC的调试级别设置为DEBUG,则调试级别MC_BASIC_LOG_LEVEL_DEBUG中的日志消息将显示在sys.log中。<br/>
  
<u>log_str</u> - A string in printf format<br/>
+
<u>log_str</u> - 以printf格式的字符串<br/>
 
<br/>
 
<br/>
{{Note/Important|The string variable used by the function log_msg must be declared GLOBAL as <u>common shared</u> or undefined behavior is expected}}
+
{{Note/Important|由函数log_msg使用的字符串变量必须声明为GLOBAL,因为可能会有<u>common shared</u>的或未定义的行为。}}
 
<br/>
 
<br/>
<u>arg1 to arg10</u> - Variables of type <u>LONG</u> that correspond with log_str printf format string. Unused arguments can be set to zero.<br/>
+
<u>arg1 to arg10</u> -与log_str printf格式字符串对应的类型为<u>LONG</u>的变量。 未使用的参数可以设置为零。<br/>
 
<br/>
 
<br/>
log_msg returns 0 if successful or -1 on failure.<br/>
+
如果成功,log_msg返回0,失败时返回-1。<br/>
  
==Example==
+
==例子==
  
The following is an MC program that sends a string to sys.log<br/>
+
以下是向sys.log发送字符串的MC程序。<br/>
 
<syntaxhighlight lang="vb">
 
<syntaxhighlight lang="vb">
 
common shared log_string as string = "Example string. x = %d. y = %d"
 
common shared log_string as string = "Example string. x = %d. y = %d"
Line 64: Line 63:
 
[[Image:SYSLOG1.PNG||Globally load SYSLOG.LIB]]
 
[[Image:SYSLOG1.PNG||Globally load SYSLOG.LIB]]
 
<br/><br/>
 
<br/><br/>
Displaying sys.log after sending a string by typing in the Linux terminal:<br/>
+
通过在Linux终端中键入发送字符串后显示sys.log:<br/>
 
<pre>
 
<pre>
 
-bash-3.2$ cat /var/sys.log
 
-bash-3.2$ cat /var/sys.log
Line 71: Line 70:
 
[[Image:SYSLOG2.PNG||sys.log example]]
 
[[Image:SYSLOG2.PNG||sys.log example]]
  
==Downloads==
+
==下载==
SYSLOG library - corresponding to softMC's formal release version ECAT 0.4.13.2rc2<br/>
+
SYSLOG库 - 对应于softMC的正式版本ECAT 0.4.13.2rc2<br/>
Extract SYSLOG.ZIP to find SYSLOG.LIB<br/>
+
提取SYSLOG.ZIP以查找SYSLOG.LIB<br/>
 
[[File:SYSLOG.zip||SYSLOG.zip]]
 
[[File:SYSLOG.zip||SYSLOG.zip]]

Latest revision as of 07:22, 17 July 2017

语言: English  • 中文(简体)‎

'sys.log'是一个Linux记录器,允许程序员在程序运行时对其进行文档化。 我们已经在MC-Basic中启用了此功能。

打印sys.log

要打印sys.log,请执行以下操作:
1. 使用ssh或串口控制台连接到softMC。
2. 要打印整个日志,在Linux终端键入:

-bash-3.2$ cat /var/sys.log

or
3. 要打印最后几行,在Linux终端键入:

-bash-3.2$ tail -50 /var/sys.log

其中'50'是从文件末尾打印的行数。

display last 20 lines of sys.log

从MC-Basic发送字符串到sys.log

全局加载MC库SYSLOG.LIB
调用函数
log_msg(byval debug_level as long, byval log_str as string, byval arg1 as long, arg2, arg3..., arg10) as long

这里参数是:

debug_level - 使用以下常量之一:

MC_BASIC_LOG_LEVEL_NON = 0
MC_BASIC_LOG_LEVEL_ERROR = 1
MC_BASIC_LOG_LEVEL_WARNING = 2
MC_BASIC_LOG_LEVEL_NOTE = 3
MC_BASIC_LOG_LEVEL_DEBUG = 4
MC_BASIC_LOG_LEVEL_ALL = 5

IMPORTANT.svgIMPORTANT
可以使用telnet设置调试级别


调试级别MC_BASIC_LOG_LEVEL_ERROR中的日志消息将始终显示在sys.log中
如果softMC中MC-BASIC的调试级别设置为DEBUG,则调试级别MC_BASIC_LOG_LEVEL_DEBUG中的日志消息将显示在sys.log中。

log_str - 以printf格式的字符串

IMPORTANT.svgIMPORTANT
由函数log_msg使用的字符串变量必须声明为GLOBAL,因为可能会有common shared的或未定义的行为。


arg1 to arg10 -与log_str printf格式字符串对应的类型为LONG的变量。 未使用的参数可以设置为零。

如果成功,log_msg返回0,失败时返回-1。

例子

以下是向sys.log发送字符串的MC程序。

common shared log_string as string = "Example string. x = %d. y = %d"

Program

        dim x as long = 5
        dim y as long = 99

        ?log_msg(MC_BASIC_LOG_LEVEL_ERROR, log_string, x, y, 0,0,0,0,0,0,0,0)

End Program


Globally load SYSLOG.LIB

通过在Linux终端中键入发送字符串后显示sys.log:

-bash-3.2$ cat /var/sys.log



sys.log example

下载

SYSLOG库 - 对应于softMC的正式版本ECAT 0.4.13.2rc2
提取SYSLOG.ZIP以查找SYSLOG.LIB
File:SYSLOG.zip