User Tools

Site Tools


Sidebar

General

Python Tutorials

WebGL Tutorials

Node.js Tutorials

Node.js in WebStorm


Martin Christen

View Martin Christen's profile on LinkedIn


Twitter

Timeline of @MartinChristen

MartinChristen avatar

RT @snebiker: #PlayGameLieschtel - brilliant event by Kantonsbibliothek Baselland #KBL to get kids into libraries, including family #gamede…
About 2 days, 14 hours ago by: Martin Christen (@MartinChristen)

MartinChristen avatar

Only a handful tickets left for @PyConDE in Karlsruhe (October 24-28, 2018) - The schedule is now available at… https://t.co/Og4fp3DsoA
About 5 days, 7 hours ago by: Martin Christen (@MartinChristen)

MartinChristen avatar

IAMCP & @swissmade_sw Augmented Reality event just started https://t.co/bdREI6lJM4 #ar #AugmentedReality #Basel… https://t.co/9KpsdU3fvM
About 6 days, 13 hours ago by: Martin Christen (@MartinChristen)
node:tutorial06

Node.js Tutorials - Part 0

Node.js Tutorial 6

Mastering the Console

Logging using console.log/info/error/warn

Text base logging can be done using the following functions:

  • console.log([data], […])
  • console.info([data], […])
  • console.error([data], […])
  • console.warn([data], […])

log: general logging
info: for information
error: for errors (output to stderr)
warn: for warnings (output to stderr)

animal = "fox";
count = 5;

In node.js the following substitution patterns are available: %s: string %d: number

Example:

console.log("The %s jumped over %d lazy dogs", animal, count);

The same can be achieved without using substitution patterns:

console.log("The", animal, "jumped over", count, "lazy dogs");

An object can be listed using console.dir().

More string subsitution possibilities are available in the util module using the function: util.format().

Logging using util.log

The util module has some log mechanims too. util.log is used for logging with timestamp:

util = require('util');
util.log('Log Message With Timestamp');

The result would be:

5 Jul 13:02:22 - Log Message With Timestamp


node/tutorial06.txt · Last modified: 2013/09/16 22:05 by mchristen