How to parse (query) logs from file


#1

I write logs on file, like:

const Logger = use('Logger')

      Logger
        .transport('file')
        .error('Error has happened!', {
          url: request.url(),
          errorMessage: error.message,
          errorData: error,
        })


Then how can I query this logs?

this doesn’t work

Logger.query(options, function (err, results) {
  console.log(results);
});

#2

if you anyone need it

'use strict'

const Helpers = use('Helpers')
const Logger = use('Logger')
const Winston = Helpers.promisify(Logger._loggerInstances.file.driver.logger)

class LogController {
	
	async index({response, view}) {
		
		//lastday
		const options = {
			from: new Date() - (24 * 60 * 60 * 1000),
			until: new Date(),
			limit: 100,
			start: 0,
			order: 'desc',
			fields: ['message']
			};
			
			const result = await Winston.query(options)
		  
			console.log(result)
			// return view.render('logs', {logs:result})
			return response.send({logs:result})
	}
}

module.exports = LogController