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: Simple-minded debug trace for Lua
Date Wed, 16 Nov 2016 19:53:54 GMT
Repository: incubator-ponymail
Updated Branches:
  refs/heads/master 62fbfb5ff -> 8708bd172


Simple-minded debug trace for Lua

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

Branch: refs/heads/master
Commit: 8708bd1723d9d70fd9d43ccfe1acf7d33df6ca9d
Parents: 62fbfb5
Author: Sebb <sebb@apache.org>
Authored: Wed Nov 16 19:53:46 2016 +0000
Committer: Sebb <sebb@apache.org>
Committed: Wed Nov 16 19:53:46 2016 +0000

----------------------------------------------------------------------
 site/api/lib/trace.lua | 69 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/8708bd17/site/api/lib/trace.lua
----------------------------------------------------------------------
diff --git a/site/api/lib/trace.lua b/site/api/lib/trace.lua
new file mode 100644
index 0000000..3f3cdf6
--- /dev/null
+++ b/site/api/lib/trace.lua
@@ -0,0 +1,69 @@
+--[[
+ 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.
+Output is to stderr as that should appear in the server logs
+
+N.B. This is intended as a handy tool for local use only;
+not intended for use in deployed code.
+
+Usage:
+
+import 'lib/trace'
+
+...
+
+whereami()
+
+...
+
+trace("Status: " .. status)
+
+]]--
+
+-- show calling location details
+function _whereami(depth)
+    depth = depth or 0
+    local data = debug.getinfo(2+depth,"Snl")
+    return data.short_src:gsub('^.+/','') .. "#" .. (data.name or '') .. "@" .. data.currentline
.. ": "
+end
+
+function trace(s, depth)
+     depth = depth or 0
+    -- Use a leading marker to make it easier to find in the logs
+     io.stderr:write("@(#) " .. _whereami(1+depth) .. tostring(s) .. "\n")
+end
+
+--[[
+debug.getinfo output
+{ "S"
+  lastlinedefined = 0,
+  linedefined = 0,
+  short_src = "../test/stack.lua",
+  source = "@../test/stack.lua",
+  what = "main"
+}
+{ "n"
+  name = "one",
+  namewhat = "global"
+}
+{ "l"
+  currentline = 12
+}
+]]--


Mime
View raw message