ponymail-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject incubator-ponymail git commit: Handy Python trace tool
Date Wed, 16 Nov 2016 16:24:36 GMT
Repository: incubator-ponymail
Updated Branches:
  refs/heads/master f63c7090a -> 8b86f187d


Handy Python trace tool

Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/8b86f187
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/8b86f187
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/8b86f187

Branch: refs/heads/master
Commit: 8b86f187d9c5d105386b37f777063847dab37e71
Parents: f63c709
Author: Sebb <sebb@apache.org>
Authored: Wed Nov 16 16:24:16 2016 +0000
Committer: Sebb <sebb@apache.org>
Committed: Wed Nov 16 16:24:16 2016 +0000

----------------------------------------------------------------------
 tools/trace.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/8b86f187/tools/trace.py
----------------------------------------------------------------------
diff --git a/tools/trace.py b/tools/trace.py
new file mode 100644
index 0000000..7a565c5
--- /dev/null
+++ b/tools/trace.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python3.4
+# -*- coding: utf-8 -*-
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""
+Simple trace facility for local debugging.
+Shows a message together with its location.
+
+N.B. This is intended as a handy tool for local use only;
+not intended for use in deployed code.
+
+Usage:
+
+from trace import trace
+...
+    trace("Message-id %s" % message-id)
+    ...
+    trace("Message-id %s" % message-id)
+    ...
+    trace("Message-id %s" % message-id)
+
+The output includes the line number so there is
+no need to customise the messages to id them.
+"""
+import inspect
+from os.path import basename
+
+def trace(s='', depth=1):
+    """
+    Show message with context from the caller
+    """
+    stack=inspect.stack()
+    maxIndex = len(stack) - 1
+    depth = maxIndex if depth >= maxIndex else depth
+    frame,filename,line_number,function_name,lines,index = stack[depth]
+    print(">>>>[%d]%s@%s#%s: %s"%(depth,basename(filename),line_number,function_name,s))
+
+if __name__ == '__main__':
+    trace("test")
+    trace("test",0)
+    trace("test",2)


Mime
View raw message