--[[----------------------------------------------------------------------------

WFSearchDebugLogging.lua

--------------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2015 Adobe Systems Incorporated
All Rights Reserved.

NOTICE: All information contained herein is, and remains the property of
Adobe Systems Incorporated and its suppliers, if any. The intellectual and
technical concepts contained herein are proprietary to Adobe Systems
Incorporated and its suppliers and are protected by all applicable
intellectual property laws, including trade secret and copyright laws.
Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe Systems Incorporated.

----------------------------------------------------------------------------]]--
local WFSearchDebugLogging = {}


-- using a common method , so that if needed it can be switched off 
function WFSearchDebugLogging.getFormattedTimeForSearchDebug( context )
	return os.date("%H.%M.%S")
end
--------------------------------------------------------------------------------
-- using a common method , so that if needed it can be switched off 
function WFSearchDebugLogging.getCurrentTimeForDebug( context )
	return os.time()
end

--------------------------------------------------------------------------------
local search_debugPrintNeeded = false
function WFSearchDebugLogging.search_debugPrint( context, logger, messageType, ... )
	if search_debugPrintNeeded then
		debug.print( ... )
	else
		if messageType == "d" then
			logger:debug( ... )
		elseif messageType == "i" then
			logger:info( ... )
		elseif messageType == "w" then
			logger:warn( ... )
		elseif messageType == "t" then
			logger:trace( ... )
		elseif messageType == "e" then
			logger:error( ... )
		end
	end
end

--------------------------------------------------------------------------------
function WFSearchDebugLogging.search_debugPrintTimeConsumed( context, logger,
												operationIndetifier, sessionIdentifier , 
												expectedMaxTime , startTime, endTime, 
												additionalData )
	local consumedTime = endTime - startTime
	if expectedMaxTime then
		if consumedTime > expectedMaxTime then 
			WFSearchDebugLogging.search_debugPrint( context, logger, "w", 
								string.format("WARNING !!! %s: %s took %sS which is more than allowed %s : %s", 
								operationIndetifier, sessionIdentifier,
								consumedTime, expectedMaxTime, additionalData) )
		end
	end
	
	WFSearchDebugLogging.search_debugPrint( context, logger, "i",
								operationIndetifier, sessionIdentifier, 
								": Time Consumed is [", consumedTime, "Sec ]", 
								additionalData )
	
	endTime = 0
	startTime = 0
end


--==============================================================================

return WFSearchDebugLogging
--==============================================================================