This mod is a fork of royvandongen Factorio-Event-Logger-Mod which does not appear to be getting updated.
It provides an event logging system for Factorio that generates formatted event logs based on events documented in the
Events API, enabling server administrators to track game events, and build tooling around it
-
Player Deaths
Logs the death of a player, identifying the cause (PvP, environmental, etc.). -
Player Join/Leave
Tracks when players join or leave the game and logs their leave reason (e.g., quit, kicked, desync). -
Chat Logging
Records all chat messages with the sender's name. -
Research Events
Logs the start, completion, and cancellation of research projects. -
Entity Placement Tracking
Tracks and logs the number of entities placed by each player. -
Rocket Launches
Logs whenever a rocket is launched. -
Evolution Factor Monitoring
Periodically logs the enemy evolution factor. -
Artillery Events
Tracks and logs artillery triggers. -
Playtime and Statistics
Periodically logs playtime and entity placement statistics for each player. -
Event API
Provides an API for other mods to log custom events.
- Search for "Events Logger" in the in-game Mod Portal.
- Click the "Install" button to add the mod to your game.
- Download or clone this repository.
- Place the mod folder into your Factorio
modsdirectory. - Start Factorio, and enable the mod in the Mod Manager.
This mod uses the following event hooks:
on_rocket_launchedon_research_startedon_research_finishedon_research_cancelledon_player_joined_gameon_player_left_gameon_pre_player_diedon_built_entityon_trigger_fired_artilleryon_console_chat
The statistics logging is performed every 10 minutes.
The mod provides a settings menu to enable or disable the following event logging formats:
Factorio Logs- Logs events to the standardfactorio-current.logfile output. Default is enabled.JSON Logs- Logs events to thescript-output/game-events.jsonfile in JSON format. Default is disabled.
All logs are captured in the standard log output.
Additionally, it is exported as JSON into the file script-output/game-events.json. This can be leveraged by your
automation and tooling.You can review these logs for detailed insights into player activities, game events, and
overall server health.
The send_event function allows you to log custom events to the game-events.json file. This function is part of the
remote interface event-logger and can be called from other mods or scripts.
To use the send_event function, you need to call it with a table containing the event details. The table must include
the following keys:
event: The name of the event (e.g.,"EVENT_NAME").tick: The current game tick (e.g.,game.tick).data: A table containing additional event data (e.g.,{["key"] = value}).
Here is an example of how to call the send_event function:
remote.call("events-logger", "send_event", {
event = "CUSTOM_EVENT",
tick = game.tick,
data = {
key1 = "value1",
key2 = "value2"
}
})Here is an example of how to call the send_event function:
remote.call("events-logger", "send_std_log",
CUSTOM_EVENT,
MESSAGE
)The script-output/game-events.json file is created and maintained by the helpers.write_file function.
This function, however, does not perform any log rotation or cleanup. It is recommended to implement a log
rotation mechanism to prevent the file from growing indefinitely.
If you are running your dedicated server on Linux, you can use the logrotate utility to manage log rotation. You need
to remember that you have to truncate, not delete the file. It is held open by Factorio server and deleting it will
not free up the disk space, and instead make new content inaccessible until the Factorio server is restarted.
Here is an example of a logrotate configuration file for Factorio:
/opt/factorio/script-output/game-events.json
{
missingok
daily
copytruncate
rotate 4
compress
notifempty
}If you are running your dedicated server on Windows, you can use the Log-Rotate package to manage log rotation. Github Repo
You can install the Log-Rotate module from the PowerShell Gallery using the following command:
Install-Module -Name Log-Rotate -RequiredVersion 1.6.1Here is an example of a Log-Rotate PowerShell script for log rotation:
Import-Module Log-Rotate
# Define your config
# Double-quotes necessary only if there are spaces in the path
$config = @'
"C:\games\factorio\script-output/game-events.json" {
missingok
daily
copytruncate
rotate 4
compress
notifempty
}
'@
# Decide on a Log-Rotate state file that will be created by Log-Rotate
$state = 'C:\var\Log-Rotate\Log-Rotate.status'
# To check rotation logic without rotating files, use the -WhatIf switch (implies -Verbose)
$config | Log-Rotate -State $state -WhatIf
# You can either Pipe the config
$config | Log-Rotate -State $state -Verbose
# Or use the full Command
Log-Rotate -ConfigAsString $config -State $state -VerboseThis mod is released under the MIT License. Feel free to modify and distribute as needed.