nomad-coe / nomad-simulations

A NOMAD plugin containing base sections for simulations.
https://nomad-coe.github.io/nomad-simulations/
Apache License 2.0
6 stars 1 forks source link

Module logger #141

Open JosePizarro3 opened 1 month ago

JosePizarro3 commented 1 month ago

@ladinesa @ndaelman-hu I have a question regarding the logger. Right now, I was passing it as an input of our functions, but I realize this might not be the best practice.

Do you know what is the best way of handling this? Define it in the class or in the modules?

ladinesa commented 1 month ago

the parse function takes in the logger as arg which should be passed on to other functions. i usually make it as class attrb. you can also define it as var in the module in some cases

ndaelman-hu commented 1 month ago

The only solution is to share the same logger object among functions. That would be either a decorator or a class attribute, as Alvin suggested. Given our structure, I would use a class decorator that prepends the section name.

ndaelman-hu commented 1 month ago

Let me first merge my branch before overhauling the schema at this scale, though.

JosePizarro3 commented 1 month ago

Ok, I think class attribute is the most consistent one. I will fix it elsewhere later.

ndaelman-hu commented 1 month ago

Ok, I think class attribute is the most consistent one. I will fix it elsewhere later.

Indeed, and if you apply it as a class decorator, your implementation will be more modular. How you prefer.

JosePizarro3 commented 1 month ago

Ok, I think class attribute is the most consistent one. I will fix it elsewhere later.

Indeed, and if you apply it as a class decorator, your implementation will be more modular. How you prefer.

Why a class decorator? I think an input to each class __init__ should be enough, right?

ndaelman-hu commented 1 month ago

Ok, I think class attribute is the most consistent one. I will fix it elsewhere later.

Indeed, and if you apply it as a class decorator, your implementation will be more modular. How you prefer.

Why a class decorator? I think an input to each class __init__ should be enough, right?

Please don't move it to the __init__ args, that just displaces the issue, rather than solving it. Instead, you want a function called during (class?) instantiation that reads in the context. That functions could either be inherited or set as a class decorator to the sections. Either are fine for our usage.