summaryrefslogtreecommitdiff
path: root/installed-tests
diff options
context:
space:
mode:
authorMarco Trevisan (TreviƱo) <mail@3v1n0.net>2022-06-09 02:07:37 +0200
committerPhilip Chimento <philip.chimento@gmail.com>2022-11-02 21:22:51 -0700
commitc116e40d8e0ed714db1abbecc3feac59724f857c (patch)
tree71d0958336494567db1f82d1595caf0c98eacb6d /installed-tests
parent6166d44852b71eb8f1de6bca8fd93bb1a4e67d3b (diff)
downloadgjs-c116e40d8e0ed714db1abbecc3feac59724f857c.tar.gz
console: Include CODE file, function and line in structured logging
This is what GLib does all the times for C code, in JS we can easily do it as well as we have traces, for now do it only for console.trace().
Diffstat (limited to 'installed-tests')
-rw-r--r--installed-tests/js/testConsole.js22
1 files changed, 17 insertions, 5 deletions
diff --git a/installed-tests/js/testConsole.js b/installed-tests/js/testConsole.js
index 1b70c7ea..a9bfa1d6 100644
--- a/installed-tests/js/testConsole.js
+++ b/installed-tests/js/testConsole.js
@@ -132,12 +132,19 @@ describe('console', function () {
});
it('traces a line', function () {
- console.trace('a trace');
+ // eslint-disable-next-line max-statements-per-line
+ console.trace('a trace'); const error = new Error();
+
+ const [_, currentFile, errorLine] = error.stack.split('\n').at(0).match(
+ /^[^@]*@(.*):(\d+):\d+$/);
expect(writer_func).toHaveBeenCalledOnceWith(
GLib.LogLevelFlags.LEVEL_MESSAGE,
- objectContainingLogMessage('a trace', DEFAULT_LOG_DOMAIN, {},
- message => matchStackTrace(message, 'testConsole'))
+ objectContainingLogMessage('a trace', DEFAULT_LOG_DOMAIN, {
+ CODE_FILE: decodedStringMatching(currentFile),
+ CODE_LINE: decodedStringMatching(errorLine),
+ },
+ message => matchStackTrace(message, 'testConsole'))
);
writer_func.calls.reset();
@@ -146,10 +153,15 @@ describe('console', function () {
it('traces a empty message', function () {
console.trace();
+ const [_, currentFile] = new Error().stack.split('\n').at(0).match(
+ /^[^@]*@(.*):\d+:\d+$/);
+
expect(writer_func).toHaveBeenCalledOnceWith(
GLib.LogLevelFlags.LEVEL_MESSAGE,
- objectContainingLogMessage('Trace', DEFAULT_LOG_DOMAIN,
- message => matchStackTrace(message, 'testConsole'))
+ objectContainingLogMessage('Trace', DEFAULT_LOG_DOMAIN, {
+ CODE_FILE: decodedStringMatching(currentFile),
+ },
+ message => matchStackTrace(message, 'testConsole'))
);
writer_func.calls.reset();