Is there any way to log in a file like laravel?


#1

I am trying to find a way to log like laravel. In laravel we log like this
\Log::info(‘something…’) and it’s stored in a log file. Is there anything like this in adonis.js?
Thank you.


#2

Hi Hkmsadek :wave: .

In fact, there is.

First you need to set in config/app.js how it should be logged, e.g. file or the database.

after, you smily do:

const Logger = use('Logger')

Logger.info('Something... ');  

edit:
I found the doc:
https://adonisjs.com/docs/4.1/logger

:slight_smile:


#3

if I use default settings in app.js as it is, then where it will save the log data? I couldn’t find it anywhere in my project. Where it saves?


#4

console output, I think.


#5

Hey @hkmsadek
It saves it in the console output, but if you want to store it in an easily accessible log file, you can do so by using file as transport in config/app.js

logger: {
  transport: 'file',
  console: {
    driver: 'console'
  },
  file: {
    driver: 'file',
    filename: 'adonis.log'
  }
}

The filename can be a relative path to the file you want to save the logs to.


#6

Thanks it solved my problem :slight_smile: