imp(messaging): removed chalk from logger middlewares
MODIFY
packages/messaging/src/middlewares/messaging.eventLogger.middleware.ts
packages/messaging/src/middlewares/messaging.eventLogger.middleware.ts
-import chalk from 'chalk';
import { tap, map } from 'rxjs/operators';
import { useContext } from '@marblejs/core';
import { provideLogger, LoggerLevel } from '../server/messaging.server.logger';
@@ -11,10 +10,8 @@ export const inputLogger$: MsgMiddlewareEffect = (event$, ctx) => {
return event$.pipe(
tap(event => {
- const eventType = chalk.yellow(event.type);
- const eventCorrelationId = chalk.magenta(event.raw.correlationId);
const channel = transportLayer.config.channel;
- const message = `${eventType}, id: ${eventCorrelationId}`;
+ const message = `${event.type}, id: ${event.raw.correlationId}`;
logger({
level: LoggerLevel.INFO,
@@ -32,18 +29,15 @@ export const outputLogger$: MsgOutputEffect = (event$, ctx) => {
return event$.pipe(
tap(({ event, initiator }) => {
- const isError = !!event.error;
- const colorize = isError ? chalk.red : chalk.yellow;
- const eventType = colorize(event.type);
- const eventCorrelationId = initiator.correlationId && chalk.magenta(initiator.correlationId);
- const eventReplyTo = initiator.replyTo && chalk.yellow(initiator.replyTo);
const channel = transportLayer.config.channel;
- const message = eventReplyTo
- ? `${eventType}, id: ${eventCorrelationId} and sent to ${eventReplyTo}`
- : `${eventType}, id: ${eventCorrelationId}`;
+ const message = event.error
+ ? `${event.error.name}, ${event.error.message} for event ${event.type}`
+ : initiator.replyTo
+ ? `${event.type}, id: ${initiator.correlationId} and sent to ${initiator.replyTo}`
+ : `${event.type}, id: ${initiator.correlationId}`;
logger({
- level: isError ? LoggerLevel.ERROR : LoggerLevel.INFO,
+ level: event.error ? LoggerLevel.ERROR : LoggerLevel.INFO,
tag: 'EVENT_OUT',
message,
channel,
@@ -60,9 +54,9 @@ export const errorLogger$: MsgErrorEffect = (event$, ctx) => {
return event$.pipe(
tap(({ error, event }) => logger({
tag: 'ERROR',
- message: chalk.red(event
+ message: event
? `${error.name}, ${error.message} for event ${event.type}`
- : `${error.name}, ${error.message}`),
+ : `${error.name}, ${error.message}`,
level: LoggerLevel.ERROR,
channel: transportLayer.config.channel,
})),

MODIFY
packages/messaging/src/middlewares/messaging.statusLogger.middleware.ts
packages/messaging/src/middlewares/messaging.statusLogger.middleware.ts
@@ -5,7 +5,6 @@ import { Transport } from '../transport/transport.interface';
import { AmqpConnectionStatus } from '../transport/strategies/amqp.strategy.interface';
import { RedisConnectionStatus } from '../transport/strategies/redis.strategy.interface';
import { ServerEvent } from '../server/messaging.server.events';
-import chalk from 'chalk';
import { MsgServerEffect } from '../effects/messaging.effects.interface';
import { TransportLayerToken } from '../server/messaging.server.tokens';
@@ -31,7 +30,7 @@ const connect$: MsgServerEffect = (event$, ctx) => {
filter(({ type }) => type === serverStatusMap.connect[transportLayer.type]),
tap(({ host, channel }) => logger({
tag: 'CONNECTED',
- message: `Connected server to host: ${chalk.yellow(host)}`,
+ message: `Connected server to host: ${host}`,
level: LoggerLevel.INFO,
channel,
})),
@@ -49,7 +48,7 @@ const disconnect$: MsgServerEffect = (event$, ctx) => {
filter(({ type }) => type === serverStatusMap.disconnect[transportLayer.type]),
tap(({ host, channel }) => logger({
tag: 'DISCONNECTED',
- message: `Disconnected server from host: ${chalk.yellow(host)}`,
+ message: `Disconnected server from host: ${host}`,
level: LoggerLevel.ERROR,
channel,
}))

MODIFY
packages/messaging/src/server/messaging.server.logger.ts
packages/messaging/src/server/messaging.server.logger.ts
@@ -6,9 +6,14 @@ import { LoggerToken } from './messaging.server.tokens';
const IS_TEST_ENV = process.env.NODE_ENV === 'test';
-export enum LoggerLevel { INFO, WARN, ERROR }
-export type LoggerOptions = { channel: string; message: string; tag: string; level?: LoggerLevel };
export type Logger = (opts: LoggerOptions) => any;
+export enum LoggerLevel { INFO, WARN, ERROR }
+export type LoggerOptions = {
+ channel: string;
+ message: string;
+ tag: string;
+ level?: LoggerLevel;
+};
export const provideLogger = (ask: ContextProvider): Logger => pipe(
ask(LoggerToken),
@@ -17,10 +22,10 @@ export const provideLogger = (ask: ContextProvider): Logger => pipe(
const defaultLogger: Logger = ({ channel, message, tag, level = LoggerLevel.INFO }) => {
const now = new Date().toISOString();
- const colorize = {
+ const colorizeText = {
[LoggerLevel.ERROR]: chalk.red,
[LoggerLevel.INFO]: chalk.green,
[LoggerLevel.WARN]: chalk.yellow,
}[level];
- return console.log(now.padEnd(30) + channel.padEnd(15) + colorize(tag.padEnd(15)) + message);
+ return console.log(now.padEnd(30) + channel.padEnd(15) + colorizeText(tag.padEnd(15)) + message);
};

imp(messaging): removed chalk from logger middlewares