Second argument to log (and maybe print): options

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
Honktown
Filter Inserter
Filter Inserter
Posts: 642
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Second argument to log (and maybe print): options

Post by Honktown »

Currently log always prints exactly the same information, and it can get annoying not getting a "clean" print. The closest one can get is adding "\n" at the start* of a string to force it to the next line.

With options, I can think of a few examples:
source = boolean, print the file (debug.getinfo(1).source)
time = boolean, print the decimal bit at the beginning (formatted ctime?)
tick = boolean, print the game tick (after the time, empty quotes or "-1" for outside control phase)

for extra coverage:
line = boolean, print the line number
name = boolean, the function name, number, or nil if anonymous, similar to debug.getinfo(1).name
I have mods! I guess!
Link

justarandomgeek
Filter Inserter
Filter Inserter
Posts: 259
Joined: Fri Mar 18, 2016 4:34 pm
Contact:

Re: Second argument to log (and maybe print): options

Post by justarandomgeek »

print is already vararg, it prints all the args.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2479
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Second argument to log (and maybe print): options

Post by darkfrei »

It would be nice if the argument can disable the text before the logged string or will be changeable.

For example

Code: Select all

log("my logged text", {prefix = mod_name .. "_" .. mod_version .. ": "})
gives:

Code: Select all

MyMod_0.0.1:  my logged text

Rseding91
Factorio Staff
Factorio Staff
Posts: 10283
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Second argument to log (and maybe print): options

Post by Rseding91 »

Well I can see the desire, ideally mods should just not be using logging in the majority of the cases. Really logging is meant for errors and debug info. In both of those cases you want all of what's included in logging now.

Logging is not meant to ever get to the modded minecraft levels of log spam where after a 2 hour play session you have a 16 MB log file.

I've thought a few times about some log-spam-detection system for mods that would auto-cull a mods ability to log if it detected they were spamming the log file. Because it already happens and we see it in crash reports all the time and I hate it.
If you want to get ahold of me I'm almost always on Discord.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2479
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Second argument to log (and maybe print): options

Post by darkfrei »

Rseding91 wrote:
Fri Feb 14, 2020 1:56 pm
Logging is not meant to ever get to the modded minecraft levels of log spam where after a 2 hour play session you have a 16 MB log file.

I've thought a few times about some log-spam-detection system for mods that would auto-cull a mods ability to log if it detected they were spamming the log file. Because it already happens and we see it in crash reports all the time and I hate it.
My log file after just game load is about 50 MB, while I cannot save the needed information in another place.

It would be nice to save the mod log into the script_output folder just with the

Code: Select all

log (string, {script_output = true})

Honktown
Filter Inserter
Filter Inserter
Posts: 642
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Second argument to log (and maybe print): options

Post by Honktown »

darkfrei wrote:
Fri Feb 14, 2020 2:55 pm
Rseding91 wrote:
Fri Feb 14, 2020 1:56 pm
Logging is not meant to ever get to the modded minecraft levels of log spam where after a 2 hour play session you have a 16 MB log file.

I've thought a few times about some log-spam-detection system for mods that would auto-cull a mods ability to log if it detected they were spamming the log file. Because it already happens and we see it in crash reports all the time and I hate it.
My log file after just game load is about 50 MB, while I cannot save the needed information in another place.
Not to be a bother, but what are you logging!?! I normally don't have everything print "fully", I leave the irrelevant log()s commented unless I'm debugging specifically something. Even data.raw is less than 10MB... unless one installs 100 mods.

Only thing I could think with Rseding is go yell at the bad mod authors... making it difficult for the good ones is not the option I would prefer (normally when I have a mod "ready" the only thing that should ever print are errors - which may not print anyway if the game errors first). I do have one mod that logs "a lot" in one step in the data stage, I can add an option for that.
I have mods! I guess!
Link

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2479
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Second argument to log (and maybe print): options

Post by darkfrei »

Honktown wrote:
Fri Feb 14, 2020 3:01 pm
Not to be a bother, but what are you logging!?!
Some mods + viewtopic.php?t=45107

justarandomgeek
Filter Inserter
Filter Inserter
Posts: 259
Joined: Fri Mar 18, 2016 4:34 pm
Contact:

Re: Second argument to log (and maybe print): options

Post by justarandomgeek »

darkfrei wrote:
Fri Feb 14, 2020 3:05 pm
Honktown wrote:
Fri Feb 14, 2020 3:01 pm
Not to be a bother, but what are you logging!?!
Some mods + viewtopic.php?t=45107
so... exactly what you're not supposed to do with it? dumping large amounts of data?

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2479
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Second argument to log (and maybe print): options

Post by darkfrei »

justarandomgeek wrote:
Fri Feb 14, 2020 4:00 pm
darkfrei wrote:
Fri Feb 14, 2020 3:05 pm
Some mods + viewtopic.php?t=45107
so... exactly what you're not supposed to do with it? dumping large amounts of data?
I want dump what I need to dump, but I want that this dump doesn't hurt Rseding91 with the huge size of log file. The suggested second argument can really help in this situation.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 3941
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Second argument to log (and maybe print): options

Post by eradicator »

Why does this suddenly have a new thread, and what happend to the idea of data stage write_file()?
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Honktown
Filter Inserter
Filter Inserter
Posts: 642
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Second argument to log (and maybe print): options

Post by Honktown »

eradicator wrote:
Fri Feb 14, 2020 4:20 pm
Why does this suddenly have a new thread, and what happend to the idea of data stage write_file()?
I did see the thread from ~6 months ago: viewtopic.php?t=71506 unless you meant something else.

My goal isn't writing to script-output in the data stage, it is reducing/customizing log prints.
I have mods! I guess!
Link

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2398
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: Second argument to log (and maybe print): options

Post by Optera »

darkfrei wrote:
Fri Feb 14, 2020 2:55 pm
My log file after just game load is about 50 MB, while I cannot save the needed information in another place.

It would be nice to save the mod log into the script_output folder just with the

Code: Select all

log (string, {script_output = true})
I'm almost scared to ask what kind of data dumps you do during data stage.
Only way I ever get to those two digit MB levels is through running LTN in debug mode for a while.

For data dump shenanigans I can see merit in writing to a different file.

Helfima
Fast Inserter
Fast Inserter
Posts: 173
Joined: Tue Jun 28, 2016 11:40 am
Contact:

Re: Second argument to log (and maybe print): options

Post by Helfima »

I made a debugger which writes only if it is active
it accepts a list of parameters
you can get inspired
https://github.com/Helfima/helmod/blob/ ... ogging.lua
Sample:

Code: Select all

Logging:debug(ModelCompute.classname, "lua_ingredient.name", lua_ingredient.name, "nextCount=", nextCount)

Post Reply

Return to “Modding interface requests”

Who is online

Users browsing this forum: No registered users