Module console
Console access object
Global object. Can be used for prompt information, warning and error logging. By starting the configuration file, the logs can be located to different devices for easy tracking. The log supports formatted output, for example:
1console.log("%d + %d = %d", 100, 200, 100 + 200);
The formatting parameters that can be used are as follows:
- %s-string
- %d-numbers, including integers and numbers
- %j-output object in JSON format
- %%-the output character'%' itself
Static function
add
Add console output system, the supported devices are console, syslog, event, you can add up to 10 outputs
1static console.add(String type);
Call parameters:
- type: String, output device
By configuring the console, program output and system errors can be sent to different devices for collecting operating environment information.
type is the configuration, which is the device name string:
1console.add("console");
syslog is only valid on posix platform:
1console.add("syslog");
event is only valid on windows platform:
1console.add("event");
Add a console output system. The supported devices are console, syslog, event and file. You can add up to 10 outputs
1static console.add(Object cfg);
Call parameters:
- cfg: Object, output configuration
By configuring the console, program output and system errors can be sent to different devices for collecting operating environment information.
cfg can configure objects for a device:
1
2
3
4console.add({
type: "console",
levels: [console.INFO, console.ERROR] // 选项,省略则输出全部级别日志
});
syslog is only valid on posix platform:
1
2
3
4console.add({
type: "syslog",
levels: [console.INFO, console.ERROR]
});
event is only valid on windows platform:
1
2
3
4console.add({
type: "event",
levels: [console.INFO, console.ERROR]
});
file log:
1
2
3
4
5
6
7
8
9
10console.add({
type: "file",
levels: [console.INFO, console.ERROR],
// 必选项,指定日志输出文件,可使用 s% 指定插入日期位置,不指定则添加在结尾
path: "path/to/file_%s.log",
// 选项,可选值为 "day", "hour", "minute", "###k", "###m", "###g",缺省为 "1m"
split: "30m",
// 选项,可选范围为 2-128,缺省为 128
count: 10
});
Add console output system in batches. The supported devices are console, syslog, event and file. You can add up to 10 outputs
1static console.add(Array cfg);
Call parameters:
- cfg: Array, output configuration array
By configuring the console, program output and system errors can be sent to different devices for collecting operating environment information.
1
2
3
4console.add(["console", {
type: "syslog",
levels: [console.INFO, console.ERROR]
}]);
reset
Initialize to the default settings, only output information in the console
1static console.reset();
log
Record common log information, equivalent to info
1
2static console.log(String fmt,
...args);
Call parameters:
- fmt: String, format string
- args: ..., optional parameter list
Record general-level log information. Usually used to output non-error prompt information.
Record common log information, equivalent to info
1static console.log(...args);
Call parameters:
- args: ..., optional parameter list
Record general-level log information. Usually used to output non-error prompt information.
debug
Record debug log information
1
2static console.debug(String fmt,
...args);
Call parameters:
- fmt: String, format string
- args: ..., optional parameter list
Record debugging log information. Usually used to output debugging information. unimportant.
Record debug log information
1static console.debug(...args);
Call parameters:
- args: ..., optional parameter list
Record debugging log information. Usually used to output debugging information. unimportant.
info
Record common log information, which is equivalent to log
1
2static console.info(String fmt,
...args);
Call parameters:
- fmt: String, format string
- args: ..., optional parameter list
Record general-level log information. Usually used to output non-error prompt information.
Record common log information, which is equivalent to log
1static console.info(...args);
Call parameters:
- args: ..., optional parameter list
Record general-level log information. Usually used to output non-error prompt information.
notice
Record warning log information
1
2static console.notice(String fmt,
...args);
Call parameters:
- fmt: String, format string
- args: ..., optional parameter list
Record warning log information. Usually used to output prompt debugging information. Generally important.
Record warning log information
1static console.notice(...args);
Call parameters:
- args: ..., optional parameter list
Record warning log information. Usually used to output prompt debugging information. Generally important.
warn
Record warning log information
1
2static console.warn(String fmt,
...args);
Call parameters:
- fmt: String, format string
- args: ..., optional parameter list
Record warning log information. Usually used to output warning debugging information. important.
Record warning log information
1static console.warn(...args);
Call parameters:
- args: ..., optional parameter list
Record warning log information. Usually used to output warning debugging information. important.
error
Record error log information
1
2static console.error(String fmt,
...args);
Call parameters:
- fmt: String, format string
- args: ..., optional parameter list
Record information for error log. Usually used to output error messages. Very important. System error information will also be recorded at this level.
Record error log information
1static console.error(...args);
Call parameters:
- args: ..., optional parameter list
Record information for error log. Usually used to output error messages. Very important. System error information will also be recorded at this level.
crit
Record critical error log information
1
2static console.crit(String fmt,
...args);
Call parameters:
- fmt: String, format string
- args: ..., optional parameter list
Log information for critical errors. Usually used to output critical error messages. Very important.
Record critical error log information
1static console.crit(...args);
Call parameters:
- args: ..., optional parameter list
Log information for critical errors. Usually used to output critical error messages. Very important.
alert
Record alarm error log information
1
2static console.alert(String fmt,
...args);
Call parameters:
- fmt: String, format string
- args: ..., optional parameter list
Record error log information for alarms. Usually used to output alarm error messages. Very important. It is the highest level of information.
Record alarm error log information
1static console.alert(...args);
Call parameters:
- args: ..., optional parameter list
Record error log information for alarms. Usually used to output alarm error messages. Very important. It is the highest level of information.
dir
Output objects in JSON format
1static console.dir(Value obj);
Call parameters:
- obj: Value, given the object to be displayed
table
Output objects in JSON format
1static console.table(Value obj);
Call parameters:
- obj: Value, given the object to be displayed
Output objects in JSON format
1
2static console.table(Value obj,
Array fields);
Call parameters:
- obj: Value, given the object to be displayed
- fields: Array, given the field to be displayed
time
Start a timer
1static console.time(String label = "time");
Call parameters:
- label: String, title, the default is an empty string.
timeElapse
Output the current timing value of the specified timer
1static console.timeElapse(String label = "time");
Call parameters:
- label: String, title, the default is an empty string.
timeEnd
End the specified timer, and output the last timer value
1static console.timeEnd(String label = "time");
Call parameters:
- label: String, title, the default is an empty string.
trace
Output current call stack
1static console.trace(String label = "trace");
Call parameters:
- label: String, title, the default is an empty string.
Output the current call stack through the log.
assert
Assertion test, if the test value is false, an error is reported
1
2static console.assert(Value value,
String msg = "");
Call parameters:
- value: Value, the value of the test
- msg: String, error message
Output formatted text to the console, the output content will not be recorded in the log system, the text will not automatically wrap after the output, and can be output continuously
1
2static console.print(String fmt,
...args);
Call parameters:
- fmt: String, format string
- args: ..., optional parameter list
Output formatted text to the console, the output content will not be recorded in the log system, the text will not automatically wrap after the output, and can be output continuously
1static console.print(...args);
Call parameters:
- args: ..., optional parameter list
moveTo
Move the console cursor to the specified position
1
2static console.moveTo(Integer row,
Integer column);
Call parameters:
- row: Integer, specify the line coordinates of the new cursor
- column: Integer, specify the column coordinates of the new cursor
hideCursor
Hide the console cursor
1static console.hideCursor();
showCursor
Show console cursor
1static console.showCursor();
clear
Clear the console
1static console.clear();
keyDown
Press a button
1
2static console.keyDown(String key,
String modifier = "");
Call parameters:
- key: String, designated key, single character is directly passed in, function key is passed in name
- modifier: String, designated control key, can be: control, alt, shift, command
The parameter key can use a string to pass in the function key:
- Function keys: f1-f12
- Arrow keys: up, down, left, right, home, end, pageup, pagedown
- Edit keys: backspace, delete, insert, enter, tab, escape, space
- Control keys: control, alt, shift, command
Press a button
1
2static console.keyDown(String key,
Array modifier);
Call parameters:
- key: String, designated key, single character is directly passed in, function key is passed in name
- modifier: Array, specify an array of control keys, can be: control, alt, shift, command
The parameter key can use a string to pass in the function key:
- Function keys: f1-f12
- Arrow keys: up, down, left, right, home, end, pageup, pagedown
- Edit keys: backspace, delete, insert, enter, tab, escape, space
- Control keys: control, alt, shift, command
keyUp
Release a button
1
2static console.keyUp(String key,
String modifier = "");
Call parameters:
- key: String, designated key, single character is directly passed in, function key is passed in name
- modifier: String, designated control key, can be: control, alt, shift, command
The parameter key can use a string to pass in the function key:
- Function keys: f1-f12
- Arrow keys: up, down, left, right, home, end, pageup, pagedown
- Edit keys: backspace, delete, insert, enter, tab, escape, space
- Control keys: control, alt, shift, command
Release a button
1
2static console.keyUp(String key,
Array modifier);
Call parameters:
- key: String, designated key, single character is directly passed in, function key is passed in name
- modifier: Array, specify an array of control keys, can be: control, alt, shift, command
The parameter key can use a string to pass in the function key:
- Function keys: f1-f12
- Arrow keys: up, down, left, right, home, end, pageup, pagedown
- Edit keys: backspace, delete, insert, enter, tab, escape, space
- Control keys: control, alt, shift, command
keyTap
Click and release a button
1
2static console.keyTap(String key,
String modifier = "");
Call parameters:
- key: String, designated key, single character is directly passed in, function key is passed in name
- modifier: String, designated control key, can be: control, alt, shift, command
The parameter key can use a string to pass in the function key:
- Function keys: f1-f12
- Arrow keys: up, down, left, right, home, end, pageup, pagedown
- Edit keys: backspace, delete, insert, enter, tab, escape, space
- Control keys: control, alt, shift, command
Click and release a button
1
2static console.keyTap(String key,
Array modifier);
Call parameters:
- key: String, designated key, single character is directly passed in, function key is passed in name
- modifier: Array, specify an array of control keys, can be: control, alt, shift, command
The parameter key can use a string to pass in the function key:
- Function keys: f1-f12
- Arrow keys: up, down, left, right, home, end, pageup, pagedown
- Edit keys: backspace, delete, insert, enter, tab, escape, space
- Control keys: control, alt, shift, command
typeString
Enter a string
1static console.typeString(String text);
Call parameters:
- text: String, specify the input string
moveMouse
Move the mouse to the specified position
1
2static console.moveMouse(Integer x,
Integer y);
Call parameters:
- x: Integer, specify the x coordinate
- y: Integer, specify the y coordinate
mouseUp
Press a mouse button
1static console.mouseUp(String button);
Call parameters:
- button: String, specify the name of the mouse button, allowed values: left, right, moddle
mouseDown
Let go of a mouse button
1static console.mouseDown(String button);
Call parameters:
- button: String, specify the name of the mouse button, allowed values: left, right, moddle
clickMouse
Click a mouse button
1
2static console.clickMouse(String button,
Boolean dbclick = false);
Call parameters:
- button: String, specify the name of the mouse button, allowed values: left, right, moddle
- dbclick: Boolean, specify whether to double click, the default is false
readLine
Read user input from the console
1static String console.readLine(String msg = "") async;
Call parameters:
- msg: String, prompt message
Return result:
- String, Return the information entered by the user
getpass
Read the password entered by the user from the console
1static String console.getpass(String msg = "") async;
Call parameters:
- msg: String, prompt message
Return result:
- String, Return the password entered by the user
Static properties
loglevel
Integer, output level, used to filter output information, the default is NOTSET, all output. After the information is filtered, it will be output to each device set by add.
1static Integer console.loglevel;
width
Integer, query the number of characters in each line of the terminal
1static readonly Integer console.width;
height
Integer, query the number of terminal rows
1static readonly Integer console.height;
constant
FATAL
loglevel constant
1const console.FATAL = 0;
ALERT
loglevel constant
1const console.ALERT = 1;
CRIT
loglevel constant
1const console.CRIT = 2;
ERROR
loglevel constant
1const console.ERROR = 3;
WARN
loglevel constant
1const console.WARN = 4;
NOTICE
loglevel constant
1const console.NOTICE = 5;
INFO
loglevel constant
1const console.INFO = 6;
DEBUG
loglevel constant
1const console.DEBUG = 7;
loglevel is only used for output, the information will not wrap after output, file and syslog will not save this level information
1const console.PRINT = 9;
NOTSET
loglevel constant
1const console.NOTSET = 10;