From 92d73a6f013c0b6d7867b1dfd19c8d009ffbe374 Mon Sep 17 00:00:00 2001 From: Joe Rayhawk Date: Sat, 19 Nov 2022 21:50:15 -0800 Subject: All debug statements to STDERR instead of STDOUT --- src/obswebsocket.cr | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/obswebsocket.cr b/src/obswebsocket.cr index df84cba..da188bc 100644 --- a/src/obswebsocket.cr +++ b/src/obswebsocket.cr @@ -159,9 +159,9 @@ module OBSWebSocket if msgtuple[1] == "clear queue" queue.each do | msg | reschan = msg[0] - print( "SENT: " ) + STDERR.print( "SENT: " ) json = JSON.parse(msg[1]) - pp json + STDERR.print( json.pretty_inspect ) if reschan openrequests[ json["d"]["requestId"].as_s ] = reschan end @@ -176,37 +176,36 @@ module OBSWebSocket end elsif @negotiated reschan = msgtuple[0] - print "SENT: " + STDERR.print( "SENT: " ) json = JSON.parse( msgtuple[1] ) - pp json + STDERR.print( json.pretty_inspect ) if reschan openrequests[ json["d"]["requestId"].as_s ] = reschan end @obs_pubsub.send( msgtuple[1] ) elsif JSON.parse( msgtuple[1] )["op"].as_i64 == 1 - print "SENT: " + STDERR.print( "SENT: " ) json = JSON.parse( msgtuple[1] ) - pp json + STDERR.print( json.pretty_inspect ) @obs_pubsub.send( msgtuple[1] ) else - print "QUEUED: " - pp msgtuple[1] + STDERR.print( "QUEUED: " ) + STDERR.print( msgtuple[1].pretty_inspect ) queue.push( { msgtuple[0], msgtuple[1] } ) end end end @obs_pubsub.on_message do | message | json = JSON.parse( message ) - print( "RECEIVED: ") - print( json.to_pretty_json ) - print( "\n") + STDERR.print( "RECEIVED: ") + STDERR.print( json.to_pretty_json ) + STDERR.print( "\n") if json["error"]? - puts json["error"] + STDERR.puts( json["error"] ) next end case json["op"].as_i64 when 0 # hello - hello = JSON.build do |j| j.object do j.field "op", 1 @@ -324,7 +323,7 @@ module OBSWebSocket when "SourceFilterEnableStateChanged" edata = json["d"]["eventData"] if ( source = @sources[edata["sourceName"].as_s]? ) - puts "SourceFilterEnableStateChanged: #{source.class}" + STDERR.puts( "SourceFilterEnableStateChanged: #{source.class}" ) source.filters[edata["filterName"].as_s].enabledcache( edata["filterEnabled"].as_bool ) else raise SourceMissingException.new( "SourceFilterEnableStateChanged: missing source #{ edata["sourceName"].as_s}" ) @@ -350,7 +349,7 @@ module OBSWebSocket spawn do d = json["d"] if d["requestStatus"]["result"].as_bool == false - puts "ERROR: #{d["requestType"].as_s} #{d["requestStatus"]["code"].as_i64}: #{d["requestStatus"]["comment"].as_s}" + STDERR.puts( "ERROR: #{d["requestType"].as_s} #{d["requestStatus"]["code"].as_i64}: #{d["requestStatus"]["comment"].as_s}" ) end if openrequests[ d["requestId"].as_s ]? channel = openrequests[ d["requestId"].as_s ] @@ -358,7 +357,7 @@ module OBSWebSocket channel.close openrequests.delete( d["requestId"].as_s ) else - puts "PUBSUBREAD THREAD: no response channel known for requestId: #{ d["requestId"].as_s }" + STDERR.puts( "PUBSUBREAD THREAD: no response channel known for requestId: #{ d["requestId"].as_s }" ) end end Fiber.yield @@ -367,14 +366,14 @@ module OBSWebSocket @obs_pubsub.run rescue ex : Socket::ConnectError | IO::Error if @connecterror < 3 - print ex.message + STDERR.print( ex.message ) @connecterror += 1 - ( @connecterror == 3 ) && ( @connecterror += 1 ) && print ". Suppressing further repeat errors." - print "\n" + ( @connecterror == 3 ) && ( @connecterror += 1 ) && STDERR.print( ". Suppressing further repeat errors." ) + STDERR.print( "\n" ) end rescue ex - pp ex - pp ex.backtrace? + STDERR.print( ex.pretty_inspect ) + STDERR.print( ex.backtrace?.pretty_inspect ) ensure @closed || @obs_pubsub.close @negotiated = false @@ -414,8 +413,8 @@ module OBSWebSocket @reqchan.send( { reschan, OBSWebSocket.req( "GetOutputList", UUID.random.to_s ) } ) d = reschan.receive if ( rdata = d["responseData"]? ) - print "OUTPUTS THREAD: " - pp rdata + STDERR.print( "OUTPUTS THREAD: " ) + STDERR.print( rdata.pretty_inspect ) rdata["outputs"].as_a.each do | output | @outputs[output["outputName"].as_s] = OBSWebSocket::Output.new( @reqchan, output ) end @@ -592,7 +591,7 @@ module OBSWebSocket return true end def invalidate - puts "SCENELIST THREAD: scenes invalidated" + STDERR.puts( "SCENELIST THREAD: scenes invalidated" ) @scenes_by_index = Array(String).new @scenes = Hash(String, OBSWebSocket::Scene).new @program = String.new -- cgit v1.2.3