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 @TFConsult: Celebrating 100th birthday of #physicist #RichardFeynman: The marvellous #Feynman lectures on #physics: https://t.co/81as7mN
About 1 week, 4 days ago by: Martin Christen (@MartinChristen)

MartinChristen avatar

RT @sergerey: Had a fantastic time giving our workshop on Spatial Data Science with PyData at @GeoPythonConf with @levijohnwolf. Looking f…
About 1 week, 5 days ago by: Martin Christen (@MartinChristen)

MartinChristen avatar

RT @fridex: Everything has an end even such an excellent conference #GeoPythonConf in Basel. Thanks to organizers for such an outstanding c…
About 1 week, 5 days 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