andrewroberts / bblog Goto Github PK
View Code? Open in Web Editor NEWGoogle Apps Script logging library
Google Apps Script logging library
Exception: You do not have permission to call SpreadsheetApp.openById. Required permissions: https://www.googleapis.com/auth/spreadsheets
at BBLog_._useSpreadsheet(BBLog:559:34)
at BBLog_(BBLog:212:30)
at getLog(BBLog:101:10)
I've been seeing this message on the stackdriver/execution logs after I started using BBLog code as a library. Trying to figure out why this error message keeps showing up. I have tried to setup oauthScopes on the library and also in the calling script (appsscript.json
) but it doesnt seem to help.
"oauthScopes": [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/drive.readonly",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/spreadsheets.readonly"
],
The code that seems to be causing the exception is ...
// snippet
/********************************************************************************
* Private Methods
*****************/
/**
* Allows logging to a Google spreadsheet. Sets the log sheet, creating
* one if it doesn't exist
*
* @param {string} key The spreadsheet key [OPTIONAL, DEFAULT: active spreadsheet]
* @param {string} sheetName The name of the sheet
* @param {boolean} hideLog
*/
BBLog_.prototype._useSpreadsheet = function(key, sheetName, hideLog) {
var spreadsheet;
if (typeof key !== 'undefined' && key !== '') {
spreadsheet = SpreadsheetApp.openById(key); // ๐ this line over here
} else {
spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
}
// snippet
My log configuration is ...
var log = BBLog.getLog({
level: BBLog.Level.ALL,
sheetName: 'Log',
displayUserId: BBLog.DisplayUserId.EMAIL_FULL,
sheetId: '15oZPWqurBBJYHaTLxNkmKCcDf8se9vyXXXXXXXXXX',
lock: LockService.getScriptLock()
});
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"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.