From d846574543be358945ce7600265b8473868372bb Mon Sep 17 00:00:00 2001 From: Juni! <154621244+juni-b-queer@users.noreply.github.com> Date: Wed, 4 Dec 2024 12:28:38 -0600 Subject: [PATCH] feat: update logging actions (#73) * feat: Update logging actions to handle sting/function inputs and no JetstreamEvent * update cache keys --- .github/workflows/cicd.yml | 4 ++-- src/actions/LoggingActions.ts | 42 ++++++++++++++++++++++++++--------- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 23a8fbc..7a94bcf 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -26,7 +26,7 @@ jobs: id: cache-nodemodules uses: actions/cache@v3 env: - cache-name: cache-node-modules + cache-name: cache-node-modules-test with: # caching node_modules path: node_modules @@ -60,7 +60,7 @@ jobs: id: cache-nodemodules uses: actions/cache@v3 env: - cache-name: cache-node-modules + cache-name: cache-node-modules-lint with: # caching node_modules path: node_modules diff --git a/src/actions/LoggingActions.ts b/src/actions/LoggingActions.ts index 85401ff..6baa9f2 100644 --- a/src/actions/LoggingActions.ts +++ b/src/actions/LoggingActions.ts @@ -3,39 +3,61 @@ import { DebugLog } from '../utils/DebugLog'; import { AbstractAction } from './AbstractAction'; export class LogInputTextAction extends AbstractAction { - constructor(private logText: string) { + constructor( + private logText: string | ((arg0: HandlerAgent, ...args: any) => string) + ) { super(); } - static make(logText: string): LogInputTextAction { + static make( + logText: string | ((arg0: HandlerAgent, ...args: any) => string) + ): LogInputTextAction { return new LogInputTextAction(logText); } // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any async handle(handlerAgent: HandlerAgent, ...args: any): Promise { - console.log(this.logText); + const text: string = AbstractAction.getStringOrFunctionReturn( + this.logText, + handlerAgent, + ...args + ); + + console.log(text); } } export class DebugLogAction extends AbstractAction { constructor( - private action: string, - private message: string, + private action: string | ((arg0: HandlerAgent, ...args: any) => string), + private message: + | string + | ((arg0: HandlerAgent, ...args: any) => string), private level: string = 'info' ) { super(); } - // TODO add a stringOrCallable interface, and function to return string or called function static make( - action: string, - message: string, + action: string | ((arg0: HandlerAgent, ...args: any) => string), + message: string | ((arg0: HandlerAgent, ...args: any) => string), level: string = 'info' ): DebugLogAction { return new DebugLogAction(action, message, level); } - // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any async handle(handlerAgent: HandlerAgent, ...args: any): Promise { - DebugLog.log(this.action, this.message, this.level); + DebugLog.log( + AbstractAction.getStringOrFunctionReturn( + this.action, + handlerAgent, + ...args + ), + AbstractAction.getStringOrFunctionReturn( + this.message, + handlerAgent, + ...args + ), + this.level + ); } }