Skip to content

Commit 160be3f

Browse files
author
Marc Lewandowski
committed
Update log messages for simpler transformation to structured template.
1 parent 8c61924 commit 160be3f

File tree

3 files changed

+81
-85
lines changed

3 files changed

+81
-85
lines changed

src/MySqlConnector/Core/ConnectionPool.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ public async ValueTask<ServerSession> GetSessionAsync(MySqlConnection connection
2929
// on the lock in RecoverLeakedSessions in high-concurrency situations
3030
if (m_sessionSemaphore.CurrentCount == 0 && unchecked(((uint) Environment.TickCount) - m_lastRecoveryTime) >= 1000u)
3131
{
32-
Log.Warn("{0} is empty; recovering leaked sessions", m_logArguments);
32+
Log.Warn("Pool{0} is empty; recovering leaked sessions", m_logArguments);
3333
RecoverLeakedSessions();
3434
}
3535

3636
if (ConnectionSettings.MinimumPoolSize > 0)
3737
await CreateMinimumPooledSessions(ioBehavior, cancellationToken).ConfigureAwait(false);
3838

3939
// wait for an open slot (until the cancellationToken is cancelled, which is typically due to timeout)
40-
Log.Debug("{0} waiting for an available session", m_logArguments);
40+
Log.Debug("Pool{0} waiting for an available session", m_logArguments);
4141
if (ioBehavior == IOBehavior.Asynchronous)
4242
await m_sessionSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
4343
else
@@ -57,12 +57,12 @@ public async ValueTask<ServerSession> GetSessionAsync(MySqlConnection connection
5757
}
5858
if (session != null)
5959
{
60-
Log.Debug("{0} found an existing session; checking it for validity", m_logArguments);
60+
Log.Debug("Pool{0} found an existing session; checking it for validity", m_logArguments);
6161
bool reuseSession;
6262

6363
if (session.PoolGeneration != m_generation)
6464
{
65-
Log.Debug("{0} discarding session due to wrong generation", m_logArguments);
65+
Log.Debug("Pool{0} discarding session due to wrong generation", m_logArguments);
6666
reuseSession = false;
6767
}
6868
else
@@ -84,7 +84,7 @@ public async ValueTask<ServerSession> GetSessionAsync(MySqlConnection connection
8484
if (!reuseSession)
8585
{
8686
// session is either old or cannot communicate with the server
87-
Log.Warn("{0} Session{1} is unusable; destroying it", m_logArguments[0], session.Id);
87+
Log.Warn("Pool{0} Session{1} is unusable; destroying it", m_logArguments[0], session.Id);
8888
AdjustHostConnectionCount(session, -1);
8989
await session.DisposeAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
9090
}
@@ -99,15 +99,15 @@ public async ValueTask<ServerSession> GetSessionAsync(MySqlConnection connection
9999
leasedSessionsCountPooled = m_leasedSessions.Count;
100100
}
101101
if (Log.IsDebugEnabled())
102-
Log.Debug("{0} returning pooled Session{1} to caller; m_leasedSessions.Count={2}", m_logArguments[0], session.Id, leasedSessionsCountPooled);
102+
Log.Debug("Pool{0} returning pooled Session{1} to caller; LeasedSessionsCount={2}", m_logArguments[0], session.Id, leasedSessionsCountPooled);
103103
return session;
104104
}
105105
}
106106

107107
// create a new session
108108
session = new ServerSession(this, m_generation, Interlocked.Increment(ref m_lastSessionId));
109109
if (Log.IsInfoEnabled())
110-
Log.Info("{0} no pooled session available; created new Session{1}", m_logArguments[0], session.Id);
110+
Log.Info("Pool{0} no pooled session available; created new Session{1}", m_logArguments[0], session.Id);
111111
await session.ConnectAsync(ConnectionSettings, m_loadBalancer, ioBehavior, cancellationToken).ConfigureAwait(false);
112112
AdjustHostConnectionCount(session, 1);
113113
session.OwningConnection = new WeakReference<MySqlConnection>(connection);
@@ -118,7 +118,7 @@ public async ValueTask<ServerSession> GetSessionAsync(MySqlConnection connection
118118
leasedSessionsCountNew = m_leasedSessions.Count;
119119
}
120120
if (Log.IsDebugEnabled())
121-
Log.Debug("{0} returning new Session{1} to caller; m_leasedSessions.Count={2}", m_logArguments[0], session.Id, leasedSessionsCountNew);
121+
Log.Debug("Pool{0} returning new Session{1} to caller; LeasedSessionsCount={2}", m_logArguments[0], session.Id, leasedSessionsCountNew);
122122
return session;
123123
}
124124
catch
@@ -146,7 +146,7 @@ private bool SessionIsHealthy(ServerSession session)
146146
public void Return(ServerSession session)
147147
{
148148
if (Log.IsDebugEnabled())
149-
Log.Debug("{0} receiving Session{1} back", m_logArguments[0], session.Id);
149+
Log.Debug("Pool{0} receiving Session{1} back", m_logArguments[0], session.Id);
150150

151151
try
152152
{
@@ -160,7 +160,7 @@ public void Return(ServerSession session)
160160
}
161161
else
162162
{
163-
Log.Warn("{0} received invalid Session{1}; destroying it", m_logArguments[0], session.Id);
163+
Log.Warn("Pool{0} received invalid Session{1}; destroying it", m_logArguments[0], session.Id);
164164
AdjustHostConnectionCount(session, -1);
165165
session.DisposeAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
166166
}
@@ -174,7 +174,7 @@ public void Return(ServerSession session)
174174
public async Task ClearAsync(IOBehavior ioBehavior, CancellationToken cancellationToken)
175175
{
176176
// increment the generation of the connection pool
177-
Log.Info("{0} clearing connection pool", m_logArguments);
177+
Log.Info("Pool{0} clearing connection pool", m_logArguments);
178178
Interlocked.Increment(ref m_generation);
179179
m_procedureCache = null;
180180
RecoverLeakedSessions();
@@ -183,7 +183,7 @@ public async Task ClearAsync(IOBehavior ioBehavior, CancellationToken cancellati
183183

184184
public async Task ReapAsync(IOBehavior ioBehavior, CancellationToken cancellationToken)
185185
{
186-
Log.Debug("{0} reaping connection pool", m_logArguments);
186+
Log.Debug("Pool{0} reaping connection pool", m_logArguments);
187187
RecoverLeakedSessions();
188188
await CleanPoolAsync(ioBehavior, session => (unchecked((uint) Environment.TickCount) - session.LastReturnedTicks) / 1000 >= ConnectionSettings.ConnectionIdleTimeout, true, cancellationToken).ConfigureAwait(false);
189189
}
@@ -223,9 +223,9 @@ private void RecoverLeakedSessions()
223223
}
224224
}
225225
if (recoveredSessions.Count == 0)
226-
Log.Debug("{0} recovered no sessions", m_logArguments);
226+
Log.Debug("Pool{0} recovered no sessions", m_logArguments);
227227
else
228-
Log.Warn("{0} recovered {1} sessions", m_logArguments[0], recoveredSessions.Count);
228+
Log.Warn("Pool{0}: RecoveredSessionCount={1}", m_logArguments[0], recoveredSessions.Count);
229229
foreach (var session in recoveredSessions)
230230
session.ReturnToPool();
231231
}
@@ -279,7 +279,7 @@ private async Task CleanPoolAsync(IOBehavior ioBehavior, Func<ServerSession, boo
279279
if (shouldCleanFn(session))
280280
{
281281
// session should be cleaned; dispose it and keep iterating
282-
Log.Info("{0} found Session{1} to clean up", m_logArguments[0], session.Id);
282+
Log.Info("Pool{0} found Session{1} to clean up", m_logArguments[0], session.Id);
283283
await session.DisposeAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
284284
}
285285
else
@@ -329,7 +329,7 @@ private async Task CreateMinimumPooledSessions(IOBehavior ioBehavior, Cancellati
329329
try
330330
{
331331
var session = new ServerSession(this, m_generation, Interlocked.Increment(ref m_lastSessionId));
332-
Log.Info("{0} created Session{1} to reach minimum pool size", m_logArguments[0], session.Id);
332+
Log.Info("Pool{0} created Session{1} to reach minimum pool size", m_logArguments[0], session.Id);
333333
await session.ConnectAsync(ConnectionSettings, m_loadBalancer, ioBehavior, cancellationToken).ConfigureAwait(false);
334334
AdjustHostConnectionCount(session, 1);
335335
lock (m_sessions)
@@ -391,7 +391,7 @@ public static ConnectionPool GetPool(string connectionString)
391391
}
392392
else if (pool != newPool && Log.IsInfoEnabled())
393393
{
394-
Log.Info("{0} was created but will not be used (due to race)", newPool.m_logArguments[0]);
394+
Log.Info("Pool{0} was created but will not be used (due to race)", newPool.m_logArguments[0]);
395395
}
396396

397397
return pool;
@@ -438,9 +438,9 @@ private ConnectionPool(ConnectionSettings cs)
438438
(ILoadBalancer) new RoundRobinLoadBalancer();
439439

440440
Id = Interlocked.Increment(ref s_poolId);
441-
m_logArguments = new object[] { "Pool{0}".FormatInvariant(Id) };
441+
m_logArguments = new object[] { "{0}".FormatInvariant(Id) };
442442
if (Log.IsInfoEnabled())
443-
Log.Info("{0} creating new connection pool for {1}", m_logArguments[0], cs.ConnectionStringBuilder.GetConnectionString(includePassword: false));
443+
Log.Info("Pool{0} creating new connection pool for ConnectionString{1}", m_logArguments[0], cs.ConnectionStringBuilder.GetConnectionString(includePassword: false));
444444

445445
if (cs.ConnectionIdleTimeout > 0)
446446
{

0 commit comments

Comments
 (0)