-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Implement console logs
- Loading branch information
Showing
21 changed files
with
472 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Net; | ||
using System.Net.Sockets; | ||
using System.Text; | ||
using System.Threading; | ||
|
||
namespace Winch.Logging | ||
{ | ||
public class LogSocket | ||
{ | ||
private Socket _socket; | ||
private readonly int _port; | ||
private readonly Logger _logger; | ||
|
||
public LogSocket(Logger logger, int port) | ||
{ | ||
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); | ||
_port = port; | ||
_logger = logger; | ||
} | ||
|
||
public void WriteToSocket(LogMessage logMessage) | ||
{ | ||
if (_socket == null) | ||
{ | ||
return; | ||
} | ||
|
||
if (!_socket.Connected) | ||
{ | ||
var endPoint = new IPEndPoint(IPAddress.Parse(Constants.IP), _port); | ||
try | ||
{ | ||
_socket?.Connect(endPoint); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_socket = null; | ||
_logger.Error($"Could not connect to console at {Constants.IP}:{_port} - {ex}"); | ||
} | ||
} | ||
|
||
try | ||
{ | ||
_socket?.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(logMessage))); | ||
} | ||
catch (SocketException) { } | ||
} | ||
|
||
public void Close() | ||
{ | ||
Thread.Sleep(TimeSpan.FromSeconds(1)); | ||
_socket?.Close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
"Name": "Winch", | ||
"Author": "Hacktix", | ||
"ModGUID": "hacktix.winch", | ||
"Version": "0.3.0" | ||
"Version": "0.3.1" | ||
} |
1 change: 1 addition & 0 deletions
1
Winch/Config/DefaultConfig.json → WinchCommon/Config/DefaultConfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Winch; | ||
|
||
public static class Constants | ||
{ | ||
public const string IP = "127.0.0.1"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Winch; | ||
|
||
public enum LogLevel | ||
{ | ||
UNITY = 0, DEBUG = 1, INFO = 2, WARN = 3, ERROR = 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Newtonsoft.Json; | ||
using WinchCommon; | ||
|
||
namespace Winch.Logging | ||
{ | ||
public class LogMessage | ||
{ | ||
[JsonProperty("source")] | ||
public string Source { get; set; } | ||
|
||
[JsonProperty("level")] | ||
public LogLevel Level { get; set; } | ||
|
||
[JsonProperty("message")] | ||
public string Message { get; set; } | ||
} | ||
} |
Oops, something went wrong.