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

feat: use NODE_ENV and cds.env.features.kibana_formatter for format #2481

Merged
merged 13 commits into from
May 25, 2022

Conversation

ZhongpinWang
Copy link
Contributor

@ZhongpinWang ZhongpinWang commented May 17, 2022

Closes SAP/cloud-sdk-backlog#380.

We implemented setLogFormat and setGlobalLogFormat in this ticket similar to log level. The default local and kibana format is exported with logFormat. Now, users can specify a log format both from the default two or even their customized formatters.

NODE_ENV is used to determine the initial log format: production -> kibana, local otherwise. This can be overwritten by the aforementioned two setters.

@ZhongpinWang ZhongpinWang marked this pull request as draft May 17, 2022 16:07
@ZhongpinWang ZhongpinWang marked this pull request as ready for review May 18, 2022 08:29
@ZhongpinWang
Copy link
Contributor Author

ZhongpinWang commented May 18, 2022

There are following cases:

  1. If features.kibana undefined
  • NODE_ENV is production -> kibana.
  • Otherwise, local.
  1. If features.kibana is defined
  • features.kibana is true -> kibana
  • features.kibana is false -> local

There are potentially some problems though and I need your thoughts on these:

  1. If a user does not use cds and wants to use local in production, they can only set features.kibana in package.json as a work around. Could this case happen?
  2. Also we need to import @sap/cds in cloud-sdk-logger.ts to align with the CAP configuration. Would it be too much or it is fine?
  3. If we want to generalize the situation, maybe we can define a separate env variable for the logger as well, which has the highest priority?

packages/util/src/logger/cloud-sdk-logger.ts Outdated Show resolved Hide resolved
.changeset/silent-cougars-bake.md Outdated Show resolved Hide resolved
Copy link
Contributor

@marikaner marikaner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not depend on CDS, I think this might not have been clear enough in the ticket.

packages/util/package.json Outdated Show resolved Hide resolved
packages/util/src/logger/cloud-sdk-logger.ts Outdated Show resolved Hide resolved
@ZhongpinWang
Copy link
Contributor Author

We should not depend on CDS, I think this might not have been clear enough in the ticket.

[fixed] Thanks for the feedback. I removed the @sap/cds dependency and add some functions to let users set up the log format similar to the log level. I kept NODE_ENV to determine the default log format same as before.

@ZhongpinWang ZhongpinWang requested a review from marikaner May 20, 2022 16:46
Copy link
Contributor

@marikaner marikaner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for taking so long. Please read my comment about scope creep ;) and add the interface and the getter. 😊

@@ -49,7 +63,7 @@ export function unmuteLoggers(): void {
*/
export const cloudSdkExceptionLogger = container.get(exceptionLoggerId, {
defaultMeta: { logger: loggerReference, test: 'exception' },
format,
format: container.options.format,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] Shouldn't the format of the SDK exception logger be the same as for other logs?

Comment on lines +206 to +211
/**
* Change the log format of a logger based on its message context.
* e.g., to set the log format for the destination accessor module of the SDK to `local`, simply call `setLogFormat(logFormat.local, 'destination-accessor')`.
* @param format - Format to set the logger to. Use `logFormat` to get the pre-defined log formats or use a custom log format.
* @param messageContextOrLogger - Message context of the logger to change the log level for or the logger itself.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nth] This is more than required by the original issue (scope creep) and usually we shouldn't allow for this, because this can cause some problems down the line (e.g. because the API was not aligned, did we consider that whether there are any features that could break because of this, etc.).

Anyways, I discussed this with @FrankEssenberger at length yesterday and we agreed that for this case we will keep it.

The reason I am mentioning this, is that currently users don't have the possibility to change the log format at all and with this we are opening up a new feature, that f.e. depends on types from the logform lib.

[req] We usually introduce our own compatible interfaces, we should do the same for the Format. @jjtang1985 could you show an example?
[req] If we have set global, get global, set single, I guess we also need get single?

Copy link
Contributor

@marikaner marikaner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discuessed, I think the requested changes are not necessary given the current state of the loggers. Let's stay consistent for now and make improvements later.

@ZhongpinWang ZhongpinWang requested review from florian-richter and removed request for florian-richter May 24, 2022 17:12
@ZhongpinWang ZhongpinWang merged commit 89f1c42 into main May 25, 2022
@ZhongpinWang ZhongpinWang deleted the support-configuring-log-format-backlog-380 branch May 25, 2022 08:01
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

Successfully merging this pull request may close these issues.

3 participants