Explain ULX logging please..

Hello community, I seen everytime functions like ulx.fancylogadmin and such, and i looked into the ULX sources, and seen the log.lua file, but I dont fully understand the logging functions,
I’ll post them here so you dont have to search them out:



function ulx.fancyLogAdmin( calling_ply, format, ... )
	local use_self_suffix = false
	local hide_echo = false
	local players = {}
	if logEcho:GetInt() ~= 0 then
		players = player.GetAll()
	end
	local arg_pos = 1
	local args = { ... }
	if type( format ) == "boolean" then
		hide_echo = format
		format = args[ 1 ]
	 	arg_pos = arg_pos + 1
	end

	if type( format ) == "table" then
		players = format
		format = args[ 1 ]
		arg_pos = arg_pos + 1
	end

	if hide_echo then
		for i=#players, 1, -1 do
			if not ULib.ucl.query( players[ i ], hiddenechoAccess ) and players[ i ] ~= calling_ply then
				table.remove( players, i )
			end
		end
	end
	table.insert( players, "CONSOLE" ) -- Dummy player used for logging and printing to dedicated console window

	local playerStrs = {}
	for i=1, #players do
		playerStrs[ i ] = {}
	end

	if hide_echo then
		insertToAll( playerStrs, default_color )
		insertToAll( playerStrs, "(SILENT) " )
	end

	local no_targets = false
	format:gsub( "([^#]*)#([%.%d]*[%a])([^#]*)", function( prefix, tag, postfix )
		if prefix and prefix ~= "" then
			insertToAll( playerStrs, default_color )
			insertToAll( playerStrs, prefix )
		end

		local specifier = tag:sub( -1, -1 )
		local arg = args[ arg_pos ]
		arg_pos = arg_pos + 1
		local color, str
		if specifier == "T" or specifier == "P" or (specifier == "A" and calling_ply) then
			if specifier == "A" then
				arg_pos = arg_pos - 1 -- This doesn't have an arg since it's at the start
				arg = { calling_ply }
			elseif type( arg ) ~= "table" then
				arg = { arg }
			end

			if #arg == 0 then no_targets = true end -- NO PLAYERS, NO LOG!!

			for i=1, #players do
				table.Add( playerStrs[ i ], makePlayerList( calling_ply, arg, players[ i ], use_self_suffix, specifier == "A" ) )
			end
			use_self_suffix = true
		else
			insertToAll( playerStrs, misc_color )
			insertToAll( playerStrs, string.format( "%" .. tag, arg ) )
		end

		if postfix and postfix ~= "" then
			insertToAll( playerStrs, default_color )
			insertToAll( playerStrs, postfix )
		end
	end )

	if no_targets then -- We don't want to log if there's nothing being targetted
		return
	end

	for i=1, #players do
		if not logEchoColors:GetBool() or players[ i ] == "CONSOLE" then -- They don't want coloring :)
			for j=#playerStrs[ i ], 1, -1 do
				if type( playerStrs[ i ][ j ] ) == "table" then
					table.remove( playerStrs[ i ], j )
				end
			end
		end

		if players[ i ] ~= "CONSOLE" then
			ULib.tsayColor( players[ i ], true, unpack( playerStrs[ i ] ) )
		else
			local msg = table.concat( playerStrs[ i ] )
			if game.IsDedicated() then
				Msg( msg .. "
" )
			end

			if logFile:GetBool() then
				ulx.logString( msg, true )
			end
		end
	end
end

function ulx.fancyLog( format, ... )
	ulx.fancyLogAdmin( _, format, ... )
end

function ulx.logUserAct( ply, target, action, hide_echo )
	local nick
	if ply:IsValid() then
		if not ply:IsConnected() or not target:IsConnected() then return end
		nick = ply:Nick()
	else
		nick = "(Console)"
	end

	action = action:gsub( "#T", target:Nick(), 1 ) -- Everything needs this replacement
	local level = logEcho:GetInt()

	if not hide_echo and level > 0 then
		local echo
		if level == 1 then
			echo = action:gsub( "#A", nick, 1 )
			ULib.tsay( _, echo, true )
		end
	elseif level > 0 then
		local echo = action:gsub( "#A", "(SILENT)" .. nick, 1 )
		ULib.tsay( ply, echo, true ) -- Whether or not the originating player has access, they're getting the echo.

		local players = player.GetAll()
		for _, player in ipairs( players ) do
			if ULib.ucl.query( player, hiddenechoAccess ) and player ~= ply then
				ULib.tsay( player, echo, true )
			end
		end
	end

	if game.IsDedicated() then
		Msg( action:gsub( "#A", nick, 1 ) .. "
" )
	end

	if logFile:GetBool() then
		ulx.logString( action:gsub( "#A", nick, 1 ), true )
	end
end

function ulx.logServAct( ply, action, hide_echo )
	local nick
	if ply:IsValid() then
		if not ply:IsConnected() then return end
		nick = ply:Nick()
	else
		nick = "(Console)"
	end

	local level = logEcho:GetInt()

	if not hide_echo and level > 0 then
		local echo
		if level == 1 then
			echo = action:gsub( "#A", nick, 1 )
			ULib.tsay( _, echo, true )
		end
	elseif level > 0 then
		local echo = action:gsub( "#A", "(SILENT)" .. nick, 1 )
		ULib.tsay( ply, echo, true ) -- Whether or not the originating player has access, they're getting the echo.

		local players = player.GetAll()
		for _, player in ipairs( players ) do
			if ULib.ucl.query( player, hiddenechoAccess ) and player ~= ply then
				ULib.tsay( player, echo, true )
			end
		end
	end

	if game.IsDedicated() then
		Msg( action:gsub( "#A", nick, 1 ) .. "
" )
	end

	if logFile:GetBool() then
		ulx.logString( action:gsub( "#A", nick, 1 ), true )
	end
end


I didnt found these functions in the ULX Docs. Hope you can help me out!



ulx.fancyLogAdmin( calling_ply, "#A did something to #T", target_ply )


This will both log to the log files and write to chat (color-coded if you have that option set) the Nick value of the calling_ply object (in place of #A), the stuff in between, and the Nick value of target_ply in place of #T.



ulx.fancyLog( "Something happened to #T", target_ply )


This does the same as fancyLogAdmin, but doesn’t take a calling_ply- or calling admin- parameter.



ulx.logServAct( caling_ply, "#A did something" )


This does the same as fancyLog, but instead doesn’t have a target_ply parameter.

All three of these will accept a boolean value- hide_echo- which will only echo the log message to the groups with proper permission to see it. If this boolean is not set, it will default to allowing all users to see the log message.

Could you explain the tags like #A and #T? I’ve seen more tags in the code, though. wouldnt it work without #A to show the admin?

#A = admin
#T = target

Read my full post please, i asked what the other tags mean.

What other tags? There are only #A and #T.