Console & log output functions. Puts something to log with log levels depending on method.
In case of command line - echo to stdout
.
Arguments, passed to console output functions are transformed to string using util.format call.
Do not create this class directly - use global console already created by UB
console.log('%s is a %s usually with weight less then %dgr', 'apple', 'fruit', 100) //Will output "apple is a fruit usually with weight less than 100gr"
console.log('apple', 'fruit', 100) //will output "apple fruit 100"
console.debug('something') // will output to log only if "Debug" level is serverConfig.logging.levels
console.warn('warning message')
console.error('error message')
# new Console ()
Methods
# assert (expression) instance
Similar to assert#ok, but the error message is formatted as util.format(message...).
Arguments:
expression
:
# debug (: *) instance
Output to log with log level Debug
Arguments:
: *
# dir (object: Object) instance
Uses util.inspect on obj and prints resulting string to stdout.
Arguments:
object
: Object
# error (: *) instance
Output to log with log level Error
. In case of OS console echo output to stderr
Arguments:
: *
# info (: *) instance
Output to log with log level Info
(alias for console.log)
Arguments:
: *
# log (: *) instance
Output to log with log level Info
. Internally use util.format for create output, so
format chars can be used:
-
%s - String.
-
%d - Number (both integer and float).
-
%j - JSON.
-
% - single percent sign ('%'). This does not consume an argument.
console.log('%s is a %s usually with weight less than %dgr', 'apple', 'fruit', 100); //Will output "apple is a fruit usually with weight less than 100gr"
console.log('apple', 'fruit', 100); //will output "apple fruit 100"
console.log('the object JSON is %j', {a: 12, b: {inner: 11}}); // will output a JSON object instead of [object Object]
Arguments:
: *
# readLn () → string instance
Read line from stdin. The end of the line is marked by any of the supported line ending styles, independent of the platform on which the code is running (supported line ending styles are CRLF, LF or CR).
The end-of-line marker is not considered part of the line and is ignored.
console.write('Enter your name:')
const name = console.readLn()
console.write('Hello, ', name, '!')
# time (label: String) instance
Mark a time.
Arguments:
label
: String
# timeEnd (label: string) instance
Finish timer, record output
Arguments:
label
: string
console.time('100-elements');
for (var i = 0; i < 100; i++) {
;
}
console.timeEnd('100-elements');
# traceFunc (f: function, eventName: string, objName: string) instance
If Trace
log level is enabled for application and !f._skipEmitterTrace
- trace to log what function is called
# warn (: *) instance
Output to log with log level Warning
. In case of OS console echo output to stderr
Arguments:
: *
# write (value: *) instance
Write to stdout
Arguments:
value
: *
console.write('Hello! \n Today is', 2023)