Skip to content

Commit 1e6cdd7

Browse files
committed
add some additional logging
1 parent c0ab8ed commit 1e6cdd7

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ If you have [nox](https://github.com/theacodes/nox) you can run the following.
3838
```
3939
> nox -s run
4040
```
41-
Nox takes care of setting up a virtual environment and running the right command for you.
41+
Nox takes care of setting up a virtual environment and running the right command for you. You can pass arguments to the server like this
42+
```
43+
> nox -s run -- --debug
44+
```
4245

4346
If you don't have nox, you can run the following from inside a virtual environment.
4447
```
4548
> pip install -r requirements.txt
4649
> python -m pyxtermjs
50+
> python -m pyxtermjs --debug
4751
```
4852

4953
### Install

pyxtermjs/app.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import fcntl
1212
import shlex
1313
import logging
14+
import sys
1415

1516
logging.getLogger("werkzeug").setLevel(logging.ERROR)
1617

@@ -20,10 +21,11 @@
2021
app.config["SECRET_KEY"] = "secret!"
2122
app.config["fd"] = None
2223
app.config["child_pid"] = None
23-
socketio = SocketIO(app, logger=False, engineio_logger=False)
24+
socketio = SocketIO(app)
2425

2526

2627
def set_winsize(fd, row, col, xpix=0, ypix=0):
28+
logging.debug("setting window size with termios")
2729
winsize = struct.pack("HHHH", row, col, xpix, ypix)
2830
fcntl.ioctl(fd, termios.TIOCSWINSZ, winsize)
2931

@@ -51,20 +53,21 @@ def pty_input(data):
5153
terminal.
5254
"""
5355
if app.config["fd"]:
54-
# print("writing to pty: %s" % data["input"])
56+
logging.debug("received input from browser: %s" % data["input"])
5557
os.write(app.config["fd"], data["input"].encode())
5658

5759

5860
@socketio.on("resize", namespace="/pty")
5961
def resize(data):
6062
if app.config["fd"]:
63+
logging.debug(f"Resizing window to {data['rows']}x{data['cols']}")
6164
set_winsize(app.config["fd"], data["rows"], data["cols"])
6265

6366

6467
@socketio.on("connect", namespace="/pty")
6568
def connect():
6669
"""new client connected"""
67-
70+
logging.info("new client connected")
6871
if app.config["child_pid"]:
6972
# already started child process, don't start another
7073
return
@@ -83,13 +86,13 @@ def connect():
8386
app.config["child_pid"] = child_pid
8487
set_winsize(fd, 50, 50)
8588
cmd = " ".join(shlex.quote(c) for c in app.config["cmd"])
86-
print("child pid is", child_pid)
87-
print(
89+
logging.info("child pid is " + child_pid)
90+
logging.info(
8891
f"starting background task with command `{cmd}` to continously read "
8992
"and forward pty output to client"
9093
)
9194
socketio.start_background_task(target=read_and_forward_pty_output)
92-
print("task started")
95+
logging.info("task started")
9396

9497

9598
def main():
@@ -120,8 +123,16 @@ def main():
120123
if args.version:
121124
print(__version__)
122125
exit(0)
123-
print(f"serving on http://127.0.0.1:{args.port}")
124126
app.config["cmd"] = [args.command] + shlex.split(args.cmd_args)
127+
green = "\033[92m"
128+
end = "\033[0m"
129+
log_format = green + "pyxtermjs > " + end + "%(levelname)s (%(funcName)s:%(lineno)s) %(message)s"
130+
logging.basicConfig(
131+
format=log_format,
132+
stream=sys.stdout,
133+
level=logging.DEBUG if args.debug else logging.INFO,
134+
)
135+
logging.info(f"serving on http://127.0.0.1:{args.port}")
125136
socketio.run(app, debug=args.debug, port=args.port, host=args.host)
126137

127138

pyxtermjs/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@
5353
term.writeln("Welcome to pyxterm.js!");
5454
term.writeln("https://github.com/cs01/pyxterm.js");
5555
term.onData((data) => {
56-
console.log("new input data", data);
56+
console.log("key pressed in browser:", data);
5757
socket.emit("pty-input", { input: data });
5858
});
5959

6060
const socket = io.connect("/pty");
6161
const status = document.getElementById("status");
6262

6363
socket.on("pty-output", function (data) {
64-
console.log("new output received from server", data);
64+
console.log("new output received from server:", data.output);
6565
term.write(data.output);
6666
});
6767

0 commit comments

Comments
 (0)