Module basic module

Module console

Console access object

The console module is a core module that provides functions similar to the console object in the browser. It can output information to the console to facilitate debugging and output information.

The most commonly used method in the console module is log(), which prints any JavaScript value to the console, automatically adding newlines. In addition to the log() method, there are also info(), warn(), and error() methods, which are used to output information, warnings, and errors respectively. Their functions are basically the same as the log() method, except for the style displayed in the console. different.

The console module also provides the dir() method, which is used to output the properties and methods of an object to the console in a more readable form, making it easier to debug complex objects. In addition, there are time() and timeEnd() methods for timing code execution in the console and outputting the time difference.

In addition to the above commonly used methods, the console module also provides some other methods, such asassert(), notice(), trace(), etc., can facilitate debugging and information output in different situations.

The console module is a very practical module that can improve debugging efficiency during the development process and output various information conveniently and quickly.

static function

add

Add a console output system. Supported devices are console, syslog, and event. Up to 10 outputs can be added.

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 collection of running environment information.

type is the configuration and 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. Up to 10 outputs can be added.

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 collection of running environment information.

cfg can configure objects for a device:

1 2 3 4
console.add({ type: "console", levels: [console.INFO, console.ERROR] // optional, default is all levels });

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
console.add({ type: "file", levels: [console.INFO, console.ERROR], path: "path/to/file_%s.log", // specifies the log output file, can use %s to specify the insertion date location, or add at the end if not specified split: "30m", // Optional values are "day", "hour", "minute", "####k", "####m", "####g", default is "1m" count: 10 // option, selectable from 2 to 128, default is 128 });

Add console output systems in batches. Supported devices are console, syslog, event and file. Up to 10 outputs can be added.

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 collection of running environment information.

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

reset

Initialize to default settings and only output information to the console.

1
static console.reset();

log

Record common log information, which is 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, which is 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 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 common log information, which is 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, 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 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 informative 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 informative 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

Records information for error logs. Usually used to output error messages. Very important. System error messages will also be logged at this level.


Record error log information

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

Call parameters:

  • args: ..., optional parameter list

Records information for error logs. Usually used to output error messages. Very important. System error messages will also be logged at this level.


crit

Record key 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 information. Very important.


Record key 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 information. Very important.


alert

Record alert error log information

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

Call parameters:

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

Records error log messages for alerts. Usually used to output alert error messages. Very important. is the highest level of information.


Record alert error log information

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

Call parameters:

  • args: ..., optional parameter list

Records error log messages for alerts. Usually used to output alert error messages. Very important. is the highest level of information.


trace

Output the current call stack

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

Call parameters:

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

Output the current call stack through the log.


Output the current call stack

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

Call parameters:

  • args: ..., optional parameter list

Output the current call stack through the log.


dir

Output objects in JSON format

1 2
static console.dir(Value obj, Object options = {});

Call parameters:

  • obj: Value, specifies the object to be processed
  • options: Object, specify format control options

The following parameters are supported:

1 2 3 4 5 6 7 8 9
{ "colors": false, // specify if output should be colorized, defaults to false "depth": 2, // specify the max depth of the output, defaults to 2 "table": false, // specify if output should be a table, defaults to false "encode_string": true, // specify if string should be encoded, defaults to true "maxArrayLength": 100, // specify max number of array elements to show, set to 0 or negative to show no elements, defaults to 100 "maxStringLength": 10000, // specify max string length to output, set to 0 or negative to show no strings, defaults to 10000 "fields": [], // specify the fields to be displayed, defaults to all }

table

Output objects in JSON format

1
static console.table(Value obj);

Call parameters:

  • obj: Value, given the object to be displayed

Output objects in JSON format

1 2
static console.table(Value obj, Array fields);

Call parameters:

  • obj: Value, given the object to be displayed
  • fields: Array, given the fields 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 timing 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.

assert

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

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

Call parameters:

  • value: Value, the value to be tested
  • 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 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 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, specifies the row coordinate 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();

readLine

Read user input from console

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

Call parameters:

  • msg: String, prompt message

Return results:

  • 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 results:

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

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. There is no line break after the information is output. File and syslog do not save this level information.

1
const console.PRINT = 9;

NOTSET

loglevel level constant

1
const console.NOTSET = 10;