diff --git a/public/js/wn/request.js b/public/js/wn/request.js index a40ca93b9e..5139c8f109 100644 --- a/public/js/wn/request.js +++ b/public/js/wn/request.js @@ -151,8 +151,8 @@ wn.request.cleanup = function(opts, r) { } // show messages - if(r.server_messages) { - r.server_messages = JSON.parse(r.server_messages) + if(r._server_messages) { + r._server_messages = JSON.parse(r._server_messages) msgprint(r.server_messages); } @@ -164,10 +164,15 @@ wn.request.cleanup = function(opts, r) { if(v)console.log(v); }) } else { - console.log(r.exc); + console.log(r.exc); } }; + // debug messages + if(r._debug_messages) { + $.each(JSON.parse(r._debug_messages), function(i, v) { console.log(v); }); + } + if(r['403']) { wn.set_route('403'); } diff --git a/webnotes/__init__.py b/webnotes/__init__.py index 854a6cc2de..ac3e22e7f1 100644 --- a/webnotes/__init__.py +++ b/webnotes/__init__.py @@ -68,6 +68,7 @@ incoming_cookies = {} add_cookies = {} # append these to outgoing request cookies = {} response = _dict({'message':'', 'exc':''}) +error_log = [] debug_log = [] message_log = [] mute_emails = False @@ -105,7 +106,16 @@ def errprint(msg): print repr(msg) from utils import cstr - debug_log.append(cstr(msg or '')) + error_log.append(repr(msg)) + +def log(msg): + if not request_method: + import conf + if getattr(conf, "logging", False): + print repr(msg) + + from utils import cstr + debug_log.append(cstr(msg)) def msgprint(msg, small=0, raise_exception=0, as_table=False): from utils import cstr diff --git a/webnotes/handler.py b/webnotes/handler.py index 0f66527f53..b914e542f6 100755 --- a/webnotes/handler.py +++ b/webnotes/handler.py @@ -213,6 +213,7 @@ def get_method(cmd): method = webnotes.get_method(cmd) else: method = globals()[cmd] + webnotes.log("method:" + cmd) return method def print_response(): @@ -257,7 +258,7 @@ def print_iframe(): eprint("") eprint(webnotes.response.get('result') or '') - if webnotes.debug_log: + if webnotes.error_log: import json eprint("""\ """ % { 'messages': json.dumps(webnotes.message_log).replace("'", "\\'"), - 'errors': json.dumps(webnotes.debug_log).replace("'", "\\'"), + 'errors': json.dumps(webnotes.error_log).replace("'", "\\'"), }) def print_raw(): @@ -289,13 +290,16 @@ def print_raw(): def make_logs(): """make strings for msgprint and errprint""" - import json + import json, conf from webnotes.utils import cstr - if webnotes.debug_log: - webnotes.response['exc'] = json.dumps("\n".join([cstr(d) for d in webnotes.debug_log])) + if webnotes.error_log: + webnotes.response['exc'] = json.dumps("\n".join([cstr(d) for d in webnotes.error_log])) if webnotes.message_log: - webnotes.response['server_messages'] = json.dumps([cstr(d) for d in webnotes.message_log]) + webnotes.response['_server_messages'] = json.dumps([cstr(d) for d in webnotes.message_log]) + + if webnotes.debug_log and getattr(conf, "logging", False): + webnotes.response['_debug_messages'] = json.dumps(webnotes.debug_log) def print_cookie_header(): """if there ar additional cookies defined during the request, add them"""