Module basic module

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:

1
console.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

1
static 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:

1
console.add("console");

syslog is only valid on posix platform:

1
console.add("syslog");

event is only valid on windows platform:

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, 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 4
console.add({ type: "console", levels: [console.INFO, console.ERROR] // 选项,省略则输出全部级别日志 });

syslog is only valid on posix platform:

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

event is only valid on windows platform:

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. The 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, program output and system errors can be sent 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 the default settings, only output information in the console

1
static console.reset();

log

Record common log information, equivalent to info

1 2
static 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

1
static 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 2
static 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

1
static 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, equivalent to log

1 2
static 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, 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 prompt information.


notice

Record warning log information

1 2
static 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

1
static 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 2
static 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

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, 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

1
static 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 2
static 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

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

Call parameters:

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

Record the error log information for alarm. Usually used to output alarm error messages. Very important. The highest level of information.


Record alarm error log information

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

Call parameters:

  • args : ..., optional parameter list

Record the error log information for alarm. Usually used to output alarm error messages. Very important. 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, the default is an empty string.

timeElapse

Output the current value of the specified timer

1
static 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

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

Call parameters:

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

trace

Output current call stack

1
static 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 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 content will not be recorded in the log system, the text will not automatically wrap after the output, and can be output continuously

1 2
static 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

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, specify the row coordinates of the new cursor
  • column : Integer, specify 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, 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
  • 方向键: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, designated key, single character is directly passed in, function key is passed in name
  • modifier : Array, specify the control key array, can be: control, alt, shift, command

The parameter key can use a string to pass in the function key:

  • 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 button

1 2
static 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
  • 方向键:up , down, left, right, home, end, pageup, pagedown
  • 编辑键:backspace , delete, insert, enter, tab, escape, space
  • 控制键:control , alt, shift, command

Release a button

1 2
static 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 the control key array, can be: control, alt, shift, command

The parameter key can use a string to pass in the function key:

  • 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, 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
  • 方向键: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, designated key, single character is directly passed in, function key is passed in name
  • modifier : Array, specify the control key array, can be: control, alt, shift, command

The parameter key can use a string to pass in the function key:

  • 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 the x coordinate
  • y : Integer, specify the y coordinate

mouseUp

Press a mouse button

1
static 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

1
static 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 2
static 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

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

Call parameters:

  • msg : String, prompt message

Return result:

  • String , returns the 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 message

Return result:

  • String , returns 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.

1
static Integer console.loglevel;

width

Integer, query the number of characters per line of the terminal

1
static readonly Integer console.width;

height

Integer, query the number of terminal rows

1
static readonly Integer console.height;

constant

FATAL

loglevel constant

1
const console.FATAL = 0;

ALERT

loglevel constant

1
const console.ALERT = 1;

CRIT

loglevel constant

1
const console.CRIT = 2;

ERROR

loglevel constant

1
const console.ERROR = 3;

WARN

loglevel constant

1
const console.WARN = 4;

NOTICE

loglevel constant

1
const console.NOTICE = 5;

INFO

loglevel constant

1
const console.INFO = 6;

DEBUG

loglevel constant

1
const console.DEBUG = 7;

PRINT

loglevel is only used for output, the information will not wrap after output, file and syslog will not save this level

1
const console.PRINT = 9;

NOTSET

loglevel constant

1
const console.NOTSET = 10;