format
This commit is contained in:
parent
d858222af7
commit
7d9044ab29
202 changed files with 10755 additions and 10972 deletions
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
|
||||
import { getLogger, type Logger } from '@stock-bot/logger';
|
||||
|
||||
interface ServiceResolver {
|
||||
resolve<T>(serviceName: string): T;
|
||||
resolveAsync<T>(serviceName: string): Promise<T>;
|
||||
|
|
@ -23,17 +24,19 @@ export class OperationContext {
|
|||
public readonly metadata: Record<string, any>;
|
||||
private readonly container?: ServiceResolver;
|
||||
private readonly startTime: Date;
|
||||
|
||||
|
||||
constructor(options: OperationContextOptions) {
|
||||
this.container = options.container;
|
||||
this.metadata = options.metadata || {};
|
||||
this.traceId = options.traceId || this.generateTraceId();
|
||||
this.startTime = new Date();
|
||||
|
||||
this.logger = options.parentLogger || getLogger(`${options.handlerName}:${options.operationName}`, {
|
||||
traceId: this.traceId,
|
||||
metadata: this.metadata,
|
||||
});
|
||||
|
||||
this.logger =
|
||||
options.parentLogger ||
|
||||
getLogger(`${options.handlerName}:${options.operationName}`, {
|
||||
traceId: this.traceId,
|
||||
metadata: this.metadata,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -42,8 +45,8 @@ export class OperationContext {
|
|||
static create(
|
||||
handlerName: string,
|
||||
operationName: string,
|
||||
options: {
|
||||
container?: ServiceResolver;
|
||||
options: {
|
||||
container?: ServiceResolver;
|
||||
parentLogger?: Logger;
|
||||
metadata?: Record<string, any>;
|
||||
traceId?: string;
|
||||
|
|
@ -95,7 +98,7 @@ export class OperationContext {
|
|||
*/
|
||||
logCompletion(success: boolean, error?: Error): void {
|
||||
const executionTime = this.getExecutionTime();
|
||||
|
||||
|
||||
if (success) {
|
||||
this.logger.info('Operation completed successfully', {
|
||||
executionTime,
|
||||
|
|
@ -138,4 +141,4 @@ export class OperationContext {
|
|||
private generateTraceId(): string {
|
||||
return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue