Increase chunk size to send fewer messages.

Fixed logging lock (causes color issues in parallel env)
This commit is contained in:
Michael Chen 2022-01-18 10:43:15 +01:00
parent f912b9db8f
commit a55af9f667
No known key found for this signature in database
GPG Key ID: 1CBC7AA5671437BB
2 changed files with 19 additions and 15 deletions

View File

@ -1,9 +1,12 @@
local secretToken = "$TOKEN" local secretToken = "$TOKEN"
local connectionUri = "$HOST" local connectionUri = "$HOST"
local waitSeconds = 5 local waitSeconds = 5
-- https://github.com/cc-tweaked/CC-Tweaked/blob/9cf70b10effeeed23e0e9c537bbbe0b2ff0d1a0f/src/main/java/dan200/computercraft/core/apis/http/options/AddressRule.java#L29
-- Chunk size must be less than packet size (type reply, success, chunkids, content: chunk) 16 kb for buffer
local maxMessageSize = (128 - 16) * 1024
local function chunkString(value, chunkSize) local function chunkString(value, chunkSize)
if not chunkSize then chunkSize = 10000 end if not chunkSize then chunkSize = maxMessageSize end
local length = value:len() local length = value:len()
local total = math.ceil(length / chunkSize) local total = math.ceil(length / chunkSize)
local chunks = {} local chunks = {}

View File

@ -274,21 +274,22 @@ public class Program : IDisposable, ICommandHandler<ResponseType>, IUserRoleMana
} }
public static void Log(LogMessage msg) { public static void Log(LogMessage msg) {
var oldColor = Console.ForegroundColor; lock (LogLock) {
try { var oldColor = Console.ForegroundColor;
Console.ForegroundColor = msg.Severity switch { try {
LogSeverity.Critical => ConsoleColor.Magenta, Console.ForegroundColor = msg.Severity switch {
LogSeverity.Error => ConsoleColor.Red, LogSeverity.Critical => ConsoleColor.Magenta,
LogSeverity.Warning => ConsoleColor.Yellow, LogSeverity.Error => ConsoleColor.Red,
LogSeverity.Info => ConsoleColor.White, LogSeverity.Warning => ConsoleColor.Yellow,
LogSeverity.Verbose => ConsoleColor.Blue, LogSeverity.Info => ConsoleColor.White,
LogSeverity.Debug => ConsoleColor.DarkBlue, LogSeverity.Verbose => ConsoleColor.Blue,
_ => ConsoleColor.Cyan, LogSeverity.Debug => ConsoleColor.DarkBlue,
}; _ => ConsoleColor.Cyan,
lock (LogLock) };
Console.WriteLine(msg.ToString()); Console.WriteLine(msg.ToString());
} finally { } finally {
Console.ForegroundColor = oldColor; Console.ForegroundColor = oldColor;
}
} }
} }