BBLog
BBLog copied to clipboard
TypeError: Cannot read property 'replace' of undefined
I tried to import the BBLog.gs file alone as a library and try to execute a test function - I get an error inside the console
The function I used to test is
function myFunction() {
var lock = LockService.getScriptLock();
var log = BBLog.getLog({
level: BBLog.Level.ALL,
sheetName: 'Log',
displayFunctionNames: BBLog.DisplayFunctionNames.YES,
displayUserId: BBLog.DisplayUserId.EMAIL_FULL,
lock: lock
});
log.info('Test log to GSheet at INFO level');
}
The error inside the console
TypeError: Cannot read property 'replace' of undefined
BBLog_._getFunctionName @ BBLog.gs:908
convertUsingDefaultPatternLayout @ BBLog.gs:871
BBLog_._log @ BBLog.gs:780
BBLog_.info @ BBLog.gs:331
and I get this log line inserted on the sheet
2022-03-24 09:42:36:600 -0400 000383 [email protected] INFO at BBLog_.info (BBLog:331:8) Test log to GSheet at INFO level
In another scenario, when I add the library directly to the sheet and run a modified test function...
function myFunction() {
var lock = LockService.getScriptLock();
var log = getLog({
level: Level.ALL,
sheetName: 'Log',
displayFunctionNames: DisplayFunctionNames.YES,
displayUserId: DisplayUserId.EMAIL_FULL,
lock: lock
});
log.info('Test log to GSheet at INFO level');
}
I get this output on the console
2022-03-24 10:15:33:363 -0400 000881 [email protected] INFO at myFunction (Tests:11:7) Test log to GSheet at INFO level
and this line on the sheet
2022-03-24 10:15:32:819 -0400 000337 [email protected] INFO at BBLog_.info (BBLog:331:8) Test log to GSheet at INFO level
I am wondering if this is because the configuration of depreciated runtime you have on your appsscript.json
file?
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "DEPRECATED_ES5"
It does look like you've found an issue with running it on V8. It is because DisplayFunctionNames is set to YES.
It has never been possible to have this set to YES and run the debugger, as BBLog throws and catches an error to get the function name, which stops the debugger running. But with V8 it looks like DisplayFunctionNames will not work running as normal or with the debugger.
Thanks for flagging this up. The DisplayFunctionNames was always a nasty gotcha that used to catch me out occasionally.