Index: nse_main.lua
===================================================================
--- nse_main.lua	(revision 29856)
+++ nse_main.lua	(working copy)
@@ -401,7 +401,7 @@
         co = co,
         env = env,
         identifier = tostring(co),
-        info = format("'%s' (%s)", self.short_basename, tostring(co));
+        info = format("'%s' (%s)", self.id, tostring(co));
         type = script_type,
         close_handlers = {},
       };
@@ -837,7 +837,7 @@
       port = current.port,
       type = current.type,
       parent = current.parent,
-      info = format("'%s' worker (%s)", current.short_basename, tostring(co));
+      info = format("'%s' (worker %s)", current.id, tostring(co));
       close_handlers = {},
       -- d = function(...) end, -- output no debug information
     };
@@ -857,6 +857,12 @@
   rawset(stdnse, "base", function ()
     return current and current.co;
   end);
+  rawset(stdnse, "gettinfo", function ()
+    return current and current.info;
+  end);
+  rawset(stdnse, "getid", function ()
+    return current and current.id;
+  end);
 
   while threads_iter and num_threads < CONCURRENCY_LIMIT do
     local thread = threads_iter()
@@ -1291,6 +1297,8 @@
   -- These functions do not exist until we are executing action functions.
   rawset(stdnse, "new_thread", nil)
   rawset(stdnse, "base", nil)
+  rawset(stdnse, "gettinfo", nil)
+  rawset(stdnse, "getid", nil)
 
   for runlevel, scripts in ipairs(runlevels) do
     -- This iterator is passed to the run function. It returns one new script
Index: nselib/stdnse.lua
===================================================================
--- nselib/stdnse.lua	(revision 29856)
+++ nselib/stdnse.lua	(working copy)
@@ -58,45 +58,78 @@
 -- Prints a formatted debug message if the current debugging level is greater
 -- than or equal to a given level.
 -- 
--- This is a convenience wrapper around
--- <code>nmap.log_write</code>. The first optional numeric
--- argument, <code>level</code>, is used as the debugging level necessary
--- to print the message (it defaults to 1 if omitted). All remaining arguments
--- are processed with Lua's <code>string.format</code> function.
+-- This is a convenience wrapper around <code>nmap.log_write</code>. The first
+-- optional numeric argument, <code>level</code>, is used as the debugging level
+-- necessary to print the message (it defaults to 1 if omitted). All remaining
+-- arguments are processed with Lua's <code>string.format</code> function.
+--
+-- If known, the output includes some context based information: the script
+-- identifier and the base thread identifier.
+--
 -- @param level Optional debugging level.
 -- @param fmt Format string.
 -- @param ... Arguments to format.
-print_debug = function(level, fmt, ...)
-  local l, d = tonumber(level), nmap.debugging();
-  if l and l <= d then
-    nmap.log_write("stdout", format(fmt, ...));
-  elseif not l and 1 <= d then
-    nmap.log_write("stdout", format(level, fmt, ...));
+function debug (level, fmt, ...)
+  local current = nmap.debugging()
+  if type(level) == "number" then
+    if level <= current then
+      local info = gettinfo()
+      if info then
+        nmap.log_write("stdout", "["..info.."] "..format(fmt, ...))
+      else
+        nmap.log_write("stdout", format(fmt, ...))
+      end
+    end
+  elseif 1 <= current then
+    -- level is fmt and fmt is first argument
+    local info = gettinfo()
+    if info then
+      nmap.log_write("stdout", "["..info.."] "..format(level, fmt, ...))
+    else
+      nmap.log_write("stdout", format(level, fmt, ...))
+    end
   end
 end
+_ENV.print_debug = debug -- alias for older name
 
 ---
 -- Prints a formatted verbosity message if the current verbosity level is greater
 -- than or equal to a given level.
 -- 
--- This is a convenience wrapper around
--- <code>nmap.log_write</code>. The first optional numeric
--- argument, <code>level</code>, is used as the verbosity level necessary
--- to print the message (it defaults to 1 if omitted). All remaining arguments
--- are processed with Lua's <code>string.format</code> function.
+-- This is a convenience wrapper around <code>nmap.log_write</code>. The first
+-- optional numeric argument, <code>level</code>, is used as the verbosity level
+-- necessary to print the message (it defaults to 1 if omitted). All remaining
+-- arguments are processed with Lua's <code>string.format</code> function.
+--
+-- If known, the output includes some context based information: the script
+-- identifier.
+--
 -- @param level Optional verbosity level.
 -- @param fmt Format string.
 -- @param ... Arguments to format.
-print_verbose = function(level, fmt, ...)
-  local l, d = tonumber(level), nmap.verbosity();
-  if l and l <= d then
-    nmap.log_write("stdout", format(fmt, ...));
-  elseif not l and 1 <= d then
-    nmap.log_write("stdout", format(level, fmt, ...));
+function verbose (level, fmt, ...)
+  local current = nmap.verbosity()
+  if type(level) == "number" then
+    if level <= current then
+      local id = getid()
+      if id then
+        nmap.log_write("stdout", "["..id.."] "..format(fmt, ...))
+      else
+        nmap.log_write("stdout", format(fmt, ...))
+      end
+    end
+  elseif 1 <= current then
+    -- level is fmt and fmt is first argument
+    local id = getid()
+    if id then
+      nmap.log_write("stdout", "["..id.."] "..format(level, fmt, ...))
+    else
+      nmap.log_write("stdout", format(level, fmt, ...))
+    end
   end
 end
+_ENV.print_verbose = verbose -- alias for older name
 
-
 --- Join a list of strings with a separator string.
 -- 
 -- This is Lua's <code>table.concat</code> function with the parameters
