Skip to content

Commit

Permalink
feat: exposes methods to control wssv
Browse files Browse the repository at this point in the history
  • Loading branch information
ndorin committed Nov 6, 2023
1 parent baa54e4 commit 0266edd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/Pepperdash Core/Logging/Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ static Debug()

// Instantiate the root logger
_logger = new LoggerConfiguration()
.WriteTo.Logger(lc => lc
.WriteTo.Console(levelSwitch: _consoleLoggingLevelSwitch))
.WriteTo.Sink(new DebugWebsocketSink(), levelSwitch: _websocketLoggingLevelSwitch)
//.WriteTo.Logger(lc => lc
//.WriteTo.Console(levelSwitch: _consoleLoggingLevelSwitch))
.WriteTo.Sink(new DebugWebsocketSink(), levelSwitch: _websocketLoggingLevelSwitch)
.WriteTo.File(@"\user\debug\global-log-{Date}.txt"
, rollingInterval: RollingInterval.Day
, restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Debug)
Expand Down Expand Up @@ -218,7 +218,7 @@ static void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventTyp

if (programEventType == eProgramStatusEventType.Stopping)
{
//_logger.CloseAndFlush();
Log.CloseAndFlush();

if (_saveTimer != null)
{
Expand Down Expand Up @@ -370,9 +370,12 @@ public static void SetDebugFilterFromConsole(string items)
/// <param name="level"> Valid values 0 (no debug), 1 (critical), 2 (all messages)</param>
public static void SetDebugLevel(int level)
{
if (level <= 2)
_consoleLoggingLevelSwitch.MinimumLevel = (LogEventLevel)level;

if (level <= 5)
{
Level = level;

_contexts.GetOrCreateItem("DEFAULT").Level = level;
SaveMemoryOnTimeout();

Expand Down
19 changes: 16 additions & 3 deletions src/Pepperdash Core/Logging/DebugWebsocketSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,33 @@ namespace PepperDash.Core
{
public class DebugWebsocketSink : ILogEventSink
{
public WebSocketServer WSSV { get; private set; }
private WebSocketServer _wssv { get; private set; }

private readonly IFormatProvider _formatProvider;

public DebugWebsocketSink()
{
WSSV = new WebSocketServer();
_wssv = new WebSocketServer();

}

public void Emit(LogEvent logEvent)
{
if (_wssv == null || !_wssv.IsListening) return;

var message = logEvent.RenderMessage(_formatProvider);
WSSV.WebSocketServices.Broadcast(message);
_wssv.WebSocketServices.Broadcast(message);
}

public void StartServerAndSetPort(int port)
{
_wssv = new WebSocketServer(port);
_wssv.Start();
}

public void StopServer()
{
_wssv.Stop();
}
}

Expand Down

0 comments on commit 0266edd

Please sign in to comment.