From e8df6da5489848dc037b2512ae3ecf61ba7d26f2 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Wed, 26 Apr 2023 21:23:25 +0100 Subject: [PATCH] [MIRROR] Fixes silo logging + add log file based logging to silo [MDB IGNORE] (#20748) * Fixes silo logging + add log file based logging to silo * Update logging.dm * Update logging.dm --------- Co-authored-by: Gamer025 <33846895+Gamer025@users.noreply.github.com> Co-authored-by: Gandalf <9026500+Gandalf2k15@users.noreply.github.com> --- code/__DEFINES/logging.dm | 1 + .../logging/categories/log_category_silo.dm | 2 + code/modules/mining/machine_redemption.dm | 2 +- code/modules/mining/machine_silo.dm | 45 ++++++++++++++----- .../mob/living/silicon/robot/robot_model.dm | 2 +- .../modules/research/machinery/_production.dm | 2 +- 6 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 code/modules/logging/categories/log_category_silo.dm diff --git a/code/__DEFINES/logging.dm b/code/__DEFINES/logging.dm index 9e0da264669..d086fa2ae62 100644 --- a/code/__DEFINES/logging.dm +++ b/code/__DEFINES/logging.dm @@ -72,6 +72,7 @@ // Log categories #define LOG_CATEGORY_NOT_FOUND "invalid_category" #define LOG_CATEGORY_TARGET_ZONE_SWITCH "target_zone_switch" +#define LOG_CATEGORY_SILO "silo" //wrapper macros for easier grepping #define DIRECT_OUTPUT(A, B) A << B diff --git a/code/modules/logging/categories/log_category_silo.dm b/code/modules/logging/categories/log_category_silo.dm new file mode 100644 index 00000000000..c3fd1faf8b8 --- /dev/null +++ b/code/modules/logging/categories/log_category_silo.dm @@ -0,0 +1,2 @@ +/datum/log_category/silo + category = LOG_CATEGORY_SILO diff --git a/code/modules/mining/machine_redemption.dm b/code/modules/mining/machine_redemption.dm index f37092fcfc8..a7a03a6d662 100644 --- a/code/modules/mining/machine_redemption.dm +++ b/code/modules/mining/machine_redemption.dm @@ -74,7 +74,7 @@ var/mats = stack_mats & mat_container.materials var/amount = gathered_ore.amount mat_container.insert_item(gathered_ore, ore_multiplier, breakdown_flags=BREAKDOWN_FLAGS_ORM) //insert it - materials.silo_log(src, "smelted", amount, "someone", mats) + materials.silo_log(src, "smelted", amount, gathered_ore.name, mats) qdel(gathered_ore) SEND_SIGNAL(src, COMSIG_ORM_COLLECTED_ORE) diff --git a/code/modules/mining/machine_silo.dm b/code/modules/mining/machine_silo.dm index 0cca6f51865..700e798eabf 100644 --- a/code/modules/mining/machine_silo.dm +++ b/code/modules/mining/machine_silo.dm @@ -66,7 +66,8 @@ GLOBAL_LIST_EMPTY(silo_access_logs) // assumes unlimited space... var/amount = I.amount materials.user_insert(I, user, breakdown_flags) - silo_log(M, "deposited", amount, "sheets", item_mats) + var/list/matlist = I.get_material_composition(breakdown_flags) + silo_log(M, "deposited", amount, I.name, matlist) return TRUE /obj/machinery/ore_silo/attackby(obj/item/W, mob/user, params) @@ -173,7 +174,7 @@ GLOBAL_LIST_EMPTY(silo_access_logs) var/datum/component/material_container/materials = GetComponent(/datum/component/material_container) var/count = materials.retrieve_sheets(text2num(href_list["eject_amt"]), eject_sheet, drop_location()) var/list/matlist = list() - matlist[eject_sheet] = MINERAL_MATERIAL_AMOUNT + matlist[eject_sheet] = MINERAL_MATERIAL_AMOUNT * count silo_log(src, "ejected", -count, "sheets", matlist) return TRUE else if(href_list["page"]) @@ -188,11 +189,20 @@ GLOBAL_LIST_EMPTY(silo_access_logs) I.buffer = src return TRUE +/** + * Creates a log entry for depositing/withdrawing from the silo both ingame and in text based log + * + * Arguments: + * - [M][/obj/machinery]: The machine performing the action. + * - action: Text that visually describes the action (smelted/deposited/resupplied...) + * - amount: The amount of sheets/objects deposited/withdrawn by this action. Positive for depositing, negative for withdrawing. + * - noun: Name of the object the action was performed with (sheet, units, ore...) + * - [mats][list]: Assoc list in format (material datum = amount of raw materials). Wants the actual amount of raw (iron, glass...) materials involved in this action. If you have 10 metal sheets each worth 2000 iron you would pass a list with the iron material datum = 20000 + */ /obj/machinery/ore_silo/proc/silo_log(obj/machinery/M, action, amount, noun, list/mats) if (!length(mats)) return var/datum/ore_silo_log/entry = new(M, action, amount, noun, mats) - var/list/datum/ore_silo_log/logs = GLOB.silo_access_logs[REF(src)] if(!LAZYLEN(logs)) GLOB.silo_access_logs[REF(src)] = logs = list(entry) @@ -226,9 +236,21 @@ GLOBAL_LIST_EMPTY(silo_access_logs) amount = _amount noun = _noun materials = mats.Copy() - for(var/each in materials) - materials[each] *= abs(_amount) format() + var/list/data = list( + "machine_name" = machine_name, + "area_name" = AREACOORD(M), + "action" = action, + "amount" = abs(amount), + "noun" = noun, + "raw_materials" = get_raw_materials(""), + "direction" = amount < 0 ? "withdrawn" : "deposited", + ) + GLOB.logger.Log( + LOG_CATEGORY_SILO, + "[machine_name] in \[[AREACOORD(M)]\] [action] [abs(amount)]x [noun] | [get_raw_materials("")]", + data, + ) /datum/ore_silo_log/proc/merge(datum/ore_silo_log/other) if (other == src || action != other.action || noun != other.noun) @@ -245,13 +267,14 @@ GLOBAL_LIST_EMPTY(silo_access_logs) /datum/ore_silo_log/proc/format() name = "[machine_name]: [action] [amount]x [noun]" + formatted = "([timestamp]) [machine_name] in [area_name]
[action] [abs(amount)]x [noun]
[get_raw_materials("")]" - var/list/msg = list("([timestamp]) [machine_name] in [area_name]
[action] [abs(amount)]x [noun]
") - var/sep = "" +/datum/ore_silo_log/proc/get_raw_materials(separator) + var/list/msg = list() for(var/key in materials) var/datum/material/M = key - var/val = round(materials[key]) / MINERAL_MATERIAL_AMOUNT - msg += sep - sep = ", " + var/val = round(materials[key]) + msg += separator + separator = ", " msg += "[amount < 0 ? "-" : "+"][val] [M.name]" - formatted = msg.Join() + return msg.Join() diff --git a/code/modules/mob/living/silicon/robot/robot_model.dm b/code/modules/mob/living/silicon/robot/robot_model.dm index b64934bdc6f..900dcec1a0c 100644 --- a/code/modules/mob/living/silicon/robot/robot_model.dm +++ b/code/modules/mob/living/silicon/robot/robot_model.dm @@ -191,7 +191,7 @@ storage_datum.energy += mat_container.use_amount_mat(to_stock, storage_datum.mat_type) charger.balloon_alert(robot, "+ [to_stock]u [initial(storage_datum.mat_type.name)]") - charger.materials.silo_log(charger, "resupplied", -to_stock, "units", list(storage_datum.mat_type)) + charger.materials.silo_log(charger, "resupplied", -1, "units", list(GET_MATERIAL_REF(storage_datum.mat_type) = to_stock)) playsound(charger, 'sound/weapons/gun/general/mag_bullet_insert.ogg', 50, vary = FALSE) return charger.balloon_alert(robot, "restock process complete") diff --git a/code/modules/research/machinery/_production.dm b/code/modules/research/machinery/_production.dm index c39261512c5..d0ac21f7f91 100644 --- a/code/modules/research/machinery/_production.dm +++ b/code/modules/research/machinery/_production.dm @@ -349,7 +349,7 @@ var/count = mat_container.retrieve_sheets(text2num(eject_amt), eject_sheet, drop_location()) var/list/matlist = list() - matlist[eject_sheet] = MINERAL_MATERIAL_AMOUNT + matlist[eject_sheet] = MINERAL_MATERIAL_AMOUNT * count materials.silo_log(src, "ejected", -count, "sheets", matlist)