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

Log callback functions #137

Merged
merged 4 commits into from
May 18, 2023
Merged

Log callback functions #137

merged 4 commits into from
May 18, 2023

Conversation

fasmat
Copy link
Member

@fasmat fasmat commented May 11, 2023

This integrates the changes from spacemeshos/post-rs#47 to allow postrs to log while being used in go-spacemesh.

@fasmat fasmat requested a review from poszu May 11, 2023 13:53
@fasmat fasmat self-assigned this May 11, 2023
@fasmat fasmat force-pushed the update-logging branch 2 times, most recently from 00cb59d to 49304c2 Compare May 17, 2023 09:16
Comment on lines +35 to +38
func GenerateProof(dataDir string, challenge []byte, cfg config.Config, logger *zap.Logger, nonces uint, threads uint, powScrypt config.ScryptParams) (*shared.Proof, error) {
if logger != nil {
setLogCallback(logger)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think that GenerateProof() and others should accept logger to be set for logging in the post-rs library. Only the first one will be set and remembered forever. While it's probably not a big deal in application code (as there will only be a single logger forever), in tests it will cause all logs to be recorded in the logger created for the first test that was executed probably causing them to appear in the wrong place (?).

I was imagining that there could be an exported function func ConfigureLogging(logger *zap.Logger) documented to be idempotent, which should be called once by the application on its boot (starting phase of postcli or go-spacemesh).

Copy link
Member Author

@fasmat fasmat May 19, 2023

Choose a reason for hiding this comment

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

I think a global logger in general is an issue. A ConfigureLogging function is a workaround for the main application, but our approach to logging is not to have one global instance but (possible multiple) instances that are dependency-injected into the services.

With a global logger running tests in parallel becomes more difficult because logs from different tests are all printed to the same output concurrently and cannot easily be associated with the test they came from. This is why for instance zaptest.NewLog takes an instance of testing.T, so that the logs can be sorted to the tests they came from and go test can print the outputs correctly.

EDIT: and tests can have different logging levels (e.g. tests where logs are irrelevant have a no-op logger, some have only info for dependent services and debug for the service at test, etc.)

@poszu poszu merged commit 6b39087 into develop May 18, 2023
@poszu poszu deleted the update-logging branch May 18, 2023 07:12
bors bot pushed a commit to spacemeshos/go-spacemesh that referenced this pull request May 18, 2023
## Motivation
This integrates the new logging in `post` (spacemeshos/post#137) into `go-spacemesh`.

## Changes
The logger needs to be passed thorough to some components of `post`.

Do not merge before
- [x] spacemeshos/post-rs#47
- [x] spacemeshos/post#137
- [x] #4390

are merged and released

## Test Plan
Existing tests pass.

## TODO
<!-- This section should be removed when all items are complete -->
- [x] Explain motivation or link existing issue(s)
- [x] Test changes and document test plan
- [x] Update documentation as needed

## DevOps Notes
<!-- Please uncheck these items as applicable to make DevOps aware of changes that may affect releases -->
- [x] This PR does not require configuration changes (e.g., environment variables, GitHub secrets, VM resources)
- [x] This PR does not affect public APIs
- [x] This PR does not rely on a new version of external services (PoET, elasticsearch, etc.)
- [x] This PR does not make changes to log messages (which monitoring infrastructure may rely on)


Co-authored-by: Bartosz Różański <[email protected]>
bors bot pushed a commit to spacemeshos/go-spacemesh that referenced this pull request May 18, 2023
## Motivation
This integrates the new logging in `post` (spacemeshos/post#137) into `go-spacemesh`.

## Changes
The logger needs to be passed thorough to some components of `post`.

Do not merge before
- [x] spacemeshos/post-rs#47
- [x] spacemeshos/post#137
- [x] #4390

are merged and released

## Test Plan
Existing tests pass.

## TODO
<!-- This section should be removed when all items are complete -->
- [x] Explain motivation or link existing issue(s)
- [x] Test changes and document test plan
- [x] Update documentation as needed

## DevOps Notes
<!-- Please uncheck these items as applicable to make DevOps aware of changes that may affect releases -->
- [x] This PR does not require configuration changes (e.g., environment variables, GitHub secrets, VM resources)
- [x] This PR does not affect public APIs
- [x] This PR does not rely on a new version of external services (PoET, elasticsearch, etc.)
- [x] This PR does not make changes to log messages (which monitoring infrastructure may rely on)


Co-authored-by: Bartosz Różański <[email protected]>
bors bot pushed a commit to spacemeshos/go-spacemesh that referenced this pull request May 18, 2023
## Motivation
This integrates the new logging in `post` (spacemeshos/post#137) into `go-spacemesh`.

## Changes
The logger needs to be passed thorough to some components of `post`.

Do not merge before
- [x] spacemeshos/post-rs#47
- [x] spacemeshos/post#137
- [x] #4390

are merged and released

## Test Plan
Existing tests pass.

## TODO
<!-- This section should be removed when all items are complete -->
- [x] Explain motivation or link existing issue(s)
- [x] Test changes and document test plan
- [x] Update documentation as needed

## DevOps Notes
<!-- Please uncheck these items as applicable to make DevOps aware of changes that may affect releases -->
- [x] This PR does not require configuration changes (e.g., environment variables, GitHub secrets, VM resources)
- [x] This PR does not affect public APIs
- [x] This PR does not rely on a new version of external services (PoET, elasticsearch, etc.)
- [x] This PR does not make changes to log messages (which monitoring infrastructure may rely on)


Co-authored-by: Bartosz Różański <[email protected]>
bors bot pushed a commit to spacemeshos/go-spacemesh that referenced this pull request May 18, 2023
## Motivation
This integrates the new logging in `post` (spacemeshos/post#137) into `go-spacemesh`.

## Changes
The logger needs to be passed thorough to some components of `post`.

Do not merge before
- [x] spacemeshos/post-rs#47
- [x] spacemeshos/post#137
- [x] #4390

are merged and released

## Test Plan
Existing tests pass.

## TODO
<!-- This section should be removed when all items are complete -->
- [x] Explain motivation or link existing issue(s)
- [x] Test changes and document test plan
- [x] Update documentation as needed

## DevOps Notes
<!-- Please uncheck these items as applicable to make DevOps aware of changes that may affect releases -->
- [x] This PR does not require configuration changes (e.g., environment variables, GitHub secrets, VM resources)
- [x] This PR does not affect public APIs
- [x] This PR does not rely on a new version of external services (PoET, elasticsearch, etc.)
- [x] This PR does not make changes to log messages (which monitoring infrastructure may rely on)


Co-authored-by: Bartosz Różański <[email protected]>
bors bot pushed a commit to spacemeshos/go-spacemesh that referenced this pull request May 18, 2023
## Motivation
This integrates the new logging in `post` (spacemeshos/post#137) into `go-spacemesh`.

## Changes
The logger needs to be passed thorough to some components of `post`.

Do not merge before
- [x] spacemeshos/post-rs#47
- [x] spacemeshos/post#137
- [x] #4390

are merged and released

## Test Plan
Existing tests pass.

## TODO
<!-- This section should be removed when all items are complete -->
- [x] Explain motivation or link existing issue(s)
- [x] Test changes and document test plan
- [x] Update documentation as needed

## DevOps Notes
<!-- Please uncheck these items as applicable to make DevOps aware of changes that may affect releases -->
- [x] This PR does not require configuration changes (e.g., environment variables, GitHub secrets, VM resources)
- [x] This PR does not affect public APIs
- [x] This PR does not rely on a new version of external services (PoET, elasticsearch, etc.)
- [x] This PR does not make changes to log messages (which monitoring infrastructure may rely on)


Co-authored-by: Bartosz Różański <[email protected]>
bors bot pushed a commit to spacemeshos/go-spacemesh that referenced this pull request May 18, 2023
## Motivation
This integrates the new logging in `post` (spacemeshos/post#137) into `go-spacemesh`.

## Changes
The logger needs to be passed thorough to some components of `post`.

Do not merge before
- [x] spacemeshos/post-rs#47
- [x] spacemeshos/post#137
- [x] #4390

are merged and released

## Test Plan
Existing tests pass.

## TODO
<!-- This section should be removed when all items are complete -->
- [x] Explain motivation or link existing issue(s)
- [x] Test changes and document test plan
- [x] Update documentation as needed

## DevOps Notes
<!-- Please uncheck these items as applicable to make DevOps aware of changes that may affect releases -->
- [x] This PR does not require configuration changes (e.g., environment variables, GitHub secrets, VM resources)
- [x] This PR does not affect public APIs
- [x] This PR does not rely on a new version of external services (PoET, elasticsearch, etc.)
- [x] This PR does not make changes to log messages (which monitoring infrastructure may rely on)


Co-authored-by: Bartosz Różański <[email protected]>
bors bot pushed a commit to spacemeshos/go-spacemesh that referenced this pull request May 18, 2023
## Motivation
This integrates the new logging in `post` (spacemeshos/post#137) into `go-spacemesh`.

## Changes
The logger needs to be passed thorough to some components of `post`.

Do not merge before
- [x] spacemeshos/post-rs#47
- [x] spacemeshos/post#137
- [x] #4390

are merged and released

## Test Plan
Existing tests pass.

## TODO
<!-- This section should be removed when all items are complete -->
- [x] Explain motivation or link existing issue(s)
- [x] Test changes and document test plan
- [x] Update documentation as needed

## DevOps Notes
<!-- Please uncheck these items as applicable to make DevOps aware of changes that may affect releases -->
- [x] This PR does not require configuration changes (e.g., environment variables, GitHub secrets, VM resources)
- [x] This PR does not affect public APIs
- [x] This PR does not rely on a new version of external services (PoET, elasticsearch, etc.)
- [x] This PR does not make changes to log messages (which monitoring infrastructure may rely on)


Co-authored-by: Bartosz Różański <[email protected]>
poszu added a commit to spacemeshos/go-spacemesh that referenced this pull request May 18, 2023
## Motivation
This integrates the new logging in `post` (spacemeshos/post#137) into `go-spacemesh`.

## Changes
The logger needs to be passed thorough to some components of `post`.

Do not merge before
- [x] spacemeshos/post-rs#47
- [x] spacemeshos/post#137
- [x] #4390

are merged and released

## Test Plan
Existing tests pass.

## TODO
<!-- This section should be removed when all items are complete -->
- [x] Explain motivation or link existing issue(s)
- [x] Test changes and document test plan
- [x] Update documentation as needed

## DevOps Notes
<!-- Please uncheck these items as applicable to make DevOps aware of changes that may affect releases -->
- [x] This PR does not require configuration changes (e.g., environment variables, GitHub secrets, VM resources)
- [x] This PR does not affect public APIs
- [x] This PR does not rely on a new version of external services (PoET, elasticsearch, etc.)
- [x] This PR does not make changes to log messages (which monitoring infrastructure may rely on)


Co-authored-by: Bartosz Różański <[email protected]>
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.

2 participants