Edit Page

Custom log messages

It is often useful to emit custom log messages or events from your application code; whether you are tracking the status of outbound emails sent in the background, or just looking for a configurable alternative to calling console.log() in your application code.

For convenience, Sails exposes its internal logging interface as sails.log. Its usage is purposely very similar to Node's console.log(), but with a handful of extra features; namely support for multiple log levels with colorized, prefixed console output.

See sails.log() for more information and examples, or sails.config.log for configuration options.

Available methods

Each of the log methods below accepts an infinite number of arguments of any data type, seperated by commas. Like console.log, data passed as arguments to the Sails logger are automatically prettified for readability using Node's util.inspect(). Consequently, standard Node.js conventions apply; any dictionaries, errors, dates, arrays, or other data types are pretty-printed using the built-in logic in util.inspect() (e.g. you see { pet: { name: 'Hamlet' } } instead of [object Object].) Also, if you log an object that has a custom inspect() method, the logger will run that method automatically and write the string it returns to the console.

sails.log.error()

Writes log output to stderr at the "error" log level. Useful for tracking major errors.

sails.log.error('Sending 500 ("Server Error") response.');
// -> error: Sending 500 ("Server Error") response.

sails.log.warn()

Writes log output to stderr at the "warn" log level. Useful for tracking information about operations that failed silently.

sails.log.warn('File upload quota exceeded for user #%d.  Request aborted.', user.id);
// -> warn: File upload quota exceeded for user #94271.  Request aborted.

sails.log()

aka sails.log.debug()

The default log function, which writes console output to stderr at the "debug" log level. Useful for passing around important technical information amongst your team; or as a general alternative to console.log().

sails.log('This endpoint (`POST /accounts`) will be deprecated in the next few days.  Please use `POST /signup` instead. ');
// -> debug: This endpoint (`POST /accounts`) will be deprecated in the next few days.  Please use `POST /signup` instead.

sails.log.info()

Writes log output to stdout at the "info" log level. Useful for capturing information about your app's business logic.

sails.log.info('A new user (', newUser.emailAddress, ') just signed up!');
// -> info: A new user ( [email protected] ) just signed up!

sails.log.verbose()

Writes log output to stdout at the "verbose" log level. Useful for capturing detailed information about your app that you only need on rare occasions.

sails.log.verbose('A user (IP adddress: `%s`) initiated an account transfer...', req.ip);
// -> verbose: A user (IP adddress: `10.48.1.191`) initiated an account transfer...

sails.log.silly()

Writes log output to stdout at the "silly" log level. Useful for capturing technical details about your app that are only useful for diagnostics and/or troubleshooting.

sails.log.silly(
'Successfully fetched Account record for requesting authenticated user (`%d`).',
'Took %dms.', req.param('id'), msElapsed);
// -> silly: Successfully fetched Account record for authenticated user (`49722`). Took 41ms.

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails-docs repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Sails logo
  • Home
  • Get started
  • Support
  • Documentation
  • Documentation

For a better experience on sailsjs.com, update your browser.

Documentation

Reference Concepts App structure | Upgrading Contribution guide | Tutorials More

Concepts

  • Assets
    • Default Tasks
    • Disabling Grunt
    • Task Automation
  • Blueprints
    • Blueprint Actions
    • Blueprint Routes
  • Configuration
    • The local.js file
    • Using `.sailsrc` Files
  • Controllers
    • Generating Controllers
    • Routing to Controllers
  • Custom Responses
    • Adding a Custom Response
    • Default Responses
  • Deployment
    • FAQ
    • Hosting
    • Scaling
  • Extending Sails
    • Adapters
      • Available Adapters
      • Custom Adapters
    • Generators
      • Available Generators
      • Custom Generators
    • Hooks
      • Hook Specification
        • .configure()
        • .defaults
        • .initialize()
        • .routes
      • Installable Hooks
      • Project Hooks
      • Using Hooks
  • File Uploads
    • Uploading to GridFS
    • Uploading to S3
  • Globals
    • Disabling Globals
  • Internationalization
    • Locales
    • Translating Dynamic Content
  • Logging
    • Custom log messages
  • Middleware
    • Conventional Defaults
  • Models and ORM
    • Associations
      • Dominance
      • Many-to-Many
      • One Way Association
      • One-to-Many
      • One-to-One
      • Through Associations
    • Attributes
    • Lifecycle callbacks
    • Model Settings
    • Models
    • Query Language
    • Validations
  • Policies
    • Sails + Passport
  • Programmatic Usage
    • Tips and Tricks
  • Realtime
    • Multi-server environments
    • On the client
    • On the server
  • Routes
    • Custom Routes
    • URL Slugs
  • Security
    • Clickjacking
    • Content Security Policy
    • CORS
    • CSRF
    • DDOS
    • P3P
    • Socket Hijacking
    • Strict Transport Security
    • XSS
  • Services
    • Creating a Service
  • Sessions
  • Testing
  • Views
    • Layouts
    • Locals
    • Partials
    • View Engines

Built with Love

The Sails framework is maintained by a web & mobile studio in Austin, TX, with the help of our contributors. We created Sails in 2012 to assist us on Node.js projects. Naturally we open-sourced it. We hope it makes your life a little bit easier!

Sails:
  • What is Sails?
  • Treeline IDE
  • Contribute
  • Logos/artwork
About:
  • The Sails Company
  • Security
  • News
  • Legal
Help:
  • Get started
  • Documentation
  • Docs
  • Enterprise
  • Hire us

© 2012-2018 The Sails Company. 
The Sails framework is free and open-source under the MIT License.