I am trying to add info/error logs in log files. For that, i make changes in logger.ts file and controller file. Both file's code i mansion below. I also add "pino-pretty" package in my project. Please help me to add logs in some files to further checks. Please let me know if any other changes are needed. adonis.js version 6
logger.ts
import env from '#start/env'
import app from '@adonisjs/core/services/app'
import { defineConfig, targets } from '@adonisjs/core/logger'
const loggerConfig = defineConfig({
default: 'app',
loggers: {
app: {
enabled: true,
name: env.get('APP_NAME'),
level: env.get('LOG_LEVEL', 'info'),
transport: {
targets: targets()
.push({
target: 'pino-roll',
level: 'info',
options: {
file: '/var/log/apps/adonisjs.log',
frequency: 'daily',
mkdir: true,
},
})
.toArray(),
},
redact: {
paths: ['password', '*.password'],
},
},
},
})
export default loggerConfig
declare module '@adonisjs/core/types' {
export interface LoggersList extends InferLoggers<typeof loggerConfig> {}
}
controller file
import logger from '@adonisjs/core/services/logger'
export default class LocationsController {
async index({ request, response }: HttpContext) {
try {
logger.info('this is an info message')
logger.debug('request', request.all())
} catch (e) {
}
}
}
I only needed to remove the first forward slash (/) from the file path:
options: {
file: 'var/log/apps/adonisjs.log',
frequency: 'daily',
mkdir: true,
},