peterherrmann / betterlog Goto Github PK
View Code? Open in Web Editor NEWWith one line of code, BetterLog extends the native apps script Logger and gives you automatic additional features like logging to a spreadsheet and more.
With one line of code, BetterLog extends the native apps script Logger and gives you automatic additional features like logging to a spreadsheet and more.
Hi Peter,
I think the project key has changed because of GAS' new IDE: I couldn't use the key MYB7yzedMbnJaMKECt6Sm7FLDhaBgl_dE
to add the Library in my script, but the key 1DSyxam1ceq72bMHsE6aOVeOl94X78WCwiYPytKi7chlg4x5GqiNXSw0l
worked fine.
Best, Hugo
I have been successfully testing the Lirbrary for several days but as of today am getting the error
Error: Not enough arguments (line 134, file "Code", project "BetterLog")
PLease let me know the best approach to repair
Great tool by the Way
Gary
Given
Logger.log("This is a: %s", undefined)
the built-in logger will log
This is a: undefined
but BetterLog will throw an exception complaining that there aren't enough arguments.
Execution failed: You do not have permission to perform that action. (line 384, file "Code", project "BetterLog") [0.048 seconds total runtime]
Could you provide some example code for using remote logging. Looks like I'd need to create a web app, but I can't see a doGet().
When executing my google script:
function test(){
Logger = BetterLog.useSpreadsheet('my id');
Logger.log("test()")
}
I receive nothing in the spreadsheet, is that normal ? Do I need to set any permissions and if yes how ? =)
Hi!
I’ve been using the library for a while and found that archived logs drop to the root of the GDrive.
So that’s why the question appeared.
Is it possible to specify a folder to save archived logs?
More context: When I add it as a library and want to call ex. onEdit(e), it returns a permission error:
"Exception: You do not have permission to call SpreadsheetApp.openById. Required permissions: https://www.googleapis.com/auth/spreadsheets"
The permission scope https://www.googleapis.com/auth/spreadsheets is already in the application.json file.
On logging GmailMessage
class getBody()
method:
It throws error:
Error: Not enough arguments [line: 206, function: replacerDemuxer, file: format_string.js]
First of all, thanks for this very useful tool! 👍
I don't know if it is really a bug, but I am getting the error "Not enough arguments" even without using "%s" in the log string. The code below reproduces the problem:
function test_LOG(){
const logger = BetterLog.useSpreadsheet(SPREADSHEET_KEY);
let url = "https://api.stackexchange.com/2.2/search/excerpts/?body=every%20product%20may%20be%20added%20to%20existing%20category.%20I%20am%20trying%20to%20find%20a%20way%20to%20render%20page%20with%20products&order=desc&sort=creation&site=stackoverflow";
logger.log(url);
}
If I have multiple triggers from multiple users that are writing to a single log sheet when it is trying to do the automatic refresh at 50000 rows SpreadsheetApp throws multiple server errors until I manually delete the contents of the log.
I assume this is because as one trigger is trying to copy the sheet before clearing it, another trigger comes in and tries to do the same thing and they all start blocking each other.
How about adding a "lock" once the refresh is going on?
The library works, but when pasting source code this error pops-up:
"Cannot handle returning cyclic object."
Hi, I just want to say thank you for developing such an amazing tool.
There is one issue that I noticed. After enabling BetterLog, code that was in onOpen would no longer run. In the Google Apps Dashboard, the Head execution shows fail. If I disable the loading of BetterLog, everything works again.
Here is my code in onOpen;
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('**> Export Hermes <**')
.addItem('Add/Update Customer to Master List', 'copyCustomer2Master')
.addToUi();
};
Cheers, Markus
Hi -
First, thank you very much for BetterLog. It's a great tool.
For security reasons I'm not able to use Libraries in my script. I'm using BetterLog as a library during development but will soon need to cut and paste it so that my scripts are self-contained. The instructions imply this is possible, but I haven't been able to figure out how. I am a complete noob at GAS and Javascript in general so I am probably missing something very simply.
Here's what I've done
Please advise how I can use the source of BetterLog in my application.
Thanks again,
Mike
Hi thx for this amazing job.
I discovered this repo after pulling my hair out trying to log webapp-calls using appscript :)
I noticed your last version mentioning 'Logger.log will now log to stackdriver' or something.
Is this possible directly using BetterLog.log(....)
without having to call the .use(...)
-spreadsheet function?
I can't seem to log my doPost()-calls into the appscript (simple stackdriver) dashboard, and I'm not sure whether its due to nested use of appscript libraries or not.
ps. Logger.log is not prone to hoisting effects right? I remember reading in the docs that the Logger.log
-instance of the main-script is supposed to be shared across modules.
As said on the README I am trying to use BetterLog inside my project instead of as a Library since google apps scripts says in their documentation that having libraries will make the script a bit slower and I am dealing with a time sensitive task.
When I try to use it copying directly from master to my project and run it I get a Exceeded maximum stack depth (line 345, file "logging")
error.
I have made a simple example public script:
https://script.google.com/d/1mfX2zDAlhdQJH8naBDX9JffVvs_25CAT2v--RdFGx6ZrSGZ7-I441oiQ/edit?usp=sharing
Left the execution transcript here:
https://gist.github.com/jjelosua/9c524e5f17257b2f186aebe74a2b55f4
First: thank you, Thank You, THANK YOU!
Already making me so much more productive.
Also, I am calling this an 'Issue' only in that I am inferring that everything Logger can do you intend BetterLog to handle. Disregard/Delete if my inference is incorrect.
Running this code:
var a = 7;
var b = 9;
var c {firstDog: "Chester",
secondDog: "Marais"};
Logger.log("You can inject variables with %s, every time you place %s in this string the next variable of the following parameters will be logged. For the last variable %s will format the object as a string", a, b, c);
...will 'stringify' the object on the fly. But if I call the same code with BetterLog it renders only
"[object Object]" for the placeholder.
However, running this code:
var a = 7;
var b = 9;
var c {firstDog: "Chester",
secondDog: "Marais"};
var c_string = JSON.stringify(c);
Logger.log("You can inject variables with %s, every time you place %s in this string the next variable of the following parameters will be logged. For the last variable %s will format the object as a string", a, b, c_string);
... works exactly as expected using BetterLog. Not too much more trouble, and all of the amazing ways that BetterLog is indeed better out-weighs this. But I thought you might like the feedback to make BetterLog even better.
Regards,
Sorry for the non-descriptive issue title, but it simply doesn't work.
To reproduce:
function myFunction() {
var spreadsheetId = '1X8x6J0OP7__8bWPkzTEvBOjM8-xEsCP2nW8ha3j1m_8';
var logSheet = SpreadsheetApp
.openById(spreadsheetId)
.getActiveSheet();
logSheet.appendRow(['Using', 'Spreadsheet', 'Service']);
Logger = BetterLog.useSpreadsheet(spreadsheetId);
Logger.log("Using BetterLog");
}
I add BetterLog
via the libraries menu, and when I run the function, I approve the script's request to access my spreadsheet. Then the spreadsheet looks like this.
The script logs successfully record the "Using BetterLog" message, but it does not appear in the spreadsheet.
Just to be sure, I also ran just this part:
function myFunction() {
var spreadsheetId = '1X8x6J0OP7__8bWPkzTEvBOjM8-xEsCP2nW8ha3j1m_8';
Logger = BetterLog.useSpreadsheet(spreadsheetId);
Logger.log("Using BetterLog");
}
Same result; no errors, correct script logs, no new data in the spreadsheet.
I read over your readme several times. Seems pretty simple, and it's exactly what I want for my purposes. Would love a fix.
Hi,
there is error in code while using Lock
// get a lock or throw exception var lock = LockService.getScriptLock().waitLock(10000); //try for 10 secs to get a lock, long enough to rollover the log
According to documentation:
https://developers.google.com/apps-script/reference/lock/lock#waitLock(Integer)
waitLock does not return anything so lock is undefined
and after that
lock.releaseLock();
cause error.
lock.waitLock(10000);
should be used separately without chaining.
Regards,
Paweł
Trying to set the time format but not seeing a change. Still logs using the default time format.
Logger = BetterLog.useSpreadsheet();
Logger.DATE_TIME_LAYOUT = "yyMMdd.HHmmss";
//Logger.DATE_TIME_LAYOUT = "''"; <- doesn't work either
I've added BetterLog using the Google scripts resource.
I'm using version 18 though I tried using older versions as well.
After reaching 50001 lines in the specified google sheet, the log doesn't roll over it creates a new sheet every time the logger is instantiated. This results in a number of sheets with "SheetName as at date-time" and throws an error on line 329 of Code.gs
BetterLog
duplicates output to console two times . This happens if the logger is run from Apps Script
development environment. This behavior probably appeared after update in Apps Script
engine about 1 year ago. Before this update BetterLog
outputted messages to console as expected only one time (without doubling them).
Example of console log with messages duplications:
11:23:10 AM Info 2022-06-13 11:23:10:821 +0300 001169 INFO doPost called
11:23:10 AM Info doPost called
11:23:11 AM Info 2022-06-13 11:23:11:289 +0300 001637 INFO doPost - contents: {"message":{"chat":{"id":123},"text":"/test"}}; runFromChatId: 123; text: /test
11:23:11 AM Info doPost - contents: {"message":{"chat":{"id":123},"text":"/test"}}; runFromChatId: 123; text: /test
11:23:11 AM Info 2022-06-13 11:23:11:599 +0300 001947 INFO doPost - not yet validated runFromChatId: 123
11:23:11 AM Info doPost - not yet validated runFromChatId: 123
11:23:11 AM Info 2022-06-13 11:23:11:893 +0300 002241 INFO doPost - authFailedAmount: 0
11:23:11 AM Info doPost - authFailedAmount: 0
...
Config for such output is the following:
const Logger = BetterLog.useSpreadsheet(SPREADSHEET_ID);
Logger.log("doPost called");
...
Fix
//Anton Samokat fix: messages are printed to console twicely.
//Added check for nativeLogger_ is not null and not undefined
//in order to be able to set nativeLogger_ as null
//and in such a way to skip printing messages to it.
if(nativeLogger_) {
//default console logging (built in with Google Apps Script's View > Logs...)
nativeLogger_.log(convertUsingDefaultPatternLayout_(msg, level));
}
There are already such checks for console:
if (typeof console !== "undefined" && typeof console.time !== "undefined") {
switch(level) {
case Level.INFO:
console.info(msg);
break;
case Level.SEVERE:
console.error(msg);
break;
case Level.WARNING:
console.warn(msg);
break;
default:
console.info(msg);
}
}
And for sheet destinations:
if (sheet_) {
logToSheet_(msg, level);
}
This checks give possibility to turn off output destinations by the following logger initial configuration:
//log config start
//Logger = BetterLog.useSpreadsheet(SPREADSHEET_ID); //use BetterLog library
const Logger = useSpreadsheet(SPREADSHEET_ID); // use local BetterLog logger
//Logger.console = undefined; //do not print messages to console
Logger.nativeLogger_ = undefined; //do not print messages to console second time
//Logger.sheet_ = undefined; //do not print messages to sheet (this particular set
//can be placed in initTestsEnvironment() function for using it in local tests runs
//in order to skip printing to the sheet for not spamming it during the tests)
//log config end
So please add check on null
or undefined
for nativeLogger_
var and publish changes in Google Apps BetterLog library.
May be it will be good to make API for the configurations above to be able to use them more simpler and transparently.
By default in BetterLog
I prefer to use console
destination, not nativeLogger_
since its default timestamp took much space and there are already timestamps (but without seconds and milliseconds) on the left side of Apps Script console.
Thanks, Anton.
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.