Skip to content

.log, .error, .debug

Robbie Chipka edited this page Dec 23, 2015 · 2 revisions

Osmosis has 3 different logging commands: log, error, and debug. Each of these takes a callback function with just one argument: the message being logged. Logging functions can be placed multiple times at any point along the command chain. This allows you control what gets logged where and helps in tracking down any errors.

####osmosis.log General logging, such as:

  • URL being followed
  • URL loaded
  • Number of elements found

####osmosis.error Error logging, such as:

  • HTTP errors
  • Parse errors
  • No elements found

####osmosis.debug Debugging, such as:

  • Process stats (stack size, RAM Usage, total HTTP requests)

###Example

osmosis
.get('example.com/items')
...
.find('li.item')
.log(function(msg) {
    fs.writeFileSync(logFile, 'li.item - '+msg)
})
...
.log(console.log)
.error(console.error)
.debug(util.debug)
Clone this wiki locally