From e57bcf3b6c63240345c25d8efbe9f0e59f7bcd35 Mon Sep 17 00:00:00 2001 From: dwasint <82520990+dwasint@users.noreply.github.com> Date: Mon, 10 Jun 2024 19:18:11 -0400 Subject: [PATCH] user logging done --- code/__DEFINES/logging.dm | 1 + code/__HELPERS/logging/_logging.dm | 37 ++++++++++++++++++- code/__HELPERS/logging/attack.dm | 7 ++-- code/__HELPERS/logging/mob.dm | 2 +- .../~monkestation-helpers/logging/attack.dm | 14 ++++++- .../mob/living/carbon/human/_species.dm | 2 +- .../mecha/equipment/mecha_equipment.dm | 2 +- .../metrics/loki_integration/subsystem.dm | 15 ++++---- 8 files changed, 64 insertions(+), 16 deletions(-) diff --git a/code/__DEFINES/logging.dm b/code/__DEFINES/logging.dm index 172f2cdf46823e..597827e2747cb0 100644 --- a/code/__DEFINES/logging.dm +++ b/code/__DEFINES/logging.dm @@ -119,6 +119,7 @@ #define LOG_CATEGORY_ARTIFACT "artifact" #define LOG_CATEGORY_BLACKMARKET "blackmarket" #define LOG_CATEGORY_ANTAG_REP "antag-rep" +#define LOG_CATEGORY_BOMBING "bombing" // Admin categories #define LOG_CATEGORY_ADMIN "admin" diff --git a/code/__HELPERS/logging/_logging.dm b/code/__HELPERS/logging/_logging.dm index 8297168e6e217b..189d7bddb79e17 100644 --- a/code/__HELPERS/logging/_logging.dm +++ b/code/__HELPERS/logging/_logging.dm @@ -83,6 +83,32 @@ GLOBAL_LIST_INIT(testing_global_profiler, list("_PROFILE_NAME" = "Global")) #define log_reftracker(msg) #endif +/atom/proc/return_category(type) + switch(type) + if(LOG_ATTACK, LOG_VICTIM) + return LOG_CATEGORY_ATTACK + if(LOG_SAY, LOG_WHISPER, LOG_DSAY, LOG_CHAT, LOG_PDA) + return LOG_CATEGORY_GAME_SAY + if(LOG_EMOTE) + return LOG_CATEGORY_GAME_EMOTE + if(LOG_OOC) + return LOG_CATEGORY_GAME_OOC + if(LOG_ADMIN, LOG_ASAY, LOG_ADMIN_PRIVATE) + return LOG_CATEGORY_ADMIN + if(LOG_VIRUS) + return LOG_CATEGORY_VIRUS + if(LOG_GAME) + return LOG_CATEGORY_GAME + if(LOG_MECHA) + return LOG_CATEGORY_MECHA + if(LOG_MECHCOMP) + return LOG_CATEGORY_MECHCOMP + if(LOG_CLONING) + return LOG_CATEGORY_CLONING + if(LOG_ECON) + return LOG_CATEGORY_ECONOMY + else + return LOG_CATEGORY_GAME /** * Generic logging helper * @@ -95,11 +121,20 @@ GLOBAL_LIST_INIT(testing_global_profiler, list("_PROFILE_NAME" = "Global")) * * color - color of the log text * * log_globally - boolean checking whether or not we write this log to the log file */ -/atom/proc/log_message(message, message_type, color = null, log_globally = TRUE) +/atom/proc/log_message(message, message_type, color = null, log_globally = TRUE, loki = TRUE, severity = "info", category) if(!log_globally) return + if(!category) + category = return_category(message_type) + var/log_text = "[key_name(src)] [message] [loc_name(src)]" + + if(isliving(src) && loki) + var/mob/living/source = src + if(source.client) + SSloki.send_user_log(category, log_text, severity, source.key, null) + switch(message_type) /// ship both attack logs and victim logs to the end of round attack.log just to ensure we don't lose information if(LOG_ATTACK, LOG_VICTIM) diff --git a/code/__HELPERS/logging/attack.dm b/code/__HELPERS/logging/attack.dm index 91c67598465a63..f61f6f827d4999 100644 --- a/code/__HELPERS/logging/attack.dm +++ b/code/__HELPERS/logging/attack.dm @@ -12,7 +12,7 @@ * * atom/object - is a tool with which the action was made (usually an item) * * addition - is any additional text, which will be appended to the rest of the log line */ -/proc/log_combat(atom/user, atom/target, what_done, atom/object=null, addition=null) +/proc/log_combat(atom/user, atom/target, what_done, atom/object=null, addition=null, severity = "error") var/ssource = key_name(user) var/starget = key_name(target) @@ -30,15 +30,14 @@ var/postfix = "[sobject][saddition][hp]" var/message = "[what_done] [starget][postfix]" - user.log_message(message, LOG_ATTACK, color="red") + user.log_message(message, LOG_ATTACK, color="red", loki = FALSE) if(isliving(user)) var/source_key = living_user.key var/target_key = null if(isliving(target)) target_key = living_target.key - if(source_key && living_user?.client.test_marked) - SSloki.send_user_log(LOG_CATEGORY_ATTACK, message, "warning", source_key, target_key) + SSloki.send_user_log(LOG_CATEGORY_ATTACK, message, severity, source_key, target_key) if(user != target) var/reverse_message = "was [what_done] by [ssource][postfix]" diff --git a/code/__HELPERS/logging/mob.dm b/code/__HELPERS/logging/mob.dm index d80ba2b82dc607..a225d6a5225823 100644 --- a/code/__HELPERS/logging/mob.dm +++ b/code/__HELPERS/logging/mob.dm @@ -11,7 +11,7 @@ /// Logs a message in a mob's individual log, and in the global logs as well if log_globally is true -/mob/log_message(message, message_type, color = null, log_globally = TRUE) +/mob/log_message(message, message_type, color = null, log_globally = TRUE, loki = TRUE, severity = "info", category) if(!LAZYLEN(message)) stack_trace("Empty message") return diff --git a/code/__HELPERS/~monkestation-helpers/logging/attack.dm b/code/__HELPERS/~monkestation-helpers/logging/attack.dm index 2ccb2fc612d42c..d2e302c8f3b731 100644 --- a/code/__HELPERS/~monkestation-helpers/logging/attack.dm +++ b/code/__HELPERS/~monkestation-helpers/logging/attack.dm @@ -12,7 +12,19 @@ if(user) if(HAS_TRAIT(user, TRAIT_PACIFISM)) bomb_message = "(while pacifist) [bomb_message]" - user.log_message(bomb_message, LOG_ATTACK) //let it go to individual logs as well as the game log + user.log_message(bomb_message, LOG_ATTACK, loki = FALSE) //let it go to individual logs as well as the game log + var/user_key + var/target_key + + if(isliving(target)) + var/mob/living/target_living = target + target_key = target_living.key + + if(isliving(user)) + var/mob/living/living_user = user + user_key = living_user.key + + SSloki.send_user_log(LOG_CATEGORY_BOMBING, bomb_message, "critical", user_key, target_key) bomb_message = "[key_name(user)] at [AREACOORD(user)] [bomb_message]." else log_attack(bomb_message) diff --git a/code/modules/mob/living/carbon/human/_species.dm b/code/modules/mob/living/carbon/human/_species.dm index fa67853e091fe3..24a32f6fbd7d88 100644 --- a/code/modules/mob/living/carbon/human/_species.dm +++ b/code/modules/mob/living/carbon/human/_species.dm @@ -1316,7 +1316,7 @@ GLOBAL_LIST_EMPTY(features_by_species) target.visible_message(span_danger("[user]'s [atk_verb] misses [target]!"), \ span_danger("You avoid [user]'s [atk_verb]!"), span_hear("You hear a swoosh!"), COMBAT_MESSAGE_RANGE, user) to_chat(user, span_warning("Your [atk_verb] misses [target]!")) - log_combat(user, target, "attempted to punch") + log_combat(user, target, "attempted to punch", severity = "warning") return FALSE var/armor_block = target.run_armor_check(affecting, MELEE) diff --git a/code/modules/vehicles/mecha/equipment/mecha_equipment.dm b/code/modules/vehicles/mecha/equipment/mecha_equipment.dm index 4c766d669d44af..eeb2eeafd919fa 100644 --- a/code/modules/vehicles/mecha/equipment/mecha_equipment.dm +++ b/code/modules/vehicles/mecha/equipment/mecha_equipment.dm @@ -205,7 +205,7 @@ log_message("[src] removed from equipment.", LOG_MECHA) chassis = null -/obj/item/mecha_parts/mecha_equipment/log_message(message, message_type=LOG_GAME, color=null, log_globally) +/obj/item/mecha_parts/mecha_equipment/log_message(message, message_type=LOG_GAME, color=null, log_globally, loki = TRUE, severity = "info", category) if(chassis) return chassis.log_message("ATTACHMENT: [src] [message]", message_type, color) return ..() diff --git a/monkestation/code/modules/metrics/loki_integration/subsystem.dm b/monkestation/code/modules/metrics/loki_integration/subsystem.dm index a57a6692755c73..d7f5c62a6277bf 100644 --- a/monkestation/code/modules/metrics/loki_integration/subsystem.dm +++ b/monkestation/code/modules/metrics/loki_integration/subsystem.dm @@ -5,13 +5,13 @@ https://grafana.com/docs/loki/latest/reference/loki-http-api/#post-lokiapiv1push */ /client - var/test_marked = TRUE + var/test_marked = FALSE /datum/config_entry/string/loki_url default = "" /datum/config_entry/flag/loki_enabled - default = TRUE + default = FALSE SUBSYSTEM_DEF(loki) name = "Loki Sender" @@ -25,25 +25,26 @@ SUBSYSTEM_DEF(loki) return SS_INIT_SUCCESS /datum/controller/subsystem/loki/proc/send_server_log(category, message, severity) - + var/time = rustg_unix_timestamp() + time = replacetext(time, ".", "") + time += "000" + var/built_json = "{\"streams\":\[{\"stream\":{\"level\":\"[severity]\",\"category\":\"[category]\", \"round\":\"[GLOB.round_id]\"},\"values\":\[\[\"[time]\", \"[message]\"\]\]}\]}" + push_data(built_json) /datum/controller/subsystem/loki/proc/send_user_log(category, message, severity, source, target) var/time = rustg_unix_timestamp() time = replacetext(time, ".", "") time += "000" - var/built_json = "{\"streams\":\[{\"stream\":{\"level\":\"[severity]\",\"target\":\"[target]\",\"source\":\"[source]\",\"category\":\"[category]\"},\"values\":\[\[\"[time]\", \"[message]\"\]\]}\]}" + var/built_json = "{\"streams\":\[{\"stream\":{\"level\":\"[severity]\",\"target\":\"[target]\",\"source\":\"[source]\",\"category\":\"[category]\", \"round\":\"[GLOB.round_id]\"},\"values\":\[\[\"[time]\", \"[message]\"\]\]}\]}" push_data(built_json) /datum/controller/subsystem/loki/proc/push_data(json) if(!json || !CONFIG_GET(flag/loki_enabled)) - message_admins("NOT ABLE TO SEND") return var/payload = json - message_admins(payload) var/list/headers = list() headers["Content-Type"] = "application/json" var/datum/http_request/request = new() //note about this, the loki_url also contains the api and userkey needed to actually send data if you are sending data outside of host box. request.prepare(RUSTG_HTTP_METHOD_POST, "[CONFIG_GET(string/loki_url)]/loki/api/v1/push", payload, headers, "tmp/response.json") request.begin_async() - message_admins("SENT LOG")