Difference between revisions of "Program Examples:sys log"
| (5 intermediate revisions by one other user not shown) | |||
| Line 1: | Line 1: | ||
| + | {{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' 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. | We've enabled this feature in MC-Basic context as well. | ||
| Line 17: | Line 18: | ||
[[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== | ==Sending strings to sys.log from MC-Basic context== | ||
| − | Globally load the MC library SYSLOG.LIB. | + | Globally load the MC library SYSLOG.LIB.<br/> |
Invoke the function<br/> | Invoke the function<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/> | ||
| Line 23: | Line 24: | ||
Where the arguments are:<br/> | Where the arguments are:<br/> | ||
| − | debug_level - Use one of the following constants: | + | <u>debug_level</u> - Use one of the following constants: |
MC_BASIC_LOG_LEVEL_NON = 0<br/> | MC_BASIC_LOG_LEVEL_NON = 0<br/> | ||
| Line 37: | Line 38: | ||
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/> | 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/> | ||
| − | log_str - A string in printf format<br/> | + | <u>log_str</u> - A string in printf format<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|The string variable used by the function log_msg must be declared GLOBAL as <u>common shared</u> or undefined behavior is expected}} | ||
<br/> | <br/> | ||
| − | arg1 to arg10 - 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> - Variables of type <u>LONG</u> that correspond with log_str printf format string. Unused arguments can be set to zero.<br/> |
<br/> | <br/> | ||
log_msg returns 0 if successful or -1 on failure.<br/> | log_msg returns 0 if successful or -1 on failure.<br/> | ||
| Line 69: | Line 70: | ||
<br/><br/> | <br/><br/> | ||
[[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/> | ||
| + | Extract SYSLOG.ZIP to find SYSLOG.LIB<br/> | ||
| + | [[File:SYSLOG.zip||SYSLOG.zip]] | ||
Latest revision as of 07:11, 17 July 2017
| Language: | English • 中文(简体) |
|---|
'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.
Contents
Printing sys.log
To print sys.log do the following:
1. Connect to the softMC using ssh or serial console.
2. To print the entire log, type in the Linux terminal:
-bash-3.2$ cat /var/sys.log
or
3. To print the last few lines, type in the Linux terminal:
-bash-3.2$ tail -50 /var/sys.log
where '50' is the number of lines that will be printed from the end of the file.
Sending strings to sys.log from MC-Basic context
Globally load the MC library SYSLOG.LIB.
Invoke the function
log_msg(byval debug_level as long, byval log_str as string, byval arg1 as long, arg2, arg3..., arg10) as long
Where the arguments are:
debug_level - Use one of the following constants:
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 | |
| Debug level can be set by using telnet |
A log message at debug level MC_BASIC_LOG_LEVEL_ERROR will always be displayed in sys.log.
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.
log_str - A string in printf format
| IMPORTANT | |
| The string variable used by the function log_msg must be declared GLOBAL as common shared or undefined behavior is expected |
arg1 to arg10 - Variables of type LONG that correspond with log_str printf format string. Unused arguments can be set to zero.
log_msg returns 0 if successful or -1 on failure.
Example
The following is an MC program that sends a string to sys.log
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
Displaying sys.log after sending a string by typing in the Linux terminal:
-bash-3.2$ cat /var/sys.log
Downloads
SYSLOG library - corresponding to softMC's formal release version ECAT 0.4.13.2rc2
Extract SYSLOG.ZIP to find SYSLOG.LIB
File:SYSLOG.zip