Afforess / Factorio-Stdlib

Factorio Standard Library Project
ISC License
165 stars 49 forks source link

added option to Logger.new to use log() if game isn't available #82

Closed Choumiko closed 7 years ago

Choumiko commented 7 years ago

Can be used during the data stage and outside of functions in control.lua. When game is available the first Logger:log() writes the buffered messages from log()

adresses #81

Nexela commented 7 years ago

While you are in the logger, I would actually love an option to not pre-pend the "logs" directory. I like keeping my logs organized by mod name. So I am constantly having to do something like this

MOD.logfile.file_name = MOD.logfile.file_name:gsub("logs/", "", 1)
Choumiko commented 7 years ago

With blueprint strings gone i think there are close to 0 mods (except the google map mod maybe?) that produce logfiles that are usefull to the players. I think simply removing it should be fine. If an additional folder is desired you can just prepend it to the modname. Logger.mod_name is currently only used in the log() i added.

Another possible issue with the current PR: In case the script errors before Logger.log() can actually use game.write_file() the buffered messages will be lost. Which may be not ideal if using it for debugging?

Afforess commented 7 years ago

Another possible issue with the current PR: In case the script errors before Logger.log() can actually use game.write_file() the buffered messages will be lost. Which may be not ideal if using it for debugging?

This scenario is only possible if an error occurs before the save is loaded and no ticks have occurred (assuming you have the debug flag set to true). Given that you lose the buffer when you have an error, and therefore have a stacktrace already for that error, you probably don't need what was in the buffer. I'm not overly worried.