Skip to content

Commit

Permalink
feat: update logging actions (#73)
Browse files Browse the repository at this point in the history
* feat: Update logging actions to handle sting/function inputs and no JetstreamEvent

* update cache keys
  • Loading branch information
juni-b-queer authored Dec 4, 2024
1 parent 35e9866 commit d846574
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
42 changes: 32 additions & 10 deletions src/actions/LoggingActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
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<any> {
DebugLog.log(this.action, this.message, this.level);
DebugLog.log(
AbstractAction.getStringOrFunctionReturn(
this.action,
handlerAgent,
...args
),
AbstractAction.getStringOrFunctionReturn(
this.message,
handlerAgent,
...args
),
this.level
);
}
}

0 comments on commit d846574

Please sign in to comment.