PhoenicisOrg/scripts

Add "logging" Module

madoar opened this issue · 7 comments

Currently we have no clear way how a script developer should create debug logs. Often we use print(...) or console.log(...) statements to write debug output to the terminal, but this is no solution we should use in the future. Therefore I propose we add a dedicated logging module to the script repository. This module should provide a set of logging functions that can be used to log debug output. Behind the scene the new logging module should make use of the existing Java API to log the information in a uniform way with phoenicis.

An open question is how should the logging methods be accessed. I can imagine two approaches

First Approach

The first and most simple approach allows the following access:

const { debug, info, error, warn } = include(...);

...
// later on
info("Start task x");
...

This approach has the benefit that it is very easy because you can directly import the required logging methods. An issue with this approach is that it does not allow for additional customization based on the script the logging messages are printed from

Second Approach

The second approach tries to fix the shortcoming of the first approach. It allows the following usage:

const Logger = include(...);
const { debug, info, error, warn } = Logger.create("Zelda");
// or:  const { debug, info, error, warn } = new Logger("Zelda");

...
// later on
info("Start task x");
...

The disadvantage of this approach is that it requires an additional command before logging can be used.

plata commented

I would suggest to implement this as a Bean.

Can you give a short example how you would use this then from JS?

plata commented

Basically no difference to what you suggested. The only point about it is that it would be implemented in Java such that it can be used from all script repositories.

The problem with a Java only solution (i.e. bean) is that we can't use destructuring. This means we would need to use something like:

const Logger = Bean(...);
const log = Logger.create("Zelda");

...
// later on
log.info("Start task x");
...
plata commented

I do not see a problem with this syntax. Actually, I prefer logger.info and logger.debug over just info and debug because it makes clear that both belongs to logging.

I'm fine either way.

@qparis, @ImperatorS79, @Zemogiter do you have any preferences?

I prefer the first approach for the same reasons as stated in the OP.