-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Ability to change logging function #4482
Comments
Hi! I think this is indeed not currently possible, but we are open to suggestions on how we could improve this 👍 That being said, the logs captured by |
@darrachequesne Hi! Our use case is that sometimes, clients cannot connect - and since we cannot always know when people using the problematic clients connect, it would be useful to temporarily get logs like in #4397 written to a file until the problem is solved (or at least properly diagnosed). |
Here are some options:
import createDebug from 'debug';
createDebug.log = function customHandler() { ... }
const server = require('http').createServer();
const io = require('socket.io')(server);
import createDebug from 'debug';
createDebug.log = function customHandler() { ... }
const server = require('http').createServer();
const io = require('socket.io')(server, { debugLib: createDebug }); // custom
const io = require('socket.io')(server); // included with socket.io
import createDebug from 'debug';
createDebug.log = function customHandler() { ... }
const server = require('http').createServer();
const io = require('socket.io')(server);
io.debug = createDebug; Context: I was forced to think this through for metalsmith.js (but use case there is different perhaps, because users are expected to install many plugins also requiring debug, see https://github.com/metalsmith/metalsmith/blob/master/lib/debug.js for inspiration |
Is your feature request related to a problem? Please describe.
Our app uses winston to send logs to different targets, e.g. log files. However, the Logs of socket.io are sent directly to the console via
debug
, and therefore missing from our log files.Describe the solution you'd like
I'd like to be able to somewhere specify a function that should be called when a log is emitted, overriding the internal "console.log" call with my own logger.
Describe alternatives you've considered
While it seems that
debug
can specify a global logger override (e.g.import { debug } from "debug"; debug.log = (...args: any[]) => { console.log("x", args); };
), it appears that only applies to the current package. For example:debug_1.log = (...args) => { console.log("message from engine.io", args); };
by hand in node_modules/engine.io/build/server.js afterconst debug_1 = require("debug");
, all calls from engine.io use that log function, but socket.io:client messages are still using console.log.The text was updated successfully, but these errors were encountered: