Skip to content

Commit

Permalink
Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
lcodes committed Sep 29, 2024
1 parent 70d4a92 commit e47a845
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/SpacetimeDBClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ HashSet<byte[]> GetInsertHashSet(System.Type tableType, int tableSize)
var table = clientDB.GetTable(tableName);
if (table == null)
{
Logger.LogError($"Unknown table name: {tableName}");
Log.Error($"Unknown table name: {tableName}");
continue;
}

if (update.Deletes.Count != 0)
{
Logger.LogWarning("Non-insert during a subscription update!");
Log.Warn("Non-insert during a subscription update!");
}

var hashSet = GetInsertHashSet(table.ClientTableType, initialSubscription.DatabaseUpdate.Tables.Count);
Expand All @@ -276,7 +276,7 @@ HashSet<byte[]> GetInsertHashSet(System.Type tableType, int tableSize)
break;

case EncodedValue.Text(var txt):
Logger.LogWarning("JavaScript messages are unsupported.");
Log.Warn("JavaScript messages are unsupported.");
break;
}
}
Expand All @@ -300,7 +300,7 @@ HashSet<byte[]> GetInsertHashSet(System.Type tableType, int tableSize)
ToReducer(transactionUpdate));
}
catch (Exception e) {
Logger.LogException(e);
Log.Exception(e);
}

if (transactionUpdate.Status is UpdateStatus.Committed(var committed))
Expand All @@ -312,7 +312,7 @@ HashSet<byte[]> GetInsertHashSet(System.Type tableType, int tableSize)
var tableName = update.TableName;
var table = clientDB.GetTable(tableName);
if (table == null) {
Logger.LogError($"Unknown table name: {tableName}");
Log.Error($"Unknown table name: {tableName}");
continue;
}

Expand All @@ -326,7 +326,7 @@ HashSet<byte[]> GetInsertHashSet(System.Type tableType, int tableSize)

if (primaryKeyChanges.TryGetValue(key, out var oldOp)) {
if ((op.insert is not null && oldOp.insert is not null) || (op.delete is not null && oldOp.delete is not null)) {
Logger.LogWarning($"Update with the same primary key was applied multiple times! tableName={tableName}");
Log.Warn($"Update with the same primary key was applied multiple times! tableName={tableName}");
// TODO(jdetter): Is this a correctable error? This would be a major error on the
// SpacetimeDB side.
continue;
Expand Down Expand Up @@ -356,7 +356,7 @@ HashSet<byte[]> GetInsertHashSet(System.Type tableType, int tableSize)

if (primaryKeyChanges.TryGetValue(key, out var oldOp)) {
if ((op.insert is not null && oldOp.insert is not null) || (op.delete is not null && oldOp.delete is not null)) {
Logger.LogWarning($"Update with the same primary key was applied multiple times! tableName={tableName}");
Log.Warn($"Update with the same primary key was applied multiple times! tableName={tableName}");
// TODO(jdetter): Is this a correctable error? This would be a major error on the
// SpacetimeDB side.
continue;
Expand Down Expand Up @@ -389,7 +389,7 @@ HashSet<byte[]> GetInsertHashSet(System.Type tableType, int tableSize)

if (!waitingOneOffQueries.Remove(messageId, out var resultSource))
{
Logger.LogError($"Response to unknown one-off-query: {messageId}");
Log.Error($"Response to unknown one-off-query: {messageId}");
break;
}

Expand Down Expand Up @@ -463,7 +463,7 @@ public void Connect(string? token, string uri, string addressOrName)
uri = $"ws://{uri}";
}

Logger.Log($"SpacetimeDBClient: Connecting to {uri} {addressOrName}");
Log.Info($"SpacetimeDBClient: Connecting to {uri} {addressOrName}");
Task.Run(async () =>
{
try
Expand All @@ -474,11 +474,11 @@ public void Connect(string? token, string uri, string addressOrName)
{
if (connectionClosed)
{
Logger.Log("Connection closed gracefully.");
Log.Info("Connection closed gracefully.");
return;
}

Logger.LogException(e);
Log.Exception(e);
}
});
}
Expand Down Expand Up @@ -562,7 +562,7 @@ private void OnMessageProcessCompleteUpdate(IEventContext eventContext, List<DbO
}
catch (Exception e)
{
Logger.LogException(e);
Log.Exception(e);
}
}
}
Expand All @@ -589,7 +589,7 @@ private void OnMessageProcessComplete(PreProcessedMessage preProcessed)
}
catch (Exception e)
{
Logger.LogException(e);
Log.Exception(e);
}
break;

Expand All @@ -605,7 +605,7 @@ private void OnMessageProcessComplete(PreProcessedMessage preProcessed)
var requestId = transactionUpdate.ReducerCall.RequestId;
if (!stats.ReducerRequestTracker.FinishTrackingRequest(requestId))
{
Logger.LogWarning($"Failed to finish tracking reducer request: {requestId}");
Log.Warn($"Failed to finish tracking reducer request: {requestId}");
}
}

Expand All @@ -623,7 +623,7 @@ private void OnMessageProcessComplete(PreProcessedMessage preProcessed)
}
catch (Exception e)
{
Logger.LogException(e);
Log.Exception(e);
}

var reducerFound = false;
Expand All @@ -633,7 +633,7 @@ private void OnMessageProcessComplete(PreProcessedMessage preProcessed)
}
catch (Exception e)
{
Logger.LogException(e);
Log.Exception(e);
}

if (!reducerFound && transactionUpdate.Status is UpdateStatus.Failed(var failed))
Expand All @@ -644,7 +644,7 @@ private void OnMessageProcessComplete(PreProcessedMessage preProcessed)
}
catch (Exception e)
{
Logger.LogException(e);
Log.Exception(e);
}
}
break;
Expand All @@ -657,7 +657,7 @@ private void OnMessageProcessComplete(PreProcessedMessage preProcessed)
}
catch (Exception e)
{
Logger.LogException(e);
Log.Exception(e);
}
break;

Expand All @@ -668,7 +668,7 @@ private void OnMessageProcessComplete(PreProcessedMessage preProcessed)
}
catch (Exception e)
{
Logger.LogException(e);
Log.Exception(e);
}
break;

Expand All @@ -686,7 +686,7 @@ public void InternalCallReducer<T>(T args)
{
if (!webSocket.IsConnected)
{
Logger.LogError("Cannot call reducer, not connected to server!");
Log.Error("Cannot call reducer, not connected to server!");
return;
}

Expand All @@ -704,7 +704,7 @@ public void Subscribe(List<string> queries)
{
if (!webSocket.IsConnected)
{
Logger.LogError("Cannot subscribe, not connected to server!");
Log.Error("Cannot subscribe, not connected to server!");
return;
}

Expand Down Expand Up @@ -741,13 +741,13 @@ public async Task<T[]> OneOffQuery<T>(string query)

if (!stats.OneOffRequestTracker.FinishTrackingRequest(requestId))
{
Logger.LogWarning($"Failed to finish tracking one off request: {requestId}");
Log.Warn($"Failed to finish tracking one off request: {requestId}");
}

T[] LogAndThrow(string error)
{
error = $"While processing one-off-query `{queryString}`, ID {messageId}: {error}";
Logger.LogError(error);
Log.Error(error);
throw new Exception(error);
}

Expand Down

0 comments on commit e47a845

Please sign in to comment.