I have a MaraDNS server and need to log all the IP's of DNS servers which query it. With logging verbosity turned up, it outputs this to stdout, but when I try to redirect stdout (and stderr) to a log file, it does'nt seem to capture it in real time and misses some of the output when writing to stdout. Any ideas?
If you're have a high query rate to your DNS server, it's possible that the storage medium you're using to store your logs is not sufficiently fast enough to keep up with your STDIO buffers. If, in the amount of time it takes to receive 100 queries, your disks are only fast enough that 90 queries can be written, then you're going to start dropping entries. Either they won't make it into your STDIO buffers at all, or you'll lose queued messages from the buffer.
If this is the case, and you have access to high performance storage, like an SSD, try putting your log on the SSD. If you don't have an SSD, you could try a compromise. Like any compromise, you do risk losing data, though.
Create a RAM based filesystem, and write your logs there. Have another job that periodically syncs or copies those logs to slower storage. You'll lose data if your server crashes, or reboots (possibly), but while things are running normally, you'll have a better chance of catching all those queries.