/* 
	Function: milsim_common_fnc_log

	Description:
		Used to log messages to the server RPT file.

	Parameters:
		0: NUMBER - log level.
		1: STRING - component name.
		2: STRING - message to log.
		3: ARRAY - key value pairs of data to log.
*/
#include "..\script_component.hpp"

params [
	["_logLevel", 1, [-1,0,1,2,3]], // script_mod.hpp
	["_component", "", [""]],
	["_message", "", [""]],
	["_data", [], [[]]]
];

if (_logLevel < DEBUG_MODE) exitWith {};

private _hash = createHashMapFromArray _data;

// Replace square brackets with round brackets to avoid parsing issues.
_message regexReplace ['(\[)', "("];
_message regexReplace ['(\])', ")"];

private _json = [_hash] call CBA_fnc_encodeJSON;
_log = format ["[%1] [%2] [%3] [%4] :: %5", QUOTE(PREFIX), _component, _fnc_scriptNameParent, _message, _json];

diag_log text _log;