Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'pino-multi-stream' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
/* 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' })