How to log (flag or track) a variable?

I’m having a hard time with a few values.
So to make tests easier, I would like to know the value of a few variables. I just don’t know how to do it.

There is that stonehearth.log file that logs a few things, I thought it would be good to have a code to print my values there.

I tried to use this:
and other variations, but it didn’t worked.

How to do it, and is this the right way to track a value?

The way the log works is you create a log at the top of the file, and then you have to specify the level of the log, and then listen to that log’s level in your users settings.

local log = radiant.log.create_logger(‘my_log_name’)

local MyClass = class()
function MyClass:func(arg_1)
log:detail(“calling func with arg_1: %s”, arg_1)

THEN, in your user_settings.json, add a logging section
"logging" : {
“mods” : {
“my_mod” : {
“my_log_name”: 9

The log level numbers are:
ERROR = 1,
INFO = 5,
DEBUG = 7,
SPAM = 9,
The number you put into your user_settings.json file is the highest log level that will be printed out into stonehearth.log. Ex: putting the number 9 means you’ll get all errors, warnings, info, debug, detail, and spam. Meanwhile, putting 3 means you’ll only get errors and warnings.

Hope this helps
Let me know if you run into any issues.


Yes, thanks, it helped a lot.
I was missing the user_settings.json setup.

The user_settings method does not work for me. If it doesn’t work for anyone else, see here for alternate way

So if it doesn’t work for you, it might be related to the user setting registration for that log. I know based on which function is used to write out the log statement, the registration in user settings will change. Can you paste the line that creates the log and your user settings file?


Thank you, Yang! I actually sent you a PM yesterday with that information, so you might still have it there. I was trying to write from the main Stonehearth mod. I’ve since separated my mod into an smod, which can be found here, along with the relevant user_settings and lua code: