OnCircle logging utility module
CoffeeScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test/spec
.gitignore
.travis.yml
Gruntfile.coffee
README.md
package.json
roip-logger.coffee

README.md

RoIP Logger Module

Environment

  • LOG_LEVEL: (optional: default 'debug') debug, info, notice, warning, error, crit, alert, emerg. Production deployments should typically use 'info' level.

Console Log Configuration

  • LOG_CONSOLE_ENABLED: (optional: defaults to true) Set to true or yes, Enables file console transport.

File Log Configuration

  • LOG_FILE_ENABLED: (optional: defaults to true) Set to true or yes, Enables file logging transport.
  • LOG_FILE_PATH: (optional: default cwd/log/#{NODE_ENV}.log) Path for log file.

Syslog Configuration

Syslog can be enabled by setting LOG_SYSLOG_ENABLED environment variable. All other parameters are optional.

  • LOG_SYSLOG_ENABLED: (optional: defaults to 'false') Set to true or yes, Enables syslog logging transport.
  • LOG_SYSLOG_HOST: (optional: defaults to 'localhost') Syslog host
  • LOG_SYSLOG_PORT: (optional: defaults to 514) Syslog port
  • LOG_SYSLOG_PATH: (optional: defaults to null) Syslog path
  • LOG_SYSLOG_APP_ID: (optional: defaults to null) Syslog APP ID
  • LOG_SYSLOG_LOCALHOST: (optional: defaults to 'localhost') localhost as reported to syslog
  • LOG_SYSLOG_PROTOCOL: (optional: defaults to udp4) Syslog protocol (Values: udp,unix,tcp)
  • LOG_SYSLOG_TYPE: (optional: defaults to 'BSD') Syslog type
  • LOG_SYSLOG_FACILITY: (optional: defaults to 'local0') Syslog facility
  • LOG_SYSLOG_PID: (optional: defaults to process.pid) Process ID for reporting to syslog
  • LOG_SYSLOG_APP_NAME: (optional: defaults to process.title) Process title for reporting to syslog

Get Started

Configure package.json

{
  ...
  "dependencies": {
    "roip-logger": "git+ssh://git@github.com:OnCircle/node-logger.git"
  },
}

Examples:

# Start using logger module:
logger = require "roip-logger"

logger.debug("Message", obj1)
logger.debug("Message", obj1, "and here", obj3)
logger.error(err)
logger.error("Error is here:", err)
logger.warning("warning is here")
logger.warning("warning is here", err)
logger.info("some info message")
logger.emerg("something really bad happened")
logger.log("info", "aaaa", "bbb")
logger.log("debug", "aaaa", "bbb")

# Error logging with stack trace
logger.error(err)
logger.error("Caught some error:", err)
logger.warning("Caught some error:", err)
logger.info(err)

# Express Request Logger and Error Handler
# As a convenience, logger provides logger.expressRequestLogger and logger.expressErrorHandler
# Typically, expressRequestLogger is configured as the first middleware and expressErrorHandler is configured last.
app.disable('x-powered-by')
app.use logger.expressRequestLogger
app.use express.limit('1mb')
app.use express.timeout(5000)
app.use utils.allowCrossDomain
app.use express.methodOverride()
app.use express.bodyParser()
app.use app.router
app.use logger.expressErrorHandler

Additional Notes

  • You can log complete objects using logger. They will be dumped into the log using util.inspect().
  • You can send Error objects to the logger, they will be dumped in the log along with their stack traces (if present).
  • Messages longer than 1024 characters long will be truncated.
  • Generally, use logger.debug for debug messages during development. Production systems are set to "info" LOG_LEVEL, so any debug messages are not logged in production.

Execution Time Profiler

logger.profile "MyMegaAsyncOperation"
  # perform async operation
  logger.profile "MyMegaAsyncOperation"