@@ -428,17 +428,6 @@ EOS_ELogLevel eos_loglevel_str_to_enum(const std::string& str)
428428 }
429429}
430430
431- void eos_set_loglevel (const LogLevelConfig& log_config)
432- {
433- if (EOS_Logging_SetLogLevel_ptr != nullptr )
434- {
435- for (size_t i = 0 ; i < log_config.category .size () - 1 ; i++)
436- {
437- EOS_Logging_SetLogLevel_ptr ((EOS_ELogCategory)i, eos_loglevel_str_to_enum (log_config.level [i]));
438- }
439- }
440- }
441-
442431// -------------------------------------------------------------------------
443432static void show_log_as_dialog (const char * log_string)
444433{
@@ -966,7 +955,7 @@ static LogLevelConfig log_config_from_json_value(json_value_s* config_json)
966955
967956 while (iter != nullptr )
968957 {
969- if (!strcmp (" logCategoryLevelPairs " , iter->name ->string ))
958+ if (!strcmp (" LogCategoryLevelPairs " , iter->name ->string ))
970959 {
971960 json_array_s* pairs = json_value_as_array (iter->value );
972961 for (auto e = pairs->start ; e != nullptr ; e = e->next )
@@ -975,11 +964,11 @@ static LogLevelConfig log_config_from_json_value(json_value_s* config_json)
975964 struct json_object_element_s * pairs_iter = pairs_json_object->start ;
976965 while (pairs_iter != nullptr )
977966 {
978- if (!strcmp (" category " , pairs_iter->name ->string ))
967+ if (!strcmp (" Category " , pairs_iter->name ->string ))
979968 {
980969 log_config.category .push_back (json_value_as_string (pairs_iter->value )->string );
981970 }
982- else if (!strcmp (" level " , pairs_iter->name ->string ))
971+ else if (!strcmp (" Level " , pairs_iter->name ->string ))
983972 {
984973 log_config.level .push_back (json_value_as_string (pairs_iter->value )->string );
985974 }
@@ -1252,6 +1241,49 @@ static void eos_call_steam_init(const std::string& steam_dll_path)
12521241 }
12531242}
12541243
1244+ // -------------------------------------------------------------------------
1245+ void eos_set_loglevel_via_config ()
1246+ {
1247+ if (EOS_Logging_SetLogLevel_ptr == nullptr )
1248+ {
1249+ return ;
1250+ }
1251+
1252+ auto path_to_log_config_json = get_path_for_eos_service_config (EOS_LOGLEVEL_CONFIG_FILENAME);
1253+
1254+ if (!std::filesystem::exists (path_to_log_config_json))
1255+ {
1256+ log_inform (" Log level config not found, using default log levels" );
1257+ return ;
1258+ }
1259+
1260+ json_value_s* log_config_as_json = read_config_json_as_json_from_path (path_to_log_config_json);
1261+ LogLevelConfig log_config = log_config_from_json_value (log_config_as_json);
1262+ free (log_config_as_json);
1263+
1264+ // Validation to prevent out of range exception
1265+ if (log_config.category .size () != log_config.level .size ())
1266+ {
1267+ log_warn (" Log level config entries out of range" );
1268+ return ;
1269+ }
1270+
1271+ // Last in the vector is AllCategories, and will not be set
1272+ size_t individual_category_size = log_config.category .size () > 0 ? log_config.category .size () - 1 : 0 ;
1273+ if (individual_category_size == 0 )
1274+ {
1275+ log_warn (" Log level config entries empty" );
1276+ return ;
1277+ }
1278+
1279+ for (size_t i = 0 ; i < individual_category_size; i++)
1280+ {
1281+ EOS_Logging_SetLogLevel_ptr ((EOS_ELogCategory)i, eos_loglevel_str_to_enum (log_config.level [i]));
1282+ }
1283+
1284+ log_inform (" Log levels set according to config" );
1285+ }
1286+
12551287// -------------------------------------------------------------------------
12561288void eos_create (EOSConfig& eosConfig)
12571289{
@@ -1519,12 +1551,6 @@ DLL_EXPORT(void) UnityPluginLoad(void*)
15191551 EOSConfig eos_config = eos_config_from_json_value (eos_config_as_json);
15201552 free (eos_config_as_json);
15211553
1522- auto path_to_log_config_json = get_path_for_eos_service_config (EOS_LOGLEVEL_CONFIG_FILENAME);
1523- json_value_s* log_config_as_json = read_config_json_as_json_from_path (path_to_log_config_json);
1524- LogLevelConfig log_config = log_config_from_json_value (log_config_as_json);
1525- free (log_config_as_json);
1526- global_logf (" NativePlugin log sonfig size (%d)" , log_config.category .size ());
1527-
15281554#if PLATFORM_WINDOWS
15291555 // support sandbox and deployment id override via command line arguments
15301556 std::stringstream argStream = std::stringstream (GetCommandLineA ());
@@ -1626,7 +1652,7 @@ DLL_EXPORT(void) UnityPluginLoad(void*)
16261652
16271653 eos_init (eos_config);
16281654
1629- eos_set_loglevel (log_config );
1655+ eos_set_loglevel_via_config ( );
16301656 // log_warn("start eos create");
16311657 eos_create (eos_config);
16321658
0 commit comments