Condividi tramite


Raccogliere i log in Web PubSub per Socket.IO

Come quando si ospita automaticamente la libreria di Socket.IO, è possibile raccogliere i log sia sul lato server che sul lato client quando si usa Web PubSub per Socket.IO.

Lato server

Il lato server include due utilità che forniscono funzionalità di debug:

  • DEBUG, che la libreria di estensione e la libreria di Socket.IO fornita da Web PubSub usano per determinate registrazioni.
  • @azure/logger, che fornisce la registrazione di rete di livello inferiore. In modo pratico, consente anche di impostare un livello di log.

DEBUG Utilità JavaScript

Registrare tutte le informazioni di debug

DEBUG=* node yourfile.js

Registrare le informazioni di debug da pacchetti specifici

# Logs debug information from the "socket.io" package
DEBUG=socket.io:* node yourfile.js

# Logs debug information from the "engine.io" package
DEBUG=engine:* node yourfile.js

# Logs debug information from the extension library "wps-sio-ext" provided by Web PubSub
DEBUG=wps-sio-ext:* node yourfile.js

# Logs debug information from multiple packages
DEBUG=engine:*,socket.io:*,wps-sio-ext:* node yourfile.js

Screenshot of logging information from DEBUG JavaScript utility

@azure/logger Utilità

È possibile abilitare la registrazione dall'utilità @azure/logger per ottenere informazioni di rete di livello inferiore impostando la variabile AZURE_LOG_LEVELdi ambiente .

AZURE_LOG_LEVEL=verbose node yourfile.js

Azure_LOG_LEVEL ha quattro livelli: verbose, info, warninge error.

Screenshot of logging information from the logger utility.

Lato client

L'uso di Web PubSub per Socket.IO non modifica la modalità di debug della libreria di Socket.IO. Fare riferimento alla documentazione della libreria Socket.IO.

Eseguire il debug del client Socket.IO in Node

# Logs all debug information
DEBUG=* node yourfile.js

# Logs debug information from the "socket.io-client" package 
DEBUG=socket.io-client:* node yourfile.js

# Logs debug information from the "engine.io-client" package 
DEBUG=engine.io-client:* node yourfile.js

# Logs debug information from multiple packages 
DEBUG=socket.io-client:*,engine.io-client* node yourfile.js

Eseguire il debug del client Socket.IO in un browser

In un browser usare localStorage.debug = '<scope>'.

# Logs all debug information
localStorage.debug = '*';

# Logs debug information from the "socket.io-client" package 
localStorage.debug = 'socket.io-client';