Skip to content

Commit

Permalink
FEATURE: have "business"-oriented log management #42. Enable filter o…
Browse files Browse the repository at this point in the history
…n Test name and TestAssertion. Migrate web client to use new Logger interface (startRegisteredLoggers instead of setEffectiveLoggerFactoryWithLogLevelNext).
  • Loading branch information
miroir-framework committed Jan 7, 2025
1 parent a73eb3b commit 97ea07f
Show file tree
Hide file tree
Showing 9 changed files with 993 additions and 966 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export type SpecificLoggerOptionsMap = Record<string,SpecificLoggerOptions>;

export interface LoggerOptions {
// defaultLevel: typeof defaultLevels[keyof typeof defaultLevels];
defaultLevel: (typeof defaultLevels)[keyof typeof defaultLevels];
// defaultLevel: (typeof defaultLevels)[keyof typeof defaultLevels];
defaultLevel: keyof typeof defaultLevels;
defaultTemplate: string;
// context?: LoggerGlobalContext;
context?: LoggerContextElement;
Expand Down
24 changes: 13 additions & 11 deletions packages/miroir-core/src/3_controllers/DomainController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -979,13 +979,13 @@ export class DomainController implements DomainControllerInterface {
let actionResult: ActionReturnType | undefined = undefined;
try {
LoggerGlobalContext.setAction(currentAction.compositeActionStepLabel);
log.info(
"handleCompositeAction compositeInstanceAction handling sub currentAction",
JSON.stringify(currentAction, null, 2),
// currentAction,
"localContext keys",
Object.keys(localContext),
);
// log.info(
// "handleCompositeAction compositeInstanceAction handling sub currentAction",
// JSON.stringify(currentAction, null, 2),
// // currentAction,
// "localContext keys",
// Object.keys(localContext),
// );
switch (currentAction.compositeActionType) {
case "compositeAction": {
log.info("handleCompositeAction compositeAction action to handle", JSON.stringify(currentAction, null, 2));
Expand All @@ -997,10 +997,12 @@ export class DomainController implements DomainControllerInterface {
break;
}
case "domainAction": {
log.info(
"handleCompositeAction domainAction action to handle",
JSON.stringify(currentAction.domainAction, null, 2)
);
if (currentAction.domainAction.actionType !== "modelAction" || (currentAction.domainAction as any).actionName !== "initModel") {
log.info(
"handleCompositeAction domainAction action to handle",
JSON.stringify(currentAction.domainAction, null, 2)
);
}
actionResult = await this.handleAction(currentAction.domainAction, currentModel);
if (actionResult?.status != "ok") {
log.error("handleCompositeAction Error on action", JSON.stringify(currentAction, null, 2), "actionResult", JSON.stringify(actionResult, null, 2));
Expand Down
21 changes: 10 additions & 11 deletions packages/miroir-core/src/3_controllers/ErrorHandling/CallUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,17 @@ export class CallUtils {
): Promise<Record<string, any>> {
if (action.actionType !== "modelAction" || action.actionName !== "initModel") {
log.info("CallUtils callPersistenceAction called with",
// context,
// continuation,
"action",
JSON.stringify(action, null, 2)
);
} else {
log.info("CallUtils callPersistenceAction called with",
"action",
action.actionType,
action.actionName
);
}
}
// else {
// log.info("CallUtils callPersistenceAction called with",
// "action",
// action.actionType,
// action.actionName
// );
// }
const result: ActionReturnType = await this.persistenceStoreLocalOrRemote.handlePersistenceAction(action);
log.info("CallUtils callPersistenceAction received result", result);
if (result["status"] == "error") {
Expand All @@ -99,8 +98,8 @@ export class CallUtils {
this.errorLogService.pushError(error);
throw error;
} else {
log.info("CallUtils callPersistenceAction ok", result);
log.info("CallUtils callPersistenceAction continuation", continuation);
// log.info("CallUtils callPersistenceAction ok", result);
// log.info("CallUtils callPersistenceAction continuation", continuation);
const transformedResult = continuation.resultTransformation
? continuation.resultTransformation(result, context)
: result;
Expand Down
6 changes: 5 additions & 1 deletion packages/miroir-core/src/4_services/LoggerFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ export class LoggerFilter implements LoggerInterface {

private filter(logger: (...msg: any[]) => void, ...msg: any[]): void {
// logger("FILTER", this.contextFilter?.testSuite, LoggerGlobalContext.getTestSuite());
if (!this.contextFilter?.testSuite || LoggerGlobalContext.getTestSuite() == this.contextFilter?.testSuite) {
if (
(!this.contextFilter?.testSuite || LoggerGlobalContext.getTestSuite() == this.contextFilter?.testSuite) &&
(!this.contextFilter?.test || LoggerGlobalContext.getTest() == this.contextFilter?.test) &&
(!this.contextFilter?.testAssertion || LoggerGlobalContext.getTestAssertion() == this.contextFilter?.testAssertion)
) {
logger(...msg);
}
// else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ function loadNewEntityInstancesInLocalCache(
: i
);

// log.info('loadNewEntityInstancesInLocalCache loading instances',deploymentUuid,section,serializableInstances);
log.info('loadNewEntityInstancesInLocalCache loading instances',deploymentUuid,section,JSON.stringify(serializableInstances[0]));

(state as any).loading[instanceCollectionEntityIndex] = sliceEntityAdapter.setAll(
(state as any).loading[instanceCollectionEntityIndex],
Expand Down Expand Up @@ -362,7 +362,7 @@ function handleInstanceAction(
// // JSON.stringify(state)
// );

const sliceEntityAdapter = initializeLocalCacheSliceStateWithEntityAdapter(
const sliceEntityAdapter:EntityAdapter<EntityInstance, string> = initializeLocalCacheSliceStateWithEntityAdapter(
instanceAction.deploymentUuid,
instanceAction.applicationSection,
instanceCollection.parentUuid,
Expand Down
27 changes: 21 additions & 6 deletions packages/miroir-standalone-app/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ const specificLoggerOptions: SpecificLoggerOptionsMap = {
// "4_miroir-redux_LocalCacheSlice": {template:"[{{time}}] {{level}} ({{name}}) -"},
}

MiroirLoggerFactory.setEffectiveLoggerFactoryWithLogLevelNext(
loglevelnext,
defaultLevels.INFO,
"[{{time}}] {{level}} ({{name}})# ",
specificLoggerOptions
);
// MiroirLoggerFactory.setEffectiveLoggerFactoryWithLogLevelNext(
// loglevelnext,
// defaultLevels.INFO,
// "[{{time}}] {{level}} ({{name}})# ",
// specificLoggerOptions
// );

let log: LoggerInterface = console as any as LoggerInterface;
MiroirLoggerFactory.registerLoggerToStart(
Expand Down Expand Up @@ -94,6 +94,21 @@ const currentMiroirConfig: MiroirConfigClient =

log.info("currentMiroirConfigName:",currentMiroirConfigName, "currentMiroirConfig", currentMiroirConfig);

MiroirLoggerFactory.startRegisteredLoggers(
loglevelnext,
{
"defaultLevel": "INFO",
"defaultTemplate": "[{{time}}] {{level}} {{name}} ### ",
// "context": {
// "testSuite": "DomainController.integ.Data.CRUD",
// "test": "Add Book instance"
// },
"specificLoggerOptions": {
}
},
);
log.info("started registered loggers DONE");

const container = document.getElementById("root");

const router = createBrowserRouter([
Expand Down
Loading

0 comments on commit 97ea07f

Please sign in to comment.