-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(typescript): add support to typescript 5.3
Replace winston in favour of simple logging implementation Update some dependencies
- Loading branch information
Showing
117 changed files
with
2,743 additions
and
1,841 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export type Extension<TMock, TRequestedOverriddenMock> = ( | ||
mock: TMock | ||
mock: TMock, | ||
) => TRequestedOverriddenMock; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
import { Format, TransformableInfo } from 'logform'; | ||
import * as winston from 'winston'; | ||
import { ConsoleTransportInstance } from 'winston/lib/winston/transports'; | ||
import { ILogger } from './logger.interface'; | ||
import { MessageFormatter } from './logger'; | ||
|
||
export function ConsoleLogger(): ConsoleTransportInstance { | ||
const customFormat: Format = winston.format.printf( | ||
(info: TransformableInfo) => `${info.level}: ${info.message}` | ||
); | ||
|
||
return new winston.transports.Console({ | ||
level: 'error', | ||
format: winston.format.combine( | ||
winston.format((info: TransformableInfo) => { | ||
info.level = info.level.toUpperCase(); | ||
return info; | ||
})(), | ||
winston.format.colorize(), | ||
winston.format.simple(), | ||
customFormat | ||
), | ||
}); | ||
/* eslint-disable no-console */ | ||
export function ConsoleLogger( | ||
messageFormatter: MessageFormatter, | ||
service: string, | ||
): ILogger { | ||
return { | ||
info: (message: string): void => { | ||
console.log(messageFormatter(service, 'info', message)); | ||
}, | ||
warning: (message: string): void => { | ||
console.log(messageFormatter(service, 'warning', message)); | ||
}, | ||
error: (message: string): void => { | ||
console.log(messageFormatter(service, 'error', message)); | ||
}, | ||
}; | ||
} | ||
/* eslint-enable no-console */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,31 @@ | ||
import { TransformableInfo } from 'logform'; | ||
import * as winston from 'winston'; | ||
import { FileTransportInstance } from 'winston/lib/winston/transports'; | ||
import fs from 'fs'; | ||
import { ILogger } from './logger.interface'; | ||
import { MessageFormatter } from './messageFormatter'; | ||
|
||
let winstonFileLogger: FileTransportInstance; | ||
export function FileLogger( | ||
messageFormatter: MessageFormatter, | ||
service: string, | ||
): ILogger { | ||
const filePath: string = 'tsAutoMock.log'; | ||
|
||
export function FileLogger(): FileTransportInstance { | ||
return ( | ||
winstonFileLogger || | ||
(winstonFileLogger = new winston.transports.File({ | ||
filename: 'tsAutoMock.log', | ||
options: { flags: 'w' }, | ||
level: 'error', | ||
format: winston.format.combine( | ||
winston.format((info: TransformableInfo) => { | ||
info.level = info.level.toUpperCase(); | ||
return info; | ||
})(), | ||
winston.format.simple(), | ||
winston.format.timestamp(), | ||
winston.format.printf( | ||
(info: TransformableInfo) => | ||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions | ||
`${info.timestamp} - ${info.level}: ${info.message}` | ||
) | ||
), | ||
})) | ||
); | ||
const writeData: (data: string) => void = (data: string) => { | ||
fs.writeFileSync(filePath, data, { | ||
flag: 'a', | ||
}); | ||
}; | ||
|
||
return { | ||
info: (message: string): void => { | ||
writeData(messageFormatter(service, 'info', message)); | ||
writeData('\n'); | ||
}, | ||
warning: (message: string): void => { | ||
writeData(messageFormatter(service, 'warning', message)); | ||
writeData('\n'); | ||
}, | ||
error: (message: string): void => { | ||
writeData(messageFormatter(service, 'error', message)); | ||
writeData('\n'); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,36 @@ | ||
import * as winston from 'winston'; | ||
import { AbstractConfigSet } from 'winston/lib/winston/config'; | ||
import { | ||
GetTsAutoMockDebugOptions, | ||
TsAutoMockDebugOptions, | ||
} from '../options/debug'; | ||
import { ConsoleLogger } from './consoleLogger'; | ||
import { FileLogger } from './fileLogger'; | ||
import { ILogger } from './logger.interface'; | ||
import { SilentLogger } from './silentLogger'; | ||
import { FileLogger } from './fileLogger'; | ||
|
||
function LoggerConfig(): AbstractConfigSet { | ||
return { | ||
levels: { | ||
info: 0, | ||
warning: 1, | ||
error: 2, | ||
}, | ||
colors: { | ||
info: 'green', | ||
warning: 'yellow', | ||
error: 'red', | ||
}, | ||
}; | ||
} | ||
|
||
export function Logger(service: string): ILogger { | ||
const config: AbstractConfigSet = LoggerConfig(); | ||
|
||
const winstonLogger: winston.Logger = winston.createLogger({ | ||
levels: config.levels, | ||
}); | ||
const now: () => string = () => new Date().toISOString(); | ||
|
||
winston.addColors(config.colors); | ||
export type MessageFormatter = ( | ||
service: string, | ||
level: string, | ||
message: string, | ||
) => string; | ||
|
||
winstonLogger.silent = true; | ||
const formatter: MessageFormatter = ( | ||
service: string, | ||
level: string, | ||
message: string, | ||
) => `${now()}-${level.toUpperCase()}: ${service} - ${message}`; | ||
|
||
export function Logger(service: string): ILogger { | ||
const options: TsAutoMockDebugOptions = GetTsAutoMockDebugOptions(); | ||
|
||
if (options) { | ||
winstonLogger.silent = false; | ||
if (!options) { | ||
return SilentLogger(); | ||
} | ||
|
||
if (options === 'file') { | ||
winstonLogger.add(FileLogger()); | ||
} else { | ||
winstonLogger.add(ConsoleLogger()); | ||
} | ||
if (options === 'file') { | ||
return FileLogger(formatter, service); | ||
} | ||
|
||
return { | ||
info: (message: string): void => { | ||
winstonLogger.info(`${service} - ${message}`); | ||
}, | ||
warning: (message: string): void => { | ||
winstonLogger.warning(`${service} - ${message}`); | ||
}, | ||
error: (message: string): void => { | ||
winstonLogger.error(`${service} - ${message}`); | ||
}, | ||
}; | ||
return ConsoleLogger(formatter, service); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type MessageFormatter = ( | ||
service: string, | ||
level: string, | ||
message: string, | ||
) => string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ILogger } from './logger.interface'; | ||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
export function SilentLogger(): ILogger { | ||
return { | ||
info: (_: string): void => {}, | ||
warning: (_: string): void => {}, | ||
error: (_: string): void => {}, | ||
}; | ||
} | ||
/* eslint-enable @typescript-eslint/no-empty-function */ |
Oops, something went wrong.