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

Enhancement: Add environment variable to set the kpm output information level. #124

Open
zong-zhe opened this issue Jul 6, 2023 · 4 comments · May be fixed by #586
Open

Enhancement: Add environment variable to set the kpm output information level. #124

zong-zhe opened this issue Jul 6, 2023 · 4 comments · May be fixed by #586
Assignees
Labels
enhancement New feature or request

Comments

@zong-zhe
Copy link
Contributor

zong-zhe commented Jul 6, 2023

Enhancement

kpm needs to increase the output information content to facilitate debugging and problem positioning, for users, some content needs to be disabled to optimize the user experience. Therefore, a switch is needed to adjust the content of the output information.

1. Add an environment variable

Set the environment variable KPM_LOG_LEVEL=debug, to show more details for debugging.
Set the environment variable KPM_LOG_LEVEL=info, to show normal message for users.
By default, KPM_LOG_LEVEL=info.

More details mainly includes some raw error information returned by library functions.

2. For future docs.

In the future design documents about displaying information, the label <debug_info> will be used to represent some uncontrollable information returned by third-party library functions.

@AkashKumar7902
Copy link
Contributor

Hey @Peefy,
If this is still relevant, I would love to work on it. Can you please assign me this issue :)

@AkashKumar7902
Copy link
Contributor

AkashKumar7902 commented Jan 26, 2024

@zong-zhe
From what I analyzed from the code, when an error occurs and all the fields of kpmEvent struct is set then both msg and err is printed to the terminal because reporter.Fatal is called at the root file i.e. kpm.go ( i could be wrong here),

kpm/kpm.go

Line 56 in 194168a

reporter.Fatal(err)

type KpmEvent struct {
	errType EventType
	msg     string
	err     error
}

so, KPM_LOG_LEVEL=info would print only msg and KPM_LOG_LEVEL=debug would print both msg and err (that is happening currently).

Is my thought process correct ?

/cc @Peefy

@zong-zhe
Copy link
Contributor Author

@zong-zhe From what I analyzed from the code, when an error occurs and all the fields of kpmEvent struct is set then both msg and err is printed to the terminal because reporter.Fatal is called at the root file i.e. kpm.go ( i could be wrong here),

kpm/kpm.go

Line 56 in 194168a

reporter.Fatal(err)

type KpmEvent struct {
	errType EventType
	msg     string
	err     error
}

so, KPM_LOG_LEVEL=info would print only msg and KPM_LOG_LEVEL=debug would print both msg and err (that is happening currently).

Is my thought process correct ?

/cc @Peefy

Hi @AkashKumar7902
Currently, we aspire for all diagnostic messages within kpm to be returned through KpmEvent, and be output to stdout or stderr using the built-in logWritter in KpmClient.

[The logWritter](https://github.com/kcl-lang/kpm/blob/b197e0b33e4c34d3ec44283bc768014f903ac9c6/pkg/client/client.go#L34)

Therefore, you can create a custom structure and implement the io.Writer interface, allowing you to realize the feature of controlling output via the environment variable within your defined structure.

And ignore this, it will be deprecated. kpm cli will be replaced by the kcl cli.

kpm/kpm.go

Line 56 in 194168a

reporter.Fatal(err)

@Gmin2
Copy link
Contributor

Gmin2 commented Jul 28, 2024

Is this still relevant ?
cc @zong-zhe @Peefy

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

Successfully merging a pull request may close this issue.

3 participants