javascript - node.js automatic logging with metadata -


I have a node. I want to create JS log decorator that works like this (pseudocode warning):

  log = function (f) {return function () {log (f.file, f) .line, F.Class, FNN, Arguments) Return Fiscal (this, Arguments)}} Is there any way to access the information given above? I'm going to heavy logging, so throwing a fake  exception  and reading trace is probably not viable (or is it?).  

Note: By f.class I mean the name of the function in which prototype is. In addition, I am using the coffee-script , if this is the case

You throw is not an exception, var stack = new error (). Stack is enough to parse file, line number and class name from there. But The problem is, that this function tracks calls, so to get the proper information for the decoration function now start functioning error or something in the class needed . To do this in the decorator, you can only get information about the file / linum where the function was decorated, and where the function was not declared. Function User () {} User.prototype.foo = function () {}; User.stack_ = function () {new error (). Stack}; // ... function rap (ctor, name) {var stack = Ctor.stack_ (); Var info = parseStack (stack); Var orig_ = Ctor.prototype [name]; Ctor.prototype [name] = function () {console.log ('info:', info); Back orig_.apply (this, argument); }; } Function parseStack (stack) {// Improved stacktrace parser return stack.split ('\ n') [1]; } // ... wrap (user, 'foo'); // ... var user = new user; User.foo (); // And you get the face like // info: on function User.stack_ (file name: line: column)

I think this can be maximized, and you should always do this stack _ function.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -