-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
2,719 additions
and
31 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -13,4 +13,4 @@ RUN yarn install | |
COPY runner.ts tsconfig.json ./ | ||
COPY lib/ ./lib/ | ||
|
||
RUN yarn tsc | ||
RUN yarn build |
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,20 +1,75 @@ | ||
import { createLogger as createWinstonLogger, format, transports, Logger } from 'winston'; | ||
|
||
/** | ||
* Extend Logger interface with custom "json" method | ||
*/ | ||
interface CustomLogger extends Logger { | ||
/** | ||
* Method for logging JSON objects | ||
* | ||
* @param obj - JSON object to log | ||
* | ||
* @example | ||
* logger.json({ foo: 'bar' }); | ||
*/ | ||
json: (obj: unknown) => void; | ||
} | ||
|
||
/** | ||
* Creates new logger instance | ||
*/ | ||
export default function createLogger(): Logger { | ||
return createWinstonLogger({ | ||
export default function createLogger(): CustomLogger { | ||
const logger = createWinstonLogger({ | ||
level: process.env.LOG_LEVEL || 'info', | ||
transports: [ | ||
new transports.Console({ | ||
format: format.combine( | ||
format.errors({ stack: true }), | ||
format.timestamp(), | ||
format.colorize(), | ||
format.simple(), | ||
format.printf((msg) => `${msg.timestamp} - ${msg.level}: ${msg.message}`) | ||
format.printf(({ level, message, timestamp, stack }) => { | ||
if (stack) { | ||
return `${timestamp} ${level}: ${message} - ${stack}`; | ||
} | ||
|
||
return `${timestamp} ${level}: ${message}`; | ||
}) | ||
), | ||
}), | ||
], | ||
}); | ||
}) as CustomLogger; | ||
|
||
/** | ||
* Method for logging JSON objects | ||
* | ||
* @param obj - JSON object to log | ||
* | ||
* @example | ||
* logger.json({ foo: 'bar' }); | ||
*/ | ||
logger.json = function (obj: unknown): void { | ||
const indent = 2; | ||
|
||
/** | ||
* Convert object to formatted string with proper indentation | ||
*/ | ||
const formattedJson = typeof obj === 'string' | ||
? JSON.stringify(JSON.parse(obj), null, indent) | ||
: JSON.stringify(obj, null, indent); | ||
|
||
/** | ||
* Split the JSON string into lines | ||
*/ | ||
const lines = formattedJson.split('\n'); | ||
|
||
/** | ||
* Log each line to preserve formatting and colors | ||
*/ | ||
lines.forEach(line => { | ||
this.info(line); | ||
}); | ||
}; | ||
|
||
return logger; | ||
} |
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
Oops, something went wrong.