LogSheet Logging
This example demonstrates the advanced logging possibilities to a Google Spreadsheet.
The following settings
are used to configure the logging behafior:
logSheetLocation
: The location of the spreadsheet document to be logged into.logFields
: The list of log fields which are used to log into a separate column in the given order.logSheetTracing
: Logs additional tracing logs into the log sheet.
The action global.sheetLog
is then used to log certain messages into the logsheet at the given processingStage
s.
👉 Edit this example in the playground.
- Config
- Script
{
"description": "Logs data to a Google Spreadsheet.",
"settings": {
"markProcessedMethod": "mark-read",
"logSheetLocation": "/GmailProcessor-Tests/logsheet-${date.now:date::yyyy-MM}",
"logSheetTracing": true,
"logFields": [
"log.timestamp",
"log.level",
"log.location",
"log.message",
"object.id",
"object.date",
"object.subject",
"object.from",
"object.url",
"attachment.name",
"attachment.size",
"attachment.contentType",
"stored.location",
"stored.url",
"stored.downloadUrl",
"context.type"
]
},
"threads": [
{
"match": {
"query": "-in:trash -in:drafts -in:spam after:${date.now:date::yyyy-MM-dd} from:${user.email} is:unread subject:\"[GmailProcessor-Test] logSheetLogging\""
},
"actions": [
{
"name": "global.sheetLog",
"args": {
"level": "info",
"message": "Thread log (pre-main): ${thread.id}"
},
"processingStage": "pre-main"
},
{
"name": "global.sheetLog",
"args": {
"level": "info",
"message": "Thread log (main): ${thread.id}"
},
"processingStage": "main"
},
{
"name": "global.sheetLog",
"args": {
"level": "info",
"message": "Thread log (post-main): ${thread.id}"
},
"processingStage": "post-main"
}
],
"messages": [
{
"actions": [
{
"name": "global.sheetLog",
"args": {
"level": "warn",
"message": "Message log (pre-main): ${message.id}"
},
"processingStage": "pre-main"
},
{
"name": "global.sheetLog",
"args": {
"level": "warn",
"message": "Message log (main): ${message.id}"
},
"processingStage": "main"
},
{
"name": "global.sheetLog",
"args": {
"level": "warn",
"message": "Message log (post-main): ${message.id}"
},
"processingStage": "post-main"
}
],
"attachments": [
{
"actions": [
{
"name": "global.sheetLog",
"args": {
"level": "error",
"message": "Attachment log (pre-main): ${attachment.hash}"
},
"processingStage": "pre-main"
},
{
"name": "attachment.store",
"args": {
"conflictStrategy": "update",
"location": "/GmailProcessor-Tests/e2e/logSheetLogging/${attachment.name}"
}
},
{
"name": "global.sheetLog",
"args": {
"level": "error",
"message": "Attachment log (post-main): ${attachment.hash}"
},
"processingStage": "post-main"
}
]
}
]
}
]
}
]
}
function logSheetLoggingRun() {
const config = {
description: "Logs data to a Google Spreadsheet.",
settings: {
markProcessedMethod: "mark-read",
logSheetLocation:
"/GmailProcessor-Tests/logsheet-${date.now:date::yyyy-MM}",
logSheetTracing: true,
logFields: [
"log.timestamp",
"log.level",
"log.location",
"log.message",
"object.id",
"object.date",
"object.subject",
"object.from",
"object.url",
"attachment.name",
"attachment.size",
"attachment.contentType",
"stored.location",
"stored.url",
"stored.downloadUrl",
"context.type",
],
},
threads: [
{
match: {
query:
'-in:trash -in:drafts -in:spam after:${date.now:date::yyyy-MM-dd} from:${user.email} is:unread subject:"[GmailProcessor-Test] logSheetLogging"',
},
actions: [
{
name: "global.sheetLog",
args: {
level: "info",
message: "Thread log (pre-main): ${thread.id}",
},
processingStage: "pre-main",
},
{
name: "global.sheetLog",
args: {
level: "info",
message: "Thread log (main): ${thread.id}",
},
processingStage: "main",
},
{
name: "global.sheetLog",
args: {
level: "info",
message: "Thread log (post-main): ${thread.id}",
},
processingStage: "post-main",
},
],
messages: [
{
actions: [
{
name: "global.sheetLog",
args: {
level: "warn",
message: "Message log (pre-main): ${message.id}",
},
processingStage: "pre-main",
},
{
name: "global.sheetLog",
args: {
level: "warn",
message: "Message log (main): ${message.id}",
},
processingStage: "main",
},
{
name: "global.sheetLog",
args: {
level: "warn",
message: "Message log (post-main): ${message.id}",
},
processingStage: "post-main",
},
],
attachments: [
{
actions: [
{
name: "global.sheetLog",
args: {
level: "error",
message: "Attachment log (pre-main): ${attachment.hash}",
},
processingStage: "pre-main",
},
{
name: "attachment.store",
args: {
conflictStrategy: "update",
location:
"/GmailProcessor-Tests/e2e/logSheetLogging/${attachment.name}",
},
},
{
name: "global.sheetLog",
args: {
level: "error",
message: "Attachment log (post-main): ${attachment.hash}",
},
processingStage: "post-main",
},
],
},
],
},
],
},
],
}
return GmailProcessorLib.run(config, "dry-run")
}
Source: logSheetLogging.ts