Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "logging" Module #1189

Open
madoar opened this issue Jan 5, 2020 · 7 comments
Open

Add "logging" Module #1189

madoar opened this issue Jan 5, 2020 · 7 comments

Comments

@madoar
Copy link
Collaborator

madoar commented Jan 5, 2020

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
Copy link
Collaborator

plata commented Jan 5, 2020

I would suggest to implement this as a Bean.

@madoar
Copy link
Collaborator Author

madoar commented Jan 5, 2020

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

@plata
Copy link
Collaborator

plata commented Jan 5, 2020

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.

@madoar
Copy link
Collaborator Author

madoar commented Jan 5, 2020

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
Copy link
Collaborator

plata commented Jan 5, 2020

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.

@madoar
Copy link
Collaborator Author

madoar commented Jan 5, 2020

I'm fine either way.

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

@Zemogiter
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants