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

stderr_stream to file not work #1149

Open
syncupasia opened this issue Sep 29, 2020 · 4 comments
Open

stderr_stream to file not work #1149

syncupasia opened this issue Sep 29, 2020 · 4 comments
Assignees
Labels
need more info Issue requires more information from poster question

Comments

@syncupasia
Copy link

Hi I've the following config in circus.ini and I have a line in the php script that will result a fatal error during execution but it just created the file and it's empty. What's the issue or anything I set up wrong? I did ps aux command I saw the php script did restart with a new time so it failed with fatal error and started again but just empty log.

[watcher:test]
cmd=/home/php/test.php
numprocesses=1
stderr_stream.class = FileStream
stderr_stream.filename = /tmp/test.err
stderr_stream.refresh_time = 0.3
stderr_stream.max_bytes = 1073741824
stderr_stream.backup_count = 5

@biozz biozz self-assigned this Oct 1, 2020
@biozz biozz added the question label Oct 1, 2020
@biozz
Copy link
Contributor

biozz commented Oct 1, 2020

Hi @syncupasia.

I was able to reproduce this on my machine and I think the issue is related to your script. If you try running example/example2.ini from the repo, you will see that the logs are working. But if you change stdout to stderr there would be just the file and no logs. That is because the script doesn't output to stderr.

My guess would be that your script outputs to the different output. Please try changing stderr to stdout and see if that works.

@biozz biozz added the need more info Issue requires more information from poster label Oct 1, 2020
@syncupasia
Copy link
Author

Hi I actually tried stdout_stream first but it's the same where it just created empty log file. I think the issue is I want to log unexpected fatal error. If I do try and catch exception then I can write something to stdout. But in this case I want to log any php fatal error so I tried stderr_stream and thought any fatal error will be in the stderr_stream.filename?

@biozz
Copy link
Contributor

biozz commented Oct 6, 2020

Than the only thing left is for you to check how you handle fatal errors. As far as I understand, fatal errors cause programs to exit, so you have to catch them in a special way.

Unfortunately handling of fatal errors in php is out of circus' scope, I don't have any other suggestions. Logging to file works as expected from what I see.

@nicovillanueva
Copy link

Hi @biozz ,

I think I'm experiencing the same issue as @syncupasia , but in this case when using the API?

I can reproduce it by running this snippet:

from circus.watcher import Watcher
import time

stdoutcfg = {
		"class": "circus.stream.FileStream",
                "filename": f"/home/user/watchertest.log",
                "max_bytes": 52428800,
                "backup_count": 5
            }
stderrcfg = {
		"class": "circus.stream.FileStream",
                "filename": f"/home/user/watchertest.err",
                "max_bytes": 52428800,
                "backup_count": 5
            }

w = Watcher(
	name='watchertest',
	cmd='python3',
	args='/home/user/printer.py',
	stdout_stream=stdoutcfg,
	stderr_stream=stderrcfg,
	stop_children=True
)
print(w.status())
w.start()
print(w.status())
print(w.info())
time.sleep(10)
print(w.status())
print(w.info())
w.stop()
print(w.status())
print(w.info())

The "printer.py" is just a script that prints to both stdout and stderr:

import sys
import time

while True:
	print("hi - stdout", file=sys.stdout, flush=True)
	print("hi - stderr", file=sys.stderr, flush=True)
	time.sleep(0.5)

What happens is that the watchertest.log and .err files are created but remain empty (0 bytes). Also, and not sure if relevant, the .status() call always returns "starting". When is it that it moves into "started"?

This is reproducible in both Circus 0.16.1 and in 0.17.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need more info Issue requires more information from poster question
Projects
None yet
Development

No branches or pull requests

3 participants