node-opcua-debug
Advanced tools
Comparing version 0.5.0 to 0.5.5
@@ -1,2 +0,2 @@ | ||
export declare function trace_from_this_projet_only(err: Error): string; | ||
export declare function display_trace_from_this_projet_only(err: Error): void; | ||
export declare function trace_from_this_projet_only(err?: Error): string; | ||
export declare function display_trace_from_this_projet_only(err?: Error): void; |
@@ -10,3 +10,3 @@ "use strict"; | ||
} | ||
err = err || new Error(); | ||
err = err || new Error("Error used to extract stack trace"); | ||
let stack = err.stack; | ||
@@ -13,0 +13,0 @@ if (stack) { |
export declare function setDebugFlag(scriptFullpath: string, flag: boolean): void; | ||
export declare function checkDebugFlag(script_fullpath: string): boolean; | ||
export declare function checkDebugFlag(scriptFullpath: string): boolean; | ||
/** | ||
@@ -10,2 +10,2 @@ * @method make_debugLog | ||
*/ | ||
export declare function make_debugLog(scripFullpath: string): Function; | ||
export declare function make_debugLog(scripFullpath: string): (...arg: any[]) => void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// tslint:disable:no-console | ||
const chalk_1 = require("chalk"); | ||
const path = require("path"); | ||
const _ = require("underscore"); | ||
let debugFlags = {}; | ||
const util_1 = require("util"); | ||
const debugFlags = {}; | ||
function w(str, l) { | ||
@@ -13,4 +15,4 @@ return (str + " ").substr(0, l); | ||
if (process.env.DEBUG) { | ||
const decorated_filename = chalk_1.default.yellow(w(filename, 30)); | ||
console.log(" Setting debug for ", decorated_filename, " to ", (flag ? chalk_1.default.cyan : chalk_1.default.red)(flag.toString())); | ||
const decoratedFilename = chalk_1.default.yellow(w(filename, 30)); | ||
console.log(" Setting debug for ", decoratedFilename, " to ", (flag ? chalk_1.default.cyan : chalk_1.default.red)(flag.toString())); | ||
} | ||
@@ -20,4 +22,4 @@ debugFlags[filename] = flag; | ||
exports.setDebugFlag = setDebugFlag; | ||
function checkDebugFlag(script_fullpath) { | ||
const filename = path.basename(script_fullpath, ".js"); | ||
function checkDebugFlag(scriptFullpath) { | ||
const filename = path.basename(scriptFullpath, ".js"); | ||
let doDebug = debugFlags[filename]; | ||
@@ -31,4 +33,5 @@ if (process && process.env && process.env.DEBUG && !debugFlags.hasOwnProperty(filename)) { | ||
exports.checkDebugFlag = checkDebugFlag; | ||
function file_line(filename, caller_line) { | ||
return chalk_1.default.bgWhite.cyan(w(filename, 30) + ":" + w(caller_line.toString(), 5)); | ||
function file_line(filename, callerLine) { | ||
const d = (new Date()).toISOString().substr(11); | ||
return chalk_1.default.bgWhite.cyan(w(d, 14) + ":" + w(filename, 30) + ":" + w(callerLine.toString(), 5)); | ||
} | ||
@@ -47,10 +50,21 @@ /** | ||
if (debugFlags[filename]) { | ||
const stack = new Error().stack || ""; | ||
const stack = new Error("").stack || ""; | ||
// caller line number | ||
const l = stack.split("\n")[2].split(":"); | ||
const caller_line = parseInt(l[l.length - 2]); | ||
const a1 = [file_line(filename, caller_line)]; | ||
const callerLine = parseInt(l[l.length - 2], 10); | ||
let a1 = [file_line(filename, callerLine)]; | ||
const a2 = _.values(arguments); | ||
const args = [].concat(a1, a2); | ||
console.log.apply(console, args); | ||
const output = util_1.format.apply(null, a2); | ||
let i = 0; | ||
for (const line of output.split("\n")) { | ||
const args = [].concat(a1, [line]); | ||
console.log.apply(console, args); | ||
a1 = [w(" ... ", 51)]; | ||
i = i + 1; | ||
if (i > 20) { | ||
const a3 = a1.concat([" .... TRUNCATED ....."]); | ||
console.log.apply(console, a3); | ||
break; | ||
} | ||
} | ||
} | ||
@@ -57,0 +71,0 @@ } |
{ | ||
"name": "node-opcua-debug", | ||
"version": "0.5.0", | ||
"version": "0.5.5", | ||
"description": "pure nodejs OPCUA SDK - module -debug", | ||
@@ -37,3 +37,3 @@ "scripts": { | ||
"homepage": "http://node-opcua.github.io/", | ||
"gitHead": "7c2f2dcb6ebdc49e57da1a028406a307df502d4e" | ||
"gitHead": "14cbd30c33c966a33fa6dade7d4520edd2098cb8" | ||
} |
import chalk from "chalk"; | ||
export function trace_from_this_projet_only(err: Error): string { | ||
export function trace_from_this_projet_only(err?: Error): string { | ||
@@ -10,3 +10,3 @@ const str = []; | ||
} | ||
err = err || new Error(); | ||
err = err || new Error("Error used to extract stack trace"); | ||
let stack: any = err.stack; | ||
@@ -23,4 +23,4 @@ if (stack) { | ||
export function display_trace_from_this_projet_only(err: Error): void { | ||
export function display_trace_from_this_projet_only(err?: Error): void { | ||
console.log(trace_from_this_projet_only(err)); | ||
} |
@@ -0,6 +1,8 @@ | ||
// tslint:disable:no-console | ||
import chalk from "chalk"; | ||
const path = require("path"); | ||
const _ = require("underscore"); | ||
import * as path from "path"; | ||
import * as _ from "underscore"; | ||
import { format } from "util"; | ||
let debugFlags: { [id: string]: boolean } = {}; | ||
const debugFlags: { [id: string]: boolean } = {}; | ||
@@ -14,6 +16,6 @@ function w(str: string, l: number): string { | ||
if (process.env.DEBUG) { | ||
const decorated_filename = chalk.yellow(w(filename, 30)); | ||
const decoratedFilename = chalk.yellow(w(filename, 30)); | ||
console.log( | ||
" Setting debug for ", | ||
decorated_filename, | ||
decoratedFilename, | ||
" to ", | ||
@@ -26,4 +28,4 @@ (flag ? chalk.cyan : chalk.red)(flag.toString()) | ||
export function checkDebugFlag(script_fullpath: string): boolean { | ||
const filename = path.basename(script_fullpath, ".js"); | ||
export function checkDebugFlag(scriptFullpath: string): boolean { | ||
const filename = path.basename(scriptFullpath, ".js"); | ||
let doDebug:boolean = debugFlags[filename]; | ||
@@ -37,4 +39,5 @@ if (process && process.env && process.env.DEBUG && !debugFlags.hasOwnProperty(filename)) { | ||
function file_line(filename: string, caller_line: number):string { | ||
return chalk.bgWhite.cyan(w(filename, 30) + ":" + w(caller_line.toString(), 5)); | ||
function file_line(filename: string, callerLine: number): string { | ||
const d = (new Date()).toISOString().substr(11); | ||
return chalk.bgWhite.cyan(w(d, 14) + ":" + w(filename, 30) + ":" + w(callerLine.toString(), 5)); | ||
} | ||
@@ -48,3 +51,3 @@ /** | ||
*/ | ||
export function make_debugLog(scripFullpath: string): Function { | ||
export function make_debugLog(scripFullpath: string): (...arg: any[]) => void { | ||
@@ -57,10 +60,23 @@ const doDebug: boolean = checkDebugFlag(scripFullpath); | ||
if (debugFlags[filename]) { | ||
const stack: string = new Error().stack || ""; | ||
const stack: string = new Error("").stack || ""; | ||
// caller line number | ||
const l: Array<string> = stack.split("\n")[2].split(":"); | ||
const caller_line: number = parseInt(l[l.length - 2]); | ||
const a1:string[] = [file_line(filename, caller_line)]; | ||
const a2:string[] = _.values(arguments); | ||
const args :string[] = ([] as string[]).concat(a1, a2); | ||
console.log.apply(console, args); | ||
const l: string[] = stack.split("\n")[2].split(":"); | ||
const callerLine: number = parseInt(l[l.length - 2], 10); | ||
let a1: string[] = [file_line(filename, callerLine)]; | ||
const a2: string[] = _.values(arguments); | ||
const output = format.apply(null, a2 as [string, ...string[]]); | ||
let i = 0; | ||
for (const line of output.split("\n")) { | ||
const args: string[] = ([] as string[]).concat(a1, [line]); | ||
console.log.apply(console, args as [string, ...string[]]); | ||
a1 = [w(" ... ", 51)]; | ||
i = i + 1; | ||
if (i > 20) { | ||
const a3 = a1.concat([" .... TRUNCATED ....."]); | ||
console.log.apply(console, a3 as [string, ...string[]]); | ||
break; | ||
} | ||
} | ||
} | ||
@@ -71,2 +87,1 @@ } | ||
} | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
37343
40
567