Files
MissionTemplate/framework/common/functions/fn_log.sqf
2024-02-06 01:52:25 -08:00

33 lines
829 B
Plaintext

/*
Function: milsim_util_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 < LOG_LEVEL) 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;