Skip to content

Commit

Permalink
feat: enable context meta as field names + refactoring + docs
Browse files Browse the repository at this point in the history
* improved naming
* add docs to all new config properties
  • Loading branch information
ahochsteger committed May 4, 2024
1 parent 31d8c46 commit 17f9959
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 130 deletions.
19 changes: 11 additions & 8 deletions src/examples/advanced/logSheetLogging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ export const runConfig: Config = {
logSheetLocation:
"/GmailProcessor-Tests/logsheet-${date.now:date::yyyy-MM}",

richLogFields: [
logFields: [
"log.timestamp",
"entity.date",
"entity.subject",
"entity.from",
"entity.url",
"attachment.name",
"attachment.size",
"attachment.contentType",
"stored.location",
"stored.url",
"stored.downloadUrl",
"context.type",
"gmailUrl",
"date",
"subject",
"from",
"gdriveLocation",
"gdriveUrl",
"gdriveDownloadUrl",
"log.message",
],
},
Expand Down
19 changes: 11 additions & 8 deletions src/gas/examples/advanced/logSheetLogging.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ function logSheetLoggingTest() {
logSheetLocation:
"/GmailProcessor-Tests/logsheet-${date.now:date::yyyy-MM}",

richLogFields: [
logFields: [
"log.timestamp",
"entity.date",
"entity.subject",
"entity.from",
"entity.url",
"attachment.name",
"attachment.size",
"attachment.contentType",
"stored.location",
"stored.url",
"stored.downloadUrl",
"context.type",
"gmailUrl",
"date",
"subject",
"from",
"gdriveLocation",
"gdriveUrl",
"gdriveDownloadUrl",
"log.message",
],
},
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ActionRegistry } from "./actions/ActionRegistry"
import { GDriveAdapter } from "./adapter/GDriveAdapter"
import { GmailAdapter } from "./adapter/GmailAdapter"
import { RichLogAdapter } from "./adapter/RichLogAdapter"
import { LogAdapter } from "./adapter/LogAdapter"
import { SpreadsheetAdapter } from "./adapter/SpreadsheetAdapter"
import { ActionConfig } from "./config/ActionConfig"
import { RequiredAttachmentConfig } from "./config/AttachmentConfig"
Expand Down Expand Up @@ -92,7 +92,7 @@ export type ProcessingInfo = {
config: RequiredConfig
gdriveAdapter: GDriveAdapter
gmailAdapter: GmailAdapter
logAdapter: RichLogAdapter
logAdapter: LogAdapter
spreadsheetAdapter: SpreadsheetAdapter
timer: Timer
}
Expand Down
14 changes: 7 additions & 7 deletions src/lib/actions/GlobalActions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Mocks,
fakedSystemDateTimeString,
} from "../../test/mocks/MockFactory"
import { LOG_MESSAGE_KEY } from "../adapter/RichLogAdapter"
import { LOG_MESSAGE_NAME } from "../adapter/LogAdapter"
import { Config } from "../config/Config"
import { LogLevel } from "../utils/Logger"
import { ConfigMocks } from "./../../test/mocks/ConfigMocks"
Expand All @@ -20,10 +20,10 @@ beforeAll(() => {
settings: {
...ConfigMocks.newDefaultSettingsConfigJson(),
logSheetLocation: LOGSHEET_FILE_PATH,
richLogFields: ["log.timestamp", "field1", "field2", "log.message"],
richLogConfig: [
{ key: "field1", title: "Field 1", value: "static value" },
{ key: "field2", title: "Field 2", value: "${context.type}" },
logFields: ["log.timestamp", "field.1", "field.2", "log.message"],
logConfig: [
{ name: "field.1", title: "Field 1", value: "static value" },
{ name: "field.2", title: "Field 2", value: "${context.type}" },
],
},
}
Expand Down Expand Up @@ -68,7 +68,7 @@ it("should log with a certain log level to a logSheet", () => {
})
// TODO: Test should not depend on the action implementation
const i = mocks.processingContext.proc.logAdapter
.getLogFieldKeys()
.indexOf(LOG_MESSAGE_KEY)
.getLogFieldNames()
.indexOf(LOG_MESSAGE_NAME)
expect(mocks.logSheet.appendRow.mock.calls[0][0][i]).toEqual("Log message")
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@ import {
} from "../../test/mocks/MockFactory"
import { Config } from "../config/Config"
import { LogLevel } from "../utils/Logger"
import { RichLogAdapter } from "./RichLogAdapter"
import { LogAdapter } from "./LogAdapter"

let richLogAdapter: RichLogAdapter
let richLogAdapter: LogAdapter
let mocks: Mocks
let config: Config
beforeEach(() => {
config = {
...ConfigMocks.newDefaultConfigJson(),
settings: {
...ConfigMocks.newDefaultSettingsConfigJson(),
richLogFields: [
logFields: [
"log.timestamp",
"log.level",
"log.message",
"field1",
"field2",
"field.1",
"field.2",
"env.runMode",
],
richLogConfig: [
{ key: "field1", title: "Field 1", value: "static value" },
{ key: "field2", title: "Field 2", value: "${context.type}" },
logConfig: [
{ name: "field.1", title: "Field 1", value: "static value" },
{ name: "field.2", title: "Field 2", value: "${context.type}" },
],
},
}
Expand All @@ -43,7 +44,8 @@ it("should create a field config compliant log array", () => {
LogLevel.INFO,
"Log message",
"static value",
"proc",
mocks.processingContext.type,
mocks.processingContext.env.runMode,
])
})

Expand All @@ -53,7 +55,8 @@ it("should create a field config compliant JSON log object", () => {
"log.timestamp": `${fakedSystemDateTimeString}.000`,
"log.level": LogLevel.INFO,
"log.message": "Log message",
field1: "static value",
field2: "proc",
"field.1": "static value",
"field.2": mocks.processingContext.type,
"env.runMode": mocks.processingContext.env.runMode,
})
})
Loading

0 comments on commit 17f9959

Please sign in to comment.