Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* istanbul ignore if */
if (process.env.NODE_ENV === 'production') {
if (!fs.existsSync(logDir)) mkdirp.sync(logDir)
streams = [
{level: 'info', stream: fs.createWriteStream(`logs/${date}-info.log`, streamOpt)},
{level: 'error', stream: fs.createWriteStream(`logs/${date}-error.log`, streamOpt)}
]
}
module.exports = koaPinoLogger({
name: 'Easy Mock',
level: process.env.NODE_ENV === 'test' ? 'silent' : /* istanbul ignore next */ 'info',
genReqId: req => req.headers['x-request-id'] || uuid.v4()
}, multistream(streams))
base: null,
}
let loggerStreams: Streams = [{ stream: process.stdout }]
if (options.sentryOptions) {
loggerStreams.push({
level: 'error',
stream: createWriteStream({
...options.sentryOptions,
stackAttributeKey: 'err',
}),
})
}
if (options.streams) loggerStreams = loggerStreams.concat(options.streams)
this.inner = pino(loggerOptions, pinoms.multistream(loggerStreams))
}
export default opts => Pino({ name, ...opts }, multistream(streams));
export function createDefaultLogger() {
const streams = [{ stream: process.stdout }];
const { accessKeyId, secretAccessKey, region } = config.aws;
if (process.env.NODE_ENV === 'production' && accessKeyId && secretAccessKey) {
const writeStream = cloudwatch({
interval: 2000,
aws_access_key_id: accessKeyId,
aws_secret_access_key: secretAccessKey,
aws_region: region,
group: '/app/rsschool-api',
});
streams.push(writeStream);
}
return pinoLogger({ streams, base: null }) as ILogger;
}
export const initLogger = (isDev = false) => {
app.setAppLogsPath()
const logBasePath = app.getPath('logs')
const fileOutStream = (title: string) => createWriteStream(`${logBasePath}/${app.name}.${title}.log`, { flags: 'a' })
const devlogs = isDev ? [
{ level: 'trace', stream: pinoms.prettyStream() },
{ level: 'trace', stream: fileOutStream('trace') }
] : []
const lg: Logger = pinoms({
streams: [
...devlogs,
{ level: 'info', stream: fileOutStream('info') },
{ level: 'warn', stream: fileOutStream('warn') },
{ level: 'error', stream: fileOutStream('error') },
{ level: 'fatal', stream: fileOutStream('fatal') }
]
}) as Logger
const master = lg.child({ ver: app.getVersion() })
const main = master.child({ platform: 'electron-main' })
const rdr = master.child({ platform: 'electron-renderer' })