Module base module

Module console

Console access object

Global object. Can be used for prompt messages, warnings and error logging. By launching the configuration file, you can locate logs to different devices for easy tracking. The log supports formatted output, for example:

1
console.log("%d + %d = %d", 100, 200, 100 + 200);

The formatting parameters that can be used are:

  • % s-string
  • % d-number, including integers and numbers
  • % j-output object in JSON format
  • %%-output character '%' itself

Static function

add

Add console output system, the supported devices are console, syslog, event, you can add up to 10 outputs

1
static console.add(String type);

Call parameters:

  • type : String, output device

By configuring the console, you can send program output and system errors to different devices for collecting operating environment information.

type is the configuration and is the device name string:

1
console.add("console");

syslog is only valid on posix platforms:

1
console.add("syslog");

event is only valid on windows platforms:

1
console.add("event");

Add console output system. Supported devices are console, syslog, event and file. You can add up to 10 outputs.

1
static console.add(Object cfg);

Call parameters:

  • cfg : Object, output configuration

By configuring the console, you can send program output and system errors to different devices for collecting operating environment information.

cfg can configure objects for a device:

1 2 3 4
console.add({ type: "console", levels: [console.INFO, console.ERROR] // 选项,省略则输出全部级别日志 });

syslog is only valid on posix platforms:

1 2 3 4
console.add({ type: "syslog", levels: [console.INFO, console.ERROR] });

event is only valid on windows platforms:

1 2 3 4
console.add({ type: "event", levels: [console.INFO, console.ERROR] });

file log:

1 2 3 4 5 6 7 8 9 10
console.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. Supported devices are console, syslog, event and file. You can add up to 10 outputs.

1
static console.add(Array cfg);

Call parameters:

  • cfg : Array, output configuration array

By configuring the console, you can send program output and system errors to different devices for collecting operating environment information.

1 2 3 4
console.add(["console", { type: "syslog", levels: [console.INFO, console.ERROR] }]);

reset

Initialize to default settings, only output information in the console

1
static console.reset();

log

Record ordinary log information, equivalent to info

1 2
static console.log(String fmt, ...args);

Call parameters:

  • fmt : String, formatted string
  • args : ..., optional parameter list

Record general level log information. Usually used to output non-error messages.


Record ordinary log information, equivalent to info

1
static console.log(...args);

Call parameters:

  • args : ..., optional parameter list

Record general level log information. Usually used to output non-error messages.


debug

Record debug log information

1 2
static console.debug(String fmt, ...args);

Call parameters:

  • fmt : String, formatted string
  • args : ..., optional parameter list

Record debug log information. Usually used to output debugging information. unimportant.


Record debug log information

1
static console.debug(...args);

Call parameters:

  • args : ..., optional parameter list

Record debug log information. Usually used to output debugging information. unimportant.


info

Record ordinary log information, which is equivalent to log

1 2
static console.info(String fmt, ...args);

Call parameters:

  • fmt : String, formatted string
  • args : ..., optional parameter list

Record general level log information. Usually used to output non-error messages.


Record ordinary log information, which is equivalent to log

1
static console.info(...args);

Call parameters:

  • args : ..., optional parameter list

Record general level log information. Usually used to output non-error messages.


notice

Record warning log information

1 2
static console.notice(String fmt, ...args);

Call parameters:

  • fmt : String, formatted string
  • args : ..., optional parameter list

Record warning log information. It is usually used to output prompt debugging information. Generally important.


Record warning log information

1
static console.notice(...args);

Call parameters:

  • args : ..., optional parameter list

Record warning log information. It is usually used to output prompt debugging information. Generally important.


warn

Record warning log information

1 2
static console.warn(String fmt, ...args);

Call parameters:

  • fmt : String, formatted string
  • args : ..., optional parameter list

Record warning log information. Usually used to output warning debugging information. important.


Record warning log information

1
static 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 2
static console.error(String fmt, ...args);

Call parameters:

  • fmt : String, formatted string
  • args : ..., optional parameter list

Records information for error logging. Usually used to output error messages. Very important. System error messages are also recorded at this level.


Record error log information

1
static console.error(...args);

Call parameters:

  • args : ..., optional parameter list

Records information for error logging. Usually used to output error messages. Very important. System error messages are also recorded at this level.


crit

Record critical error log information

1 2
static console.crit(String fmt, ...args);

Call parameters:

  • fmt : String, formatted string
  • args : ..., optional parameter list

Records critical error log information. Usually used to output critical error messages. Very important.


Record critical error log information

1
static console.crit(...args);

Call parameters:

  • args : ..., optional parameter list

Records critical error log information. Usually used to output critical error messages. Very important.


alert

Log alert error log information

1 2
static console.alert(String fmt, ...args);

Call parameters:

  • fmt : String, formatted string
  • args : ..., optional parameter list

Records log information for alert errors. Usually used to output alarm error messages. Very important. Is the highest level of information.


Log alert error log information

1
static console.alert(...args);

Call parameters:

  • args : ..., optional parameter list

Records log information for alert errors. Usually used to output alarm error messages. Very important. Is the highest level of information.


dir

Output objects in JSON format

1
static console.dir(Value obj);

Call parameters:

  • obj : Value, given the object to be displayed

time

Start a timer

1
static console.time(String label = "time");

Call parameters:

  • label : String, title, default is empty string.

timeElapse

Output the current value of the specified timer

1
static console.timeElapse(String label = "time");

Call parameters:

  • label : String, title, default is empty string.

timeEnd

End the specified timer and output the last time value

1
static console.timeEnd(String label = "time");

Call parameters:

  • label : String, title, default is empty string.

trace

Print the current call stack

1
static console.trace(String label = "trace");

Call parameters:

  • label : String, title, default is empty string.

Print the current call stack through the log.


assert

Assertion test, if the test value is false, an error is reported

1 2
static console.assert(Value value, String msg = "");

Call parameters:

  • value : Value, the value of the test
  • msg : String, error message

print

Output formatted text to the console. The output will not be recorded in the log system. After the text is output, it will not be automatically wrapped. It can be output continuously.

1 2
static console.print(String fmt, ...args);

Call parameters:

  • fmt : String, formatted string
  • args : ..., optional parameter list

Output formatted text to the console. The output will not be recorded in the log system. After the text is output, it will not be automatically wrapped. It can be output continuously.

1
static console.print(...args);

Call parameters:

  • args : ..., optional parameter list

moveTo

Move the console cursor to the specified position

1 2
static console.moveTo(Integer row, Integer column);

Call parameters:

  • row : Integer, specifies the row coordinates of the new cursor
  • column : Integer, specifies the column coordinates of the new cursor

hideCursor

Hide console cursor

1
static console.hideCursor();

showCursor

Show console cursor

1
static console.showCursor();

clear

Clear console

1
static console.clear();

keyDown

Press a button

1 2
static console.keyDown(String key, String modifier = "");

Call parameters:

  • key : String, specified key, single character is directly passed in, function key is passed in name
  • modifier : String, specifies the control key, which can be: control, alt, shift, command

The parameter key can be passed as a function key using a string:

  • Function keys: f1-f12
  • 方向键:up , down, left, right, home, end, pageup, pagedown
  • 编辑键:backspace , delete, insert, enter, tab, escape, space
  • 控制键:control , alt, shift, command

Press a button

1 2
static console.keyDown(String key, Array modifier);

Call parameters:

  • key : String, specified key, single character is directly passed in, function key is passed in name
  • modifier : Array, specifies the control key array, which can be: control, alt, shift, command

The parameter key can be passed as a function key using a string:

  • Function keys: f1-f12
  • 方向键:up , down, left, right, home, end, pageup, pagedown
  • 编辑键:backspace , delete, insert, enter, tab, escape, space
  • 控制键:control , alt, shift, command

keyUp

Release a key

1 2
static console.keyUp(String key, String modifier = "");

Call parameters:

  • key : String, specified key, single character is directly passed in, function key is passed in name
  • modifier : String, specifies the control key, which can be: control, alt, shift, command

The parameter key can be passed as a function key using a string:

  • Function keys: f1-f12
  • 方向键:up , down, left, right, home, end, pageup, pagedown
  • 编辑键:backspace , delete, insert, enter, tab, escape, space
  • 控制键:control , alt, shift, command

Release a key

1 2
static console.keyUp(String key, Array modifier);

Call parameters:

  • key : String, specified key, single character is directly passed in, function key is passed in name
  • modifier : Array, specifies the control key array, which can be: control, alt, shift, command

The parameter key can be passed as a function key using a string:

  • Function keys: f1-f12
  • 方向键:up , down, left, right, home, end, pageup, pagedown
  • 编辑键:backspace , delete, insert, enter, tab, escape, space
  • 控制键:control , alt, shift, command

keyTap

Click and release a button

1 2
static console.keyTap(String key, String modifier = "");

Call parameters:

  • key : String, specified key, single character is directly passed in, function key is passed in name
  • modifier : String, specifies the control key, which can be: control, alt, shift, command

The parameter key can be passed as a function key using a string:

  • Function keys: f1-f12
  • 方向键:up , down, left, right, home, end, pageup, pagedown
  • 编辑键:backspace , delete, insert, enter, tab, escape, space
  • 控制键:control , alt, shift, command

Click and release a button

1 2
static console.keyTap(String key, Array modifier);

Call parameters:

  • key : String, specified key, single character is directly passed in, function key is passed in name
  • modifier : Array, specifies the control key array, which can be: control, alt, shift, command

The parameter key can be passed as a function key using a string:

  • Function keys: f1-f12
  • 方向键:up , down, left, right, home, end, pageup, pagedown
  • 编辑键:backspace , delete, insert, enter, tab, escape, space
  • 控制键:control , alt, shift, command

typeString

Enter a string

1
static console.typeString(String text);

Call parameters:

  • text : String, specify the input string

moveMouse

Move the mouse to the specified position

1 2
static console.moveMouse(Integer x, Integer y);

Call parameters:

  • x : Integer, specify x coordinate
  • y : Integer, specify the y coordinate

mouseUp

Press a mouse button

1
static console.mouseUp(String button);

Call parameters:

  • button : String, specifies the name of the mouse button. Allowed values ​​are: left, right, moddle

mouseDown

Let go of a mouse button

1
static console.mouseDown(String button);

Call parameters:

  • button : String, specifies the name of the mouse button. Allowed values ​​are: left, right, moddle

clickMouse

Click a mouse button

1 2
static console.clickMouse(String button, Boolean dbclick = false);

Call parameters:

  • button : String, specifies the name of the mouse button. Allowed values ​​are: left, right, moddle
  • dbclick : Boolean, specify whether to double-click, default is false

readLine

Read user input from the console

1
static String console.readLine(String msg = "") async;

Call parameters:

  • msg : String, prompt

Returns the result:

  • String , return information entered by the user

getpass

Read the password entered by the user from the console

1
static String console.getpass(String msg = "") async;

Call parameters:

  • msg : String, prompt

Returns the result:

  • String , return the password entered by the user

Static property

loglevel

Integer, output level, used to filter output information, the default is NOTSET, all output. After filtering, the information will be output to each device set by add.

1
static Integer console.loglevel;

width

Integer, query terminal characters per line

1
static readonly Integer console.width;

height

Integer, query terminal rows

1
static readonly Integer console.height;

constant

FATAL

loglevel level constant

1
const console.FATAL = 0;

ALERT

loglevel level constant

1
const console.ALERT = 1;

CRIT

loglevel level constant

1
const console.CRIT = 2;

ERROR

loglevel level constant

1
const console.ERROR = 3;

WARN

loglevel level constant

1
const console.WARN = 4;

NOTICE

loglevel level constant

1
const console.NOTICE = 5;

INFO

loglevel level constant

1
const console.INFO = 6;

DEBUG

loglevel level constant

1
const console.DEBUG = 7;

PRINT

loglevel is only used for output, no newline after outputting information, file and syslog do not save this level

1
const console.PRINT = 9;

NOTSET

loglevel level constant

1
const console.NOTSET = 10;