debugtrace-js v2.2.0
debugtrace-js
debugtrace-js is a library that outputs trace logs when debugging JavaScript programs. It is available on Node.js 16 or later.
By embedding debugtrace.enter()
and debugtrace.leave()
at the start and end of functions, you can output the execution status of the JavaScript program under development to the log.
1. Features
- Automatically outputs invoker's function name, source file and line number.
- Automatically indents the log with nesting methods and objects.
- There are no dependent libraries at run time.
2. How to use
Do the following for debug target and related methods.
- Insert
debugtrace.enter()
at the beginning of functions. - Insert
debugtrace.leave()
at the end of functions or just before thereturn
statement. - Insert
debugtrace.print('foo', foo)
to output arguments, local variables and return value to the log if necessary.
The following is an example of JavaScript source used debugtrace-js methods and the log of when it has been executed.
// ReadmeExample.js
const debugtrace = require('debugtrace-js') // TODO: Debug
class Contact {
constructor(id, firstName, lastName, birthday) {
this.id = id
this.firstName = firstName
this.lastName = lastName
this.birthday = birthday
}
}
const func2 = () => {
debugtrace.enter() // TODO: Debug
let contacts = [
new Contact(1, 'Akane' , 'Apple', new Date(Date.UTC(1991, 2, 3))),
new Contact(2, 'Yukari', 'Apple', new Date(Date.UTC(1992, 3, 4)))
]
debugtrace.print('contacts', contacts) // TODO: Debug
debugtrace.leave() // TODO: Debug
}
const func1 = () => {
debugtrace.enter() // TODO: Debug
debugtrace.printMessage('Hello, World!')
func2()
debugtrace.leave() // TODO: Debug
}
func1()
2025-02-11 15:49:38.591+09:00 debugtrace-js 2.2.0 on Node.js 22.13.1
2025-02-11 15:49:38.617+09:00
2025-02-11 15:49:38.618+09:00 Enter func1 (ReadmeExample.js:25)
2025-02-11 15:49:38.618+09:00 | Hello, World! (ReadmeExample.js:26)
2025-02-11 15:49:38.618+09:00 | Enter func2 (ReadmeExample.js:15)
2025-02-11 15:49:38.620+09:00 | | contacts = [
2025-02-11 15:49:38.620+09:00 | | (Contact){
2025-02-11 15:49:38.620+09:00 | | id: 1, firstName: 'Akane', lastName: 'Apple',
2025-02-11 15:49:38.620+09:00 | | birthday: 1991-03-03 09:00:00.000+09:00
2025-02-11 15:49:38.621+09:00 | | },
2025-02-11 15:49:38.621+09:00 | | (Contact){
2025-02-11 15:49:38.621+09:00 | | id: 2, firstName: 'Yukari', lastName: 'Apple',
2025-02-11 15:49:38.621+09:00 | | birthday: 1992-04-04 09:00:00.000+09:00
2025-02-11 15:49:38.622+09:00 | | }
2025-02-11 15:49:38.622+09:00 | | ] (ReadmeExample.js:20)
2025-02-11 15:49:38.622+09:00 | Leave func2 (ReadmeExample.js:21) duration: 00:00:00.004
2025-02-11 15:49:38.622+09:00 Leave func1 (ReadmeExample.js:28) duration: 00:00:00.004
3. Function List
This library has the following methods. These have no return value.
4. Properties of debugtrace-js
The following properties can be specified for on debugtrace-js.
5. License
(C) 2015 Masato Kokubo
6. Release Notes
debugtrace-js 2.2.0 - February 16, 2025
The following properties have been deleted.
debugtrace.minimumOutputLengthAndSize
debugtrace.minimumOutputStringLength
The default values of the following properties have been changed. |Property name |Default value|Old default value| |:---------------------------|------------:|----------------:| |
debugtrace.collectionLimit
| 128| 512| |debugtrace.stringLimit
| 256| 8192|The
printOptions
argument (optional) has been added to theprint
function.
debugtrace-js 2.1.2 - March 13, 2022
- The
print
andprintMessage
functions now return the argument value.
debugtrace-js 2.1.1 - October 9, 2021
- Fixed a bug that an exception is thrown when outputting a type name.
- Changed to output Node.js version at startup.
debugtrace-js 2.1.0 - August 9, 2021
- Improved function output (output only the first line of the function definition)
- Added the
basicPrint
function - Improved the line break handling of data output
debugtrace-js 2.0.0 - August 2, 2020
- Supported Node.js 10 or later
- Improved the line break handling of data output