I've written a python program that acts as a server (tcp, kindof) and logs a ton of vital info on stdout (and file). The program runs on an ARM board with a small VGA dispay attached to it.
Now I want to display some information on the physical display of the board, while maintaining the logging on the tty where the program was launched.
Let us say I connect to the ARM board via SSH, and run the program on /dev/tty3.
I've managed to use ncurses to display things on /dev/tty1 (which is the physical display). Problem is, all the logging goes also to the pyhsical display.
To achieve this I've basically redirected stodut to /dev/tty1 with some piece of code found on SO:
NCURSES_TTY = '/dev/tty1'
with open(NCURSES_TTY, 'rb') as inf, open(NCURSES_TTY, 'wb') as outf:
os.dup2(inf.fileno(), 0)
os.dup2(outf.fileno(), 1)
os.dup2(outf.fileno(), 2)
os.environ['TERM'] = 'linux'
logging.debug("Starting server..")
But this, of course, redirects all output. Any idea of how to split ncurses and plain python logging to separate TTYs?
Ok, solved.. it was pretty simple..
1) detect current tty
2) set up python loggin to log to detected tty
3) trick stdout and err to go to desired tty
4) import ncurses and do logging
That's it. The power of Unix (tested on OSX)..