I use Google Sheets for logging, ultimately, for charting things how I want to. I then publish the charts in the sheet and I can pull them into my dashboards.
I use scripts in the sheet to receive the data, and I send the data via a web request. I used to do it with Webcore, now I use a custom virtual device to send the data.
This is the main script I use in the sheet workbook:
// version 2.1-cburgess 6/1/22
function doGet(request) {
if(request != null) {
var ss = SpreadsheetApp.openById("");
sheet = ss.getSheetByName(request.parameter["XtabX"]);
firstRowRange = sheet.getRange(1, 1, 1, sheet.getLastColumn());
sheetHeaders=firstRowRange.getValues();
// columns start at one, but arrays start at 0, so this is the right number for inserting into an array that will be placed into the columns
var newColumnArrayCount=sheet.getLastColumn();
// initialize new row to be inserted before it gets filled with data
var newRow = new Array(sheetHeaders[0].length);
// Get query string to check for tab parameter
var tt=request.queryString;
// initialize new row to be inserted before it gets filled with data
var newRow = new Array(sheetHeaders[0].length);
for(var x=0;x<newColumnArrayCount;x++) newRow[x]="";
// get all the parameter values and insert into new row
for (var i in request.parameters) {
var foundRow=false;
// if the parameter is the tab name, continue to the next parameter
if(i.toString()=="XtabX") {
continue;
}
for(var x=0;x<sheetHeaders[0].length;x++) {
if(i.toString().toLowerCase()==sheetHeaders[0][x].toString().toLowerCase()) {
var currentpar = request.parameter[i];
isNaN(currentpar) ? newRow[x] = currentpar : newRow[x] = Number(currentpar);
foundRow=true;
break;
}
}
if(foundRow==false) {
if(sheet.getLastColumn()==sheet.getMaxColumns()) {
sheet.insertColumnAfter(sheet.getLastColumn());
}
sheetHeaders[0][newColumnArrayCount]=i;
newRow[newColumnArrayCount]=request.parameter[i];
firstRowRange=sheet.getRange(1, 1, 1, sheet.getLastColumn()+1);
firstRowRange.setValues(sheetHeaders);
firstRowRange = sheet.getRange(1, 1, 1, sheet.getLastColumn());
sheetHeaders=firstRowRange.getValues();
newColumnArrayCount++;
}
}
if(newRow[0]=="") {
Logger.log("setting date");
newRow[0]=new Date();
}
// Appends a new row to the bottom of the
// spreadsheet containing the values in the array
sheet.appendRow(newRow);
sheet.getRange(sheet.getLastRow()-1, 1, 1, sheet.getLastColumn()).copyFormatToRange(sheet, 1, sheet.getLastColumn(), sheet.getLastRow(), sheet.getLastRow());
}
}
This is what I use to delete old rows within a set number of days.
function doGet(request) {
var ss = SpreadsheetApp.openById("");
var xtab = request.parameter["sheet"];
var tab = xtab.replace("%20"," ");
console.log(tab);
sheet = ss.getSheetByName(tab);
var values = sheet.getDataRange().getValues();
var pastDate = new Date();
var deleteDays = request.parameter["days"];
pastDate.setDate(pastDate.getDate()-deleteDays);
var numRows = 0;
for( var row = values.length -1; row >= 1; --row ) {
var cellDate = values[row][0];
if (cellDate < pastDate) {
sheet.deleteRow(parseInt(row)+1);
numRows++;
}
}
};
I use this virtual device to send my logs. It has attributes to enter the URIs of the app scripts in the sheet.
It uses this format:
Set up the logParams with the data by making a string.
logParams = "Variable Name 1="variableName1+"Variable Name 2="+variableName2 ...
Then I set the sendLog attribute using the logParams string:
googleLogs.sendLog("Sheet Name", logParams)
Inside the code for the log device, there is an array built in the code that has to be manually modified for deletes, you just add entries to it in the format:
"sheet=Sheet Name&days=7" -> to keep 7 days worth of data on the sheet. It will randomly delete the rows down to the proper number of retention days for sheets added to the array.
I left my sheets in the code as an example of setting up the delete array in the code.
Edit: Note, this is a bit of a manual and hacky way to do it, and though I'm posting code this is not a release or anything, but if you want to try and use what I posted I'm happy to help you get it working.
Also note, I use just one sheet workbook for all my logs, so there are many different log sheets within the one sheet file that has the apps code installed.
Also, you have to fill in your app sheet ID in those scripts first on this line:
var ss = SpreadsheetApp.openById("");
The sheet ID is part of the sheet URL... you can google how to get that from the URL.