varAA =function() {log ("XXXX");}; AA ();varModel ={};model.test=function() {log ("Model.test");}; Model.test ();functionlog (msg) {varinfo =Stackinfo (); varMethod = Info[' method ']; varFile = info[' file ']; varline = info[' line ']; Console.log (("+ method +") < "+ File +": "+ line +" > "+msg);}
Here is the Main methodfunctionStackinfo () {varPath = require (' path '); varStackreg =/at\s+ (. *) \s+\ ((. *):(\d*):(\d*)/i; varSTACKREG2 =/at\s+ () (. *):(\d*):(\d*)/i; varStacklist = (NewError ()). Stack.split (' \ n '). Slice (3); vars = stacklist[0]; varSP = stackreg.exec (s) | |Stackreg2.exec (s); vardata = {}; if(sp && Sp.length = = = 5) {Data.method= Sp[1]; Data.path= Sp[2]; Data.line= Sp[3]; Data.pos= Sp[4]; Data.file=Path.basename (Data.path); } returndata;}
Output format content:
(AA) <c.js:6> xxxx
(Object.model.test) <c.js:12> model.test
Nodejs get function name and function operation collation