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

unable to log.OutputToBuf early enough #588

Open
tharvik opened this issue Oct 15, 2019 · 4 comments
Open

unable to log.OutputToBuf early enough #588

tharvik opened this issue Oct 15, 2019 · 4 comments

Comments

@tharvik
Copy link
Contributor

tharvik commented Oct 15, 2019

I want to output something to stdout without having the logger writing it on. The issue is that it's already writing quite early on (via the func init construct).

package main

import (
	_ "go.dedis.ch/cothority/v3/skipchain"
	onet_log "go.dedis.ch/onet/v3/log"
)

func init() {
	onet_log.OutputToBuf() // already useless
}

func main() {
	// nothing
}

gives with DEBUG_LVL=4

4 : protocol.go:111 (v3.(*protocolStorage).Register) - Registered Broadcast to 59af9e1e-79cc-301b-b2b4-bbfe989bac36
4 : protocol.go:111 (v3.(*protocolStorage).Register) - Registered blsCoSiProtoDefault to 522a1bad-ed6f-3326-bbef-36fe2a859cf1
4 : protocol.go:111 (v3.(*protocolStorage).Register) - Registered blsSubCoSiProtoDefault to 9941c053-dc08-359f-8a68-d00fee072378
4 : protocol.go:111 (v3.(*protocolStorage).Register) - Registered scExtendRoster to 324d4101-3ab7-3672-a985-43b9ec56a82e
4 : protocol.go:111 (v3.(*protocolStorage).Register) - Registered scGetBlocks to 15533989-b358-3b71-b454-4558037237a3

A working way to do it (but ugly), is to create a dedicated pkg just containing the OutputToBuf call inside an init, then importing it before anything else.

A better way to fix it would be to avoid init everything, especially if the func called have side effects. That's the main issue IMO, that init (and its combo, global variables) is used as a way to avoid having a dedicated struct to contain the state of a given part.

@tharvik tharvik added the bug label Oct 15, 2019
@ineiti
Copy link
Member

ineiti commented Oct 21, 2019

That will be difficult to achieve given the compile-time plugin structure of protocols and services.

If I understand your proposition correctly, you would like to replace the automatic registration of protocols and services with something more user-controlled.

Can you be more specific what you're actually trying to achieve?

@tharvik
Copy link
Contributor Author

tharvik commented Oct 21, 2019

If I understand your proposition correctly, you would like to replace the automatic registration of protocols and services with something more user-controlled.

In the long run, that would be best; but maybe, it's reaching larger than the scope of this issue.

Can you be more specific what you're actually trying to achieve?

I'm writing a small CLI which generates a Roster configuration, but outputing this config to stdout gets it gets mangled with the logging from onet.

@ineiti
Copy link
Member

ineiti commented Oct 22, 2019

So you either write it to a file or put DEBUG_LVL=0 when calling it...

@tharvik
Copy link
Contributor Author

tharvik commented Oct 22, 2019

So you either write it to a file or put DEBUG_LVL=0 when calling it...

I can work around it, that's not the issue. The issue is that I don't have a normal/obvious way to control os.Stdout when using onet, it get mixed with intended output and library output. IMO, it's akin to having a library calling os.Exit when receiving a malformed message.

@ineiti ineiti added v4 wontfix and removed bug labels Mar 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants