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

parameter to set log file location #367

Closed
fsiler opened this issue Oct 24, 2023 · 8 comments
Closed

parameter to set log file location #367

fsiler opened this issue Oct 24, 2023 · 8 comments
Labels
enhancement New feature or request

Comments

@fsiler
Copy link

fsiler commented Oct 24, 2023

Is your feature request related to a problem? Please describe.
I'm trying to run as a Windows service and I can't find events in the Log Viewer or the log file.

Describe the solution you'd like
Parameters, ideally both in the config file and command line, to set log file path.

Describe alternatives you've considered
Looked in Event Viewer and on disk, can't find log file.

@fsiler fsiler added the enhancement New feature or request label Oct 24, 2023
@burningalchemist
Copy link
Owner

Hey @fsiler, sql_exporter is writing logs to stdout (or stderr) (or in the case of Windows STD_OUTPUT_HANDLE or STD_ERROR_HANDLE). There are no plans to involve sql_exporter in any filesystem activities like writing log files, managing log file rotation and so on. This is typically the job of the platform the service runs on to handle and route such data.

Writing logs to the Windows Event log requires direct interaction with this subsystem as well, which is also undesired.

Current workaround to keep things in the file would be to use > or >> redirects in your service definition string like here. This also implies the user is responsible for log rotation, making sure there's enough disk space. etc. So overall there's an established process defined by the user.

There might be better alternatives for passing stdout stream to files in Windows, but unfortunately I don't have enough domain knowledge to suggest anything at this time.

@fsiler
Copy link
Author

fsiler commented Oct 24, 2023

I appreciate the desire to not be involved in handling files. However, the link you sent me just flat out doesn't work. I have tried several variations and can't get this to work. I'm wondering if I need to wrap in powershell or something to get this to function. If I get it to work, would you accept a pull request showing the working method?

@burningalchemist
Copy link
Owner

burningalchemist commented Oct 24, 2023

Hey @fsiler, I'm sorry it didn't work. I need to find a Windows box somewhere to try things out myself. I also agree that you might need to use Powershell (e.g. Tee-Object method or something).

As for the contribution, I'd be interested in the prior discussion first, of course. Any recipe that solves the problem without writing files from the service is really appreciated, but I also assume that our options are limited.

Let me have a look at it. I'm currently busy for delivering some other features, so I don't have any ETA at the moment.

@fsiler
Copy link
Author

fsiler commented Oct 27, 2023

I think it's probably possible to use a Powershell wrapper as described here to capture STDOUT and STDERR. Of course, that doesn't require code changes, so if I can get that to work I'll do a writeup and contribute a PR against the README :).

@burningalchemist
Copy link
Owner

burningalchemist commented Oct 28, 2023

Yeah, that'd be fantastic and a valuable contribution for many Windows users. If not, I think it's still essential for Windows users to have some insights on what's going on with the app, so I'll try to find a way to do this.

@fsiler
Copy link
Author

fsiler commented Nov 6, 2023

I did get this working, but annoyingly it involves NSSM. I'm using Chocolatey to install NSSM. Do you want me to prepare Powershell to fetch and install NSSM, or are you okay with a quick guide based on what I have now?

@burningalchemist
Copy link
Owner

Hey @fsiler, I think just a quick guide should be enough for starters. Feel free to open a PR and we'll discuss the details, I'm happy to assist as well. 👍

@burningalchemist
Copy link
Owner

It looks like the issue has been resolved. We can use NSSM to configure and manage the service in Windows, so I'll close this ticket for now.

Writing logs directly to the file or EventLog in Windows might be considered after the planned log library change.

@burningalchemist burningalchemist closed this as not planned Won't fix, can't repro, duplicate, stale Nov 14, 2023
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

No branches or pull requests

2 participants