socket.io
socket.io copied to clipboard
Dynamic `DEBUG` env variable
Hello we can use DEBUG only during start application, but I need change it on the fly (during running application)
Can I change DEBUG env variable via code?
Every module has separated version of debug instance. I think will be better to have only one instance and expose enable/disable
We can control debug on the fly (don't need to restart application, it isn't possible in my situation and enable/disable debug on the fly will be nice approach)
Any advices @rauchg?
Right before creating the server, you can import the debug package and call debug.enable("socket.io*,engine,socket.io*")
debug logs can indeed be enabled on the fly:
import { Server } from "socket.io";
import debugPackage from "debug";
const io = new Server(3000);
io.on("connection", (socket) => {
console.log(`connect ${socket.id}`);
debugPackage.disable("socket*");
});
debugPackage.enable("socket*");
prints
socket.io:server incoming connection with id 6t5_AorgjnvnZLzLAAAA +0ms
socket.io-parser decoded 0 as {"type":0,"nsp":"/"} +0ms
socket.io:client connecting to namespace / +0ms
socket.io:namespace adding socket to nsp / +0ms
socket.io:socket socket connected - writing packet +0ms
socket.io:socket join room tYHxCafjaCT8hFpfAAAB +0ms
socket.io-parser encoding packet {"type":0,"data":{"sid":"tYHxCafjaCT8hFpfAAAB"},"nsp":"/"} +2ms
socket.io-parser encoded {"type":0,"data":{"sid":"tYHxCafjaCT8hFpfAAAB"},"nsp":"/"} as 0{"sid":"tYHxCafjaCT8hFpfAAAB"} +0ms
connect tYHxCafjaCT8hFpfAAAB
// and then nothing
Please reopen if needed.