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-to-file / logging on Windows with SC.exe #1416

Closed
itdaniher opened this issue Oct 16, 2020 · 5 comments · Fixed by #1534
Closed

Log-to-file / logging on Windows with SC.exe #1416

itdaniher opened this issue Oct 16, 2020 · 5 comments · Fixed by #1534

Comments

@itdaniher
Copy link

Consul Template version

v0.25.1

Expected behavior

Consul-template supports logging to file. Consul-template can be started as a service on Windows, and the resultant messages can be inspected. Consul offers -log-file via stdarg and Nomad offers log_file in the config.

Actual behavior

Consul-template only supports Syslog and stdout/stderr logging mechanisms. Windows discards stdout/stderr messages from services. Seemingly no way to get persistent logging without wrapping consul-template.exe in a script that captures stdout and stderr to a file.

Calling: ArraySeq(sc.exe, create, consul-template, binpath=, C:\opt\consul-template\consul-template.exe)
Calling: ArraySeq(sc.exe, config, consul-template, DisplayName=, Consul-Templat, binPath=, C:\opt\consul-template\consul-template.exe -config=C:\opt\consul-template\config-windows.hcl -vault-token=s.REDACTED -consul-token=REDACTED)
Calling: WrappedArray(sc.exe, start, consul-template)

Steps to reproduce

  1. Create and start an instance of consul-template as a service with sc.exe on Windows
  2. Attempt to inspect behavior.
  3. Unable to inspect behavior - no ability to log messages to a file.

References

Are there any other GitHub issues (open or closed) that should
be linked here? For example:

@eikenb
Copy link
Contributor

eikenb commented Oct 16, 2020

They @itdaniher, thanks for taking the time to submit a ticket.

What do applications typically do for logging on Windows? Is it typical to provide something like a '-log-file /path/to/log` style option, either as a command line argument or a config option? What would you like to see?

I'm sure I can look this up but I'm mainly interested in what you want, a real use case. Thanks.

@itdaniher
Copy link
Author

I'd love to see -log-file as a command line argument. Consul's semantics here work very nicely for our needs. Not sure what's the norm (fortunately not often problem-solving on Windows!)

Thanks!

@ksandrmatveyev
Copy link

ksandrmatveyev commented Jul 7, 2021

Hi @eikenb . I think it will be really useful as we can run consul-template as windows service since 0.26.0 #1382, but we are blind due to no logs we can get. https://www.consul.io/docs/agent/options#_log_file, such as -log-file, -log-rotate-bytes, -log-rotate-duration and -log-rotate-max-files, are what I assume is ok

deblasis added a commit to deblasis/consul-template that referenced this issue Nov 12, 2021
- Consul-like CLI flags used to control the behaviour of the feature
- `log_file` configuration stanza
- updated docs for CLI and config

Fixes hashicorp#1416

Signed-off-by: Alessandro De Blasis <alex@deblasis.net>
@deblasis
Copy link
Contributor

Hi there 👋

I just created #1534. It should address this issue by adding -log-file, -log-rotate-bytes, -log-rotate-duration and -log-rotate-max-files and also the corresponding items inside a new configuration stanza named log-file.

I also dared to write the relevant documentation. I hope that's OK.

Cheers!

@eikenb eikenb added this to the v0.28.0 milestone Nov 17, 2021
@mcouillard
Copy link

As an alternative, some Windows magic can redirect standard output to a file. So creating the service like this will do it (capturing both standard out, 1, and errors, 2, in the same file).

sc.exe create VaultAgent binPath= "vault.exe agent -config=vault-agent.hcl -log-level=DEBUG 1>> agent.log 2>&1" displayName= "VaultAgent" start= auto

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

Successfully merging a pull request may close this issue.

5 participants