OpenFactorioServerManager / factorio-server-manager

A tool to help manage Factorio multiplayer servers including mods and save games.
MIT License
541 stars 130 forks source link

Getting chatlogs without console logs #306

Closed Mattie112 closed 2 years ago

Mattie112 commented 2 years ago

(so it can be parsed a bit better in my discord bot)

If I manually start a server like: bin\x64\factorio.exe --console-log console.log --start-server TEST

I get 2 files factorio-current.log and console.log

The factorio-current.log contains all gameplay related stuff (loading mods etc) small example:

   2.948 Checksum for script __FactoriGOChatBot-companion__/control.lua: 593434900
   2.950 Checksum for script __far-reach__/control.lua: 1060698213
   2.953 Checksum for script __ixuClock__/control.lua: 1447163985
   2.955 Checksum for script __LightedPolesPlus__/control.lua: 909963510
   2.960 Info UDPSocket.cpp:27: Opening socket at (IP ADDR:({0.0.0.0:34197}))
   2.960 Hosting game at IP ADDR:({0.0.0.0:34197})
   2.960 Info HttpSharedState.cpp:54: Downloading https://auth.factorio.com/generate-server-padlock-2?api_version=4
   3.491 Info AuthServerConnector.cpp:69: Obtained serverPadlock for serverHash (Zcswdywo3udzOOITqi6yKqZBLYfD78CX) from the auth server.
   3.491 Info ServerMultiplayerManager.cpp:799: updateTick(0) changing state from(CreatingGame) to(InGame)
   8.944 ConnectionRequestReplyConfirm (type(ConnectionRequestReplyConfirm) ) from(IP ADDR:({127.0.0.1:62928}))
   8.944 Refusing connection for address (IP ADDR:({127.0.0.1:62928})), username (Mattie). UserVerificationMissing
   9.344 ConnectionRequestReplyConfirm (type(ConnectionRequestReplyConfirm) ) from(IP ADDR:({127.0.0.1:62929}))
   9.347 Info ServerRouter.cpp:467: Replying to connectionRequest for address(IP ADDR:({127.0.0.1:62929})).
   9.347 Info ServerSynchronizer.cpp:608: nextHeartbeatSequenceNumber(350) adding peer(1)
   9.364 Info ServerMultiplayerManager.cpp:799: updateTick(0) changing state from(InGame) to(InGameSavingMap)
   9.377 Info ServerMultiplayerManager.cpp:950: updateTick(0) received stateChanged peerID(1) oldState(Ready) newState(ConnectedWaitingForMap)

The file console.log contains:

=== Log opened 2022-01-30 15:22:53 ===
2022-01-30 15:23:00 [JOIN] Mattie joined the game
2022-01-30 15:23:04 [CHAT] Mattie: foo
2022-01-30 15:23:08 [CHAT] Mattie: bar
2022-01-30 15:23:09 [LEAVE] Mattie left the game

For my Discord bot I want to get chat/join/leave, however parsing the last line does not always work because if someone quits you get a lot of log entries in one go. It would be great if the console-log could be specified to go to an other file.

There might be an option https://github.com/OpenFactorioServerManager/factorio-server-manager/wiki/Installation-and-Usage#confjson but I tried all combinations but I could not get it to work. I can't find a good explanation on what it does.

For example, my conf.json contains:

        "console_log_file": "/opt/factorio/console.log",

But when I check the log I do not see this added to the start arguments:

2022/01/30 14:18:52 Factorio Server:    0.001 Program arguments: "/opt/factorio/bin/x64/factorio" "--bind" "0.0.0.0" "--port" "34197" "--server-settings" "/opt/factorio/config/server-settings.json" "--rcon-port" "34198" "--rcon-password" <private> "--server-adminlist" "/opt/factorio/config/server-adminlist.json" "--start-server-load-latest"

Am I using it incorrectly? Or is this not implemented? I am on the devlop branch btw.

Perhaps around here if I understand the code correctly: https://github.com/OpenFactorioServerManager/factorio-server-manager/blob/develop/src/factorio/server.go#L250

Mattie112 commented 2 years ago

And just to confirm:

Adding the following:

    args = append(args,
        "--bind", server.BindIP,
        "--port", strconv.Itoa(server.Port),
        "--server-settings", config.SettingsFile,
        "--rcon-port", strconv.Itoa(config.FactorioRconPort),
        "--rcon-password", config.FactorioRconPass,
        "--console-log", "/opt/factorio/console.log")

Does give me a nice log with only chats! Exactly what I want! (and yes I did get it to work building in WSL).

So really my question is: What are the current log file options? Are they correct / used?

Would it be OK if I submit a PR that adds a chat-log config variable (optional). I think on startup we should clear this file just like the factorio-server-console.log

edit: If anyone wants to try this HARDCODED to /opt/factorio/console.log feel free to use: https://hub.docker.com/layers/190112090/mattie112/temp/factorio-server-manager/images/sha256-d9586a00ccead3f95ecd295dc798e6556312b3628f08c6e1616ad710dd76ffec?context=repo