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

On my way to the 3D city model workshop in Bonn where I‘m presenting our latest @igeoFHNW #AugmentedReality App… https://t.co/8ghq4GfZW5
About 5 days, 7 hours ago by: Martin Christen (@MartinChristen)

MartinChristen avatar

Teaching #Python to 11-13-year-old girls was great fun today at the Swiss national future day (#zukunftstag).… https://t.co/1lDmWdl02D
About 1 week, 2 days ago by: Martin Christen (@MartinChristen)

MartinChristen avatar

RT @GeoPythonConf: Interested in joining GeoPython 2019? Register to the mailing list: https://t.co/ub3CU7L5WL #python #GeoPython #geospat…
About 2 weeks, 2 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