Skip to content

Commit

Permalink
Revert logger name
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-lf committed Dec 7, 2024
1 parent 7d4c4ae commit 9038aaa
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 77 deletions.
32 changes: 16 additions & 16 deletions Snowflake.Data/Client/SnowflakeDbCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public class SnowflakeDbCommand : DbCommand

private SnowflakeDbParameterCollection parameterCollection;

private SFLogger _logger = SFLoggerFactory.GetLogger<SnowflakeDbCommand>();
private SFLogger logger = SFLoggerFactory.GetLogger<SnowflakeDbCommand>();

private readonly QueryResultsAwaiter _queryResultsAwaiter = QueryResultsAwaiter.Instance;

public SnowflakeDbCommand()
{
_logger.Debug("Constructing SnowflakeDbCommand class");
logger.Debug("Constructing SnowflakeDbCommand class");
// by default, no query timeout
this.CommandTimeout = 0;
parameterCollection = new SnowflakeDbParameterCollection();
Expand Down Expand Up @@ -165,7 +165,7 @@ public override void Cancel()

public override int ExecuteNonQuery()
{
_logger.Debug($"ExecuteNonQuery");
logger.Debug($"ExecuteNonQuery");
SFBaseResultSet resultSet = ExecuteInternal();
long total = 0;
do
Expand All @@ -190,7 +190,7 @@ public override int ExecuteNonQuery()

public override async Task<int> ExecuteNonQueryAsync(CancellationToken cancellationToken)
{
_logger.Debug($"ExecuteNonQueryAsync");
logger.Debug($"ExecuteNonQueryAsync");
cancellationToken.ThrowIfCancellationRequested();

var resultSet = await ExecuteInternalAsync(cancellationToken).ConfigureAwait(false);
Expand All @@ -217,7 +217,7 @@ public override async Task<int> ExecuteNonQueryAsync(CancellationToken cancellat

public override object ExecuteScalar()
{
_logger.Debug($"ExecuteScalar");
logger.Debug($"ExecuteScalar");
SFBaseResultSet resultSet = ExecuteInternal();

if(resultSet.Next())
Expand All @@ -228,7 +228,7 @@ public override object ExecuteScalar()

public override async Task<object> ExecuteScalarAsync(CancellationToken cancellationToken)
{
_logger.Debug($"ExecuteScalarAsync");
logger.Debug($"ExecuteScalarAsync");
cancellationToken.ThrowIfCancellationRequested();

var result = await ExecuteInternalAsync(cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -263,22 +263,22 @@ protected override DbParameter CreateDbParameter()

protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
{
_logger.Debug($"ExecuteDbDataReader");
logger.Debug($"ExecuteDbDataReader");
SFBaseResultSet resultSet = ExecuteInternal();
return new SnowflakeDbDataReader(this, resultSet);
}

protected override async Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
{
_logger.Debug($"ExecuteDbDataReaderAsync");
logger.Debug($"ExecuteDbDataReaderAsync");
try
{
var result = await ExecuteInternalAsync(cancellationToken).ConfigureAwait(false);
return new SnowflakeDbDataReader(this, result);
}
catch (Exception ex)
{
_logger.Error("The command failed to execute.", ex);
logger.Error("The command failed to execute.", ex);
throw;
}
}
Expand All @@ -290,7 +290,7 @@ protected override async Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBeha
/// <returns>The query id.</returns>
public string ExecuteInAsyncMode()
{
_logger.Debug($"ExecuteInAsyncMode");
logger.Debug($"ExecuteInAsyncMode");
SFBaseResultSet resultSet = ExecuteInternal(asyncExec: true);
return resultSet.queryId;
}
Expand All @@ -303,7 +303,7 @@ public string ExecuteInAsyncMode()
/// <returns>The query id.</returns>
public async Task<string> ExecuteAsyncInAsyncMode(CancellationToken cancellationToken)
{
_logger.Debug($"ExecuteAsyncInAsyncMode");
logger.Debug($"ExecuteAsyncInAsyncMode");
var resultSet = await ExecuteInternalAsync(cancellationToken, asyncExec: true).ConfigureAwait(false);
return resultSet.queryId;
}
Expand All @@ -315,7 +315,7 @@ public async Task<string> ExecuteAsyncInAsyncMode(CancellationToken cancellation
/// <returns>The query status.</returns>
public QueryStatus GetQueryStatus(string queryId)
{
_logger.Debug($"GetQueryStatus");
logger.Debug($"GetQueryStatus");
return _queryResultsAwaiter.GetQueryStatus(connection, queryId);
}

Expand All @@ -327,7 +327,7 @@ public QueryStatus GetQueryStatus(string queryId)
/// <returns>The query status.</returns>
public async Task<QueryStatus> GetQueryStatusAsync(string queryId, CancellationToken cancellationToken)
{
_logger.Debug($"GetQueryStatusAsync");
logger.Debug($"GetQueryStatusAsync");
return await _queryResultsAwaiter.GetQueryStatusAsync(connection, queryId, cancellationToken);
}

Expand All @@ -338,7 +338,7 @@ public async Task<QueryStatus> GetQueryStatusAsync(string queryId, CancellationT
/// <returns>The query results.</returns>
public DbDataReader GetResultsFromQueryId(string queryId)
{
_logger.Debug($"GetResultsFromQueryId");
logger.Debug($"GetResultsFromQueryId");

Task task = _queryResultsAwaiter.RetryUntilQueryResultIsAvailable(connection, queryId, CancellationToken.None, false);
task.Wait();
Expand All @@ -356,7 +356,7 @@ public DbDataReader GetResultsFromQueryId(string queryId)
/// <returns>The query results.</returns>
public async Task<DbDataReader> GetResultsFromQueryIdAsync(string queryId, CancellationToken cancellationToken)
{
_logger.Debug($"GetResultsFromQueryIdAsync");
logger.Debug($"GetResultsFromQueryIdAsync");

await _queryResultsAwaiter.RetryUntilQueryResultIsAvailable(connection, queryId, cancellationToken, true);

Expand Down Expand Up @@ -464,7 +464,7 @@ private void CheckIfCommandTextIsSet()
if (string.IsNullOrEmpty(CommandText))
{
var errorMessage = "Unable to execute command due to command text not being set";
_logger.Error(errorMessage);
logger.Error(errorMessage);
throw new Exception(errorMessage);
}
}
Expand Down
48 changes: 24 additions & 24 deletions Snowflake.Data/Client/SnowflakeDbConnection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2012-2021 Snowflake Computing Inc. All rights reserved.
*/

Expand All @@ -16,7 +16,7 @@ namespace Snowflake.Data.Client
[System.ComponentModel.DesignerCategory("Code")]
public class SnowflakeDbConnection : DbConnection
{
private SFLogger _logger = SFLoggerFactory.GetLogger<SnowflakeDbConnection>();
private SFLogger logger = SFLoggerFactory.GetLogger<SnowflakeDbConnection>();

internal SFSession SfSession { get; set; }

Expand Down Expand Up @@ -120,7 +120,7 @@ public void PreventPooling()
throw new Exception("Session not yet created for this connection. Unable to prevent the session from pooling");
}
SfSession.SetPooling(false);
_logger.Debug($"Session {SfSession.sessionId} marked not to be pooled any more");
logger.Debug($"Session {SfSession.sessionId} marked not to be pooled any more");
}

internal bool HasActiveExplicitTransaction() => ExplicitTransaction != null && ExplicitTransaction.IsActive;
Expand All @@ -138,7 +138,7 @@ private bool TryToReturnSessionToPool()
var sessionReturnedToPool = SnowflakeDbConnectionPool.AddSession(SfSession);
if (sessionReturnedToPool)
{
_logger.Debug($"Session pooled: {SfSession.sessionId}");
logger.Debug($"Session pooled: {SfSession.sessionId}");
}
return sessionReturnedToPool;
}
Expand All @@ -149,28 +149,28 @@ private TransactionRollbackStatus TerminateTransactionForDirtyConnectionReturnin
return TransactionRollbackStatus.Success;
try
{
_logger.Debug("Closing dirty connection: an active transaction exists in session: " + SfSession.sessionId);
logger.Debug("Closing dirty connection: an active transaction exists in session: " + SfSession.sessionId);
using (IDbCommand command = CreateCommand())
{
command.CommandText = "ROLLBACK";
command.ExecuteNonQuery();
// error to indicate a problem within application code that a connection was closed while still having a pending transaction
_logger.Error("Closing dirty connection: rollback transaction in session " + SfSession.sessionId + " succeeded.");
logger.Error("Closing dirty connection: rollback transaction in session " + SfSession.sessionId + " succeeded.");
ExplicitTransaction = null;
return TransactionRollbackStatus.Success;
}
}
catch (Exception exception)
{
// error to indicate a problem with rollback of an active transaction and inability to return dirty connection to the pool
_logger.Error("Closing dirty connection: rollback transaction in session: " + SfSession.sessionId + " failed, exception: " + exception.Message);
logger.Error("Closing dirty connection: rollback transaction in session: " + SfSession.sessionId + " failed, exception: " + exception.Message);
return TransactionRollbackStatus.Failure; // connection won't be pooled
}
}

public override void ChangeDatabase(string databaseName)
{
_logger.Debug($"ChangeDatabase to:{databaseName}");
logger.Debug($"ChangeDatabase to:{databaseName}");

string alterDbCommand = $"use database {databaseName}";

Expand All @@ -183,7 +183,7 @@ public override void ChangeDatabase(string databaseName)

public override void Close()
{
_logger.Debug("Close Connection.");
logger.Debug("Close Connection.");
if (IsNonClosedWithSession())
{
var returnedToPool = TryToReturnSessionToPool();
Expand All @@ -207,7 +207,7 @@ public override async Task CloseAsync()

public virtual async Task CloseAsync(CancellationToken cancellationToken)
{
_logger.Debug("Close Connection.");
logger.Debug("Close Connection.");
TaskCompletionSource<object> taskCompletionSource = new TaskCompletionSource<object>();

if (cancellationToken.IsCancellationRequested)
Expand All @@ -232,18 +232,18 @@ await SfSession.CloseAsync(cancellationToken).ContinueWith(
if (previousTask.IsFaulted)
{
// Exception from SfSession.CloseAsync
_logger.Error("Error closing the session", previousTask.Exception);
logger.Error("Error closing the session", previousTask.Exception);
taskCompletionSource.SetException(previousTask.Exception);
}
else if (previousTask.IsCanceled)
{
_connectionState = ConnectionState.Closed;
_logger.Debug("Session close canceled");
logger.Debug("Session close canceled");
taskCompletionSource.SetCanceled();
}
else
{
_logger.Debug("Session closed successfully");
logger.Debug("Session closed successfully");
_connectionState = ConnectionState.Closed;
taskCompletionSource.SetResult(null);
}
Expand All @@ -252,7 +252,7 @@ await SfSession.CloseAsync(cancellationToken).ContinueWith(
}
else
{
_logger.Debug("Session not opened. Nothing to do.");
logger.Debug("Session not opened. Nothing to do.");
taskCompletionSource.SetResult(null);
}
}
Expand All @@ -267,10 +267,10 @@ protected virtual bool CanReuseSession(TransactionRollbackStatus transactionRoll

public override void Open()
{
_logger.Debug("Open Connection.");
logger.Debug("Open Connection.");
if (_connectionState != ConnectionState.Closed)
{
_logger.Debug($"Open with a connection already opened: {_connectionState}");
logger.Debug($"Open with a connection already opened: {_connectionState}");
return;
}
try
Expand All @@ -280,14 +280,14 @@ public override void Open()
SfSession = SnowflakeDbConnectionPool.GetSession(ConnectionString, Password);
if (SfSession == null)
throw new SnowflakeDbException(SFError.INTERNAL_ERROR, "Could not open session");
_logger.Debug($"Connection open with pooled session: {SfSession.sessionId}");
logger.Debug($"Connection open with pooled session: {SfSession.sessionId}");
OnSessionEstablished();
}
catch (Exception e)
{
// Otherwise when Dispose() is called, the close request would timeout.
_connectionState = ConnectionState.Closed;
_logger.Error("Unable to connect: ", e);
logger.Error("Unable to connect: ", e);
if (e is SnowflakeDbException)
{
throw;
Expand All @@ -310,10 +310,10 @@ internal void FillConnectionStringFromTomlConfigIfNotSet()

public override Task OpenAsync(CancellationToken cancellationToken)
{
_logger.Debug("Open Connection Async.");
logger.Debug("Open Connection Async.");
if (_connectionState != ConnectionState.Closed)
{
_logger.Debug($"Open with a connection already opened: {_connectionState}");
logger.Debug($"Open with a connection already opened: {_connectionState}");
return Task.CompletedTask;
}
registerConnectionCancellationCallback(cancellationToken);
Expand All @@ -328,7 +328,7 @@ public override Task OpenAsync(CancellationToken cancellationToken)
// Exception from SfSession.OpenAsync
Exception sfSessionEx = previousTask.Exception;
_connectionState = ConnectionState.Closed;
_logger.Error("Unable to connect", sfSessionEx);
logger.Error("Unable to connect", sfSessionEx);
throw new SnowflakeDbException(
sfSessionEx,
SnowflakeDbException.CONNECTION_FAILURE_SSTATE,
Expand All @@ -338,14 +338,14 @@ public override Task OpenAsync(CancellationToken cancellationToken)
else if (previousTask.IsCanceled)
{
_connectionState = ConnectionState.Closed;
_logger.Debug("Connection canceled");
logger.Debug("Connection canceled");
throw new TaskCanceledException("Connecting was cancelled");
}
else
{
// Only continue if the session was opened successfully
SfSession = previousTask.Result;
_logger.Debug($"Connection open with pooled session: {SfSession.sessionId}");
logger.Debug($"Connection open with pooled session: {SfSession.sessionId}");
OnSessionEstablished();
}
}, TaskContinuationOptions.None); // this continuation should be executed always (even if the whole operation was canceled) because it sets the proper state of the connection
Expand Down Expand Up @@ -409,7 +409,7 @@ protected override void Dispose(bool disposing)
catch (Exception ex)
{
// Prevent an exception from being thrown when disposing of this object
_logger.Error("Unable to close connection", ex);
logger.Error("Unable to close connection", ex);
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion Snowflake.Data/Client/SnowflakeDbConnectionPool.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved.
*/

Expand Down
4 changes: 2 additions & 2 deletions Snowflake.Data/Client/SnowflakeDbDataReader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2012-2019 Snowflake Computing Inc. All rights reserved.
*/

Expand All @@ -18,7 +18,7 @@ namespace Snowflake.Data.Client
{
public class SnowflakeDbDataReader : DbDataReader
{
static private readonly SFLogger s_logger = SFLoggerFactory.GetLogger<SnowflakeDbDataReader>();
static private readonly SFLogger logger = SFLoggerFactory.GetLogger<SnowflakeDbDataReader>();

private SnowflakeDbCommand dbCommand;

Expand Down
Loading

0 comments on commit 9038aaa

Please sign in to comment.