Files
Bubberstation/code/modules/logging/log_holder.dm
Jordan Dominion 3ceee2aab4 World Initialization Refactor (#74808)
- Removes unnecessary real global vars.
- Adds comments pointing to the init order defined in
/code/game/world.dm.
- Prevent people using `GLOBAL_REAL_VAR` and `GLOBAL_REAL` to circumvent
init order.
- Properly type `PROFILE_STORE` real global.
- Refactored `make_datum_references_lists()` and moved the call to it
into `GLOB` init with duct tape.
- Renamed `GLOB.admin_log` to `GLOB.admin_activities` as it wasn't
actually a log file.
- Whitelist loading happens in config.
- Renamed `SSdbcore`'s `SetRoundID()` to `InitializeRound()`. Now
handles calling `CheckSchemaVersion()`.
- Created macro for setting up log `GLOB`s.
- Removed log line for `GLOB` count.
- Moved call to `make_datum_reference_lists()` to
`/datum/controller/global_vars/Initialize()`. I slimmed it down where
possible too.
- Updated comments about world init order.
- Move `load_admins()` call to after log setup.
- Removes unused function `gib_stack_trace()`.
- Removes a bunch of unused log `GLOB`s.
- Unlocks the secrets of the universe by finally making the first
executed line of code deterministic.

No functional changes. Closes #74792
Testmerge thoroughly.

---------

Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
2023-04-24 18:38:38 -06:00

77 lines
2.6 KiB
Plaintext

GLOBAL_DATUM_INIT(logger, /datum/log_holder, new)
GLOBAL_PROTECT(logger)
/**
* Main datum to manage logging actions
*/
/datum/log_holder
/// Round ID, if set, that logging is initialized for
var/round_id
/// When the log_holder first initialized
var/logging_start_timestamp
/// Associative: category -> datum
var/list/datum/log_category/log_categories
/// typecache list for categories that exist but are disabled
var/list/disabled_categories
var/initialized = FALSE
var/shutdown = FALSE
/// Assembles basic information for logging, creating the log category datums and checking for config flags as required
/datum/log_holder/proc/init_logging()
if(initialized)
CRASH("Attempted to call init_logging twice!")
initialized = TRUE
round_id = GLOB.round_id
logging_start_timestamp = rustg_unix_timestamp()
log_categories = list()
disabled_categories = list()
for(var/datum/log_category/category_type as anything in subtypesof(/datum/log_category))
var/category = initial(category_type.category)
if(!category)
continue
if(category in log_categories)
stack_trace("Found two identical log category type definitions! [category_type]")
continue
var/config_flag = initial(category_type.config_flag)
if(config_flag && !config.Get(config_flag))
disabled_categories[category] = TRUE
continue
category_type = log_categories[category] = new category_type
var/list/log_start_entry = list(
LOG_HEADER_CATEGORY = category,
LOG_HEADER_INIT_TIMESTAMP = big_number_to_text(logging_start_timestamp),
LOG_HEADER_ROUND_ID = big_number_to_text(GLOB.round_id),
)
rustg_file_write("[json_encode(log_start_entry)]\n", category_type.get_output_file(null))
if(fexists(GLOB.config_error_log))
fcopy(GLOB.config_error_log, "[GLOB.log_directory]/config_error.log")
fdel(GLOB.config_error_log)
world._initialize_log_files()
/// Tells the log_holder to not allow any more logging to be done, and dumps all categories to their json file
/datum/log_holder/proc/shutdown_logging()
if(shutdown)
CRASH("Attempted to call shutdown_logging twice!")
shutdown = TRUE
/// This is Log because log is a byond internal proc
/datum/log_holder/proc/Log(category, message, list/data)
if(!initialized || shutdown)
CRASH("Attempted to perform logging before initializion or after shutdown!")
if(disabled_categories[category])
return
var/datum/log_category/log_category = log_categories[category]
if(!log_category)
Log(LOG_CATEGORY_NOT_FOUND, message, data)
CRASH("Attempted to log to a category that doesn't exist! [category]")
log_category.add_entry(message, data)