aboutsummaryrefslogtreecommitdiffstats
path: root/uni/unimgr/dbg.js
blob: a5804d131c084a6612f203bc411587b362067637 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*******************************************************************************
* Copyright (c) 2015 CableLabs Inc. and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution, and is available at
* http://www.apache.org/licenses/LICENSE-2.0
*******************************************************************************/

(function(){
  
	var dbgFlag = true;
	var pre = ""

	var on  = function() { dbgFlag = true; };
	var off = function() { dbgFlag = false; };

	var p   = function(str, tab) { 
		if ( dbgFlag ) 
		{
			var tabStr = "";
			if (tab) {
			  for (var i = 0; i < tab; i++ )
				 tabStr += "    ";
			}
			console.log(pre + tabStr + str);
		}
	};

	var pj  = function(obj) { 
		if ( dbgFlag ) 
			console.log(JSON.stringify(obj,null,3)) ;
	};

	var e = function(eMsg) {
	  console.log("!! ERROR: " + eMsg);
	}

	var w = function(eMsg) {
	  console.log("** WARNIING: " + eMsg);
	}
		
	// for testing.  Write regaurdless of dbgFlag
	var t   = function(str, tab) { 
		var tabStr = "";
		if (tab) {
		  for (var i = 0; i < tab; i++ )
			 tabStr += "    ";
		}
		console.log(pre + tabStr + str);
	}

function curTime() {

    var date = new Date();

    var hour = date.getHours();
    hour = (hour < 10 ? "0" : "") + hour;

    var min  = date.getMinutes();
    min = (min < 10 ? "0" : "") + min;

    var sec  = date.getSeconds();
    sec = (sec < 10 ? "0" : "") + sec;

    // var year = date.getFullYear();

    // var month = date.getMonth() + 1;
    // month = (month < 10 ? "0" : "") + month;

    // var day  = date.getDate();
    // day = (day < 10 ? "0" : "") + day;

    // return year + ":" + month + ":" + day + ":" + hour + ":" + min + ":" + sec;

    return hour + ":" + min + ":" + sec;


}

	module.exports.curTime  = curTime; // returns str w current time

	module.exports.on  = on;   //   enable DBG printing
	module.exports.off = off;  //   squelch DBG printing 
	module.exports.p   = p;    //   print a debug string
	module.exports.pj  = pj;   //   print JSON version of an object
	module.exports.w   = w;    //   print an warning msg
	module.exports.e   = e;    //   print an error msg
	module.exports.t   = t;    //   print an error msg



}());