Noitidart
Noitidart

Reputation: 37238

Disable request logs in terminal

Is it possible to turn off sails request logs. Like I'm trying to not see the example pasted below. Because when I run my integration tests, these logs get in the way of the report.

<- PUT /api/v1/entrance/login                 (361ms 200)
 |  The requesting user agent has been successfully logged in.
 |  
 |  Under the covers, this stores the id of the logged-in user in the session as the `userId` key.  The next time this user agent sends a request, assuming it includes a cookie (like a web browser), Sails will automatically make this user id available as req.session.userId in the corresponding action.  (Also note that, thanks to the included "custom" hook, when a relevant request is received from a logged-in user, that user's entire record from the database will be fetched and exposed as `req.me`.)
 |  
 ° 
<- GET /api/v1/user/me/overview/subscribe     (26ms 200)

Upvotes: 2

Views: 435

Answers (4)

Anselmo Park
Anselmo Park

Reputation: 1011

I think you set test cases similar with me.

I added configuration in my ./test/lifecycle.test.js.

'./lifecycle.test.js` is addressed in https://sailsjs.com/documentation/concepts/testing#?lifecycletestjs

When I call sails.lift() in it, I added this configuration as below:

  sails.lift(
    {
      log: { level: 'silent' },
      apianalytics: { routesToLog: [] },
    },

And then, I could see only mocha log.

Upvotes: 1

matpop
matpop

Reputation: 2020

To disable requests logging only in production, it may be convenient to just add the configuration to config/env/production.js, leaving the routesToLog property as an empty array, thereby no logging routine will be bound to any event, so there'll be no overhead whatsoever.

Upvotes: 2

Dejan Kubaša
Dejan Kubaša

Reputation: 191

It's sails hook. https://www.npmjs.com/package/sails-hook-apianalytics

Read documentation, u can edit logs or disable some of them, or just uninstall hook.

Run npm uninstall sails-hook-apianalytics on root of project and then lift sails.

Upvotes: 3

If you check the sails.js documentation about logs, you can change the level of logs as you want. There are several ways to accomplish that, but i prefer to put the log level in the env file, because some logs are not needed in production but in development make sense and is ease to do this:

// config/env/production.js
module.exports = {
  ...
  log: {
    level: 'debug'
  }
  ...
}

Upvotes: 1

Related Questions