Skip to content

Commit

Permalink
fix: use dhilog instead of slogerr (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitij-k-osmosys authored Jan 24, 2025
1 parent 54d2de6 commit c14ba9b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions apps/api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ MAX_RETRY_COUNT=3 # Max retry count, default is 3
ARCHIVE_LIMIT=1000 # Max notifications to archive, default is 1000
ARCHIVE_INTERVAL=3600 # Interval (in seconds) for archiving notifications, default 3600 (every 1 hour)

# Slogger configuration
SLOGGER_LOG_TYPE=
SLOGGER_LOG_LEVEL=error #Log level, default is error
SLOGERR_API_ENDPOINT= #Slogger log api url
SLOGERR_API_TOKEN= #Slogger api token
ENABLE_SLOGERR=false #default set to false
# Dhilog configuration
DHILOG_LOG_TYPE= # Custom "Log types" value defined on Dhilog portal
DHILOG_LOG_LEVEL=error # Log level, default is error
DHILOG_API_ENDPOINT= # Dhilog log api url
DHILOG_API_TOKEN= # Dhilog api token
ENABLE_DHILOG=false # Default set to false

# Logger configuration
LOG_LEVEL=info # Log level, default is info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ interface LogInfo {
severity: string;
}

export class SlogerrTransport extends TransportStream {
export class DhilogTransport extends TransportStream {
private readonly httpService: HttpService;
private readonly configService: ConfigService;
private readonly logger = new Logger(SlogerrTransport.name);
private readonly logger = new Logger(DhilogTransport.name);

constructor(options: CustomTransportOptions) {
super(options);
Expand All @@ -32,14 +32,14 @@ export class SlogerrTransport extends TransportStream {
}

async log(info: LogInfo, callback: () => void): Promise<void> {
const allowedLevels = (this.configService.get<string>('SLOGGER_LOG_LEVEL') || 'error')
const allowedLevels = (this.configService.get<string>('DHILOG_LOG_LEVEL') || 'error')
.split(',')
.map((level) => level.trim());
const logType = this.configService.get<string>('SLOGGER_LOG_TYPE') || 'Exceptions';
const logType = this.configService.get<string>('DHILOG_LOG_TYPE') || 'Exceptions';

if (allowedLevels.includes(info.level)) {
const apiEndpoint = this.configService.get<string>('SLOGERR_API_ENDPOINT');
const apiKey = this.configService.get<string>('SLOGERR_API_TOKEN');
const apiEndpoint = this.configService.get<string>('DHILOG_API_ENDPOINT');
const apiKey = this.configService.get<string>('DHILOG_API_TOKEN');

this.logger.log(`Log Info: ${stringify(info)}`);

Expand Down Expand Up @@ -67,13 +67,13 @@ export class SlogerrTransport extends TransportStream {

if (response.status !== 200) {
this.logger.warn(
`Failed to send log to Slogerr. Status: ${response.status}, Message: ${response.statusText}`,
`Failed to send log to Dhilog. Status: ${response.status}, Message: ${response.statusText}`,
);
} else {
this.logger.log('Error log successfully sent to Slogerr', response);
this.logger.log('Error log successfully sent to Dhilog', response);
}
} catch (error) {
this.logger.warn('Failed to send log to Slogerr', error.message);
this.logger.warn('Failed to send log to Dhilog', error.message);
}
}

Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/config/logger.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'winston-daily-rotate-file';
import { ConfigService } from '@nestjs/config';
import { name as applicationName } from 'package.json';
import DailyRotateFile from 'winston-daily-rotate-file';
import { SlogerrTransport } from 'src/common/logger/slogerr.transport';
import { DhilogTransport } from 'src/common/logger/dhilog.transport';
import { stringify } from 'flatted';

const configService = new ConfigService();
Expand All @@ -19,7 +19,7 @@ const logDir = 'logs';
const combinedLogMaxSize = configService.get<string>('COMBINED_LOG_MAX_SIZE');
const errorLogMaxSize = configService.get<string>('ERROR_LOG_MAX_SIZE');

const enableSlogger = configService.get<string>('ENABLE_SLOGERR') || 'false';
const enableDhilog = configService.get<string>('ENABLE_DHILOG') || 'false';

const logFormat = format.combine(
format.timestamp(),
Expand Down Expand Up @@ -83,7 +83,7 @@ if (errorLogMaxSize === '0') {
errorLogOptions.maxSize = '20m';
}

const slogerrTransport = new SlogerrTransport({
const dhilogTransport = new DhilogTransport({
httpService,
configService,
});
Expand All @@ -98,7 +98,7 @@ const transportsConfig = [
}),
new transports.DailyRotateFile(combinedLogOptions),
new transports.DailyRotateFile(errorLogOptions),
...(enableSlogger === 'true' ? [slogerrTransport] : []),
...(enableDhilog === 'true' ? [dhilogTransport] : []),
];

export const loggerConfig = WinstonModule.createLogger({
Expand Down

0 comments on commit c14ba9b

Please sign in to comment.