Skip to content

Commit 23ce58a

Browse files
Student Mainceleron533
authored andcommitted
Tweak debug message out levels
1 parent 6f4fd01 commit 23ce58a

File tree

5 files changed

+31
-24
lines changed

5 files changed

+31
-24
lines changed

shadowsocks-csharp/Controller/Service/TCPRelay.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public void CreateRemote()
221221
this._server = server;
222222

223223
/* prepare address buffer length for AEAD */
224-
Logger.Debug($"_addrBufLength={_addrBufLength}");
224+
Logger.Trace($"_addrBufLength={_addrBufLength}");
225225
_encryptor.AddrBufLength = _addrBufLength;
226226
}
227227

@@ -798,7 +798,7 @@ private void StartPipe(AsyncSession session)
798798
PipeRemoteReceiveCallback, session);
799799

800800
TryReadAvailableData();
801-
Logger.Debug($"_firstPacketLength = {_firstPacketLength}");
801+
Logger.Trace($"_firstPacketLength = {_firstPacketLength}");
802802
SendToServer(_firstPacketLength, session);
803803
}
804804
catch (Exception e)
@@ -837,12 +837,12 @@ private void PipeRemoteReceiveCallback(IAsyncResult ar)
837837
if (bytesToSend == 0)
838838
{
839839
// need more to decrypt
840-
Logger.Debug("Need more to decrypt");
840+
Logger.Trace("Need more to decrypt");
841841
session.Remote.BeginReceive(_remoteRecvBuffer, 0, RecvSize, SocketFlags.None,
842842
PipeRemoteReceiveCallback, session);
843843
return;
844844
}
845-
Logger.Debug($"start sending {bytesToSend}");
845+
Logger.Trace($"start sending {bytesToSend}");
846846
_connection.BeginSend(_remoteSendBuffer, 0, bytesToSend, SocketFlags.None,
847847
PipeConnectionSendCallback, new object[] { session, bytesToSend });
848848
IStrategy strategy = _controller.GetCurrentStrategy();

shadowsocks-csharp/Controller/Service/UpdateChecker.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void CheckUpdate(Configuration config)
6262

6363
try
6464
{
65-
logger.Debug("Checking updates...");
65+
logger.Info("Checking updates...");
6666
WebClient http = CreateWebClient();
6767
http.DownloadStringCompleted += http_DownloadStringCompleted;
6868
http.DownloadStringAsync(new Uri(UpdateURL));
@@ -119,7 +119,7 @@ private void http_DownloadStringCompleted(object sender, DownloadStringCompleted
119119
}
120120
else
121121
{
122-
logger.Debug("No update is available");
122+
logger.Info("No update is available");
123123
if (CheckUpdateCompleted != null)
124124
{
125125
CheckUpdateCompleted(this, new EventArgs());
@@ -156,7 +156,7 @@ private void Http_DownloadFileCompleted(object sender, System.ComponentModel.Asy
156156
logger.LogUsefulException(e.Error);
157157
return;
158158
}
159-
logger.Debug($"New version {LatestVersionNumber}{LatestVersionSuffix} found: {LatestVersionLocalName}");
159+
logger.Info($"New version {LatestVersionNumber}{LatestVersionSuffix} found: {LatestVersionLocalName}");
160160
if (CheckUpdateCompleted != null)
161161
{
162162
CheckUpdateCompleted(this, new EventArgs());

shadowsocks-csharp/Encryption/AEAD/AEADEncryptor.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public override void Encrypt(byte[] buf, int length, byte[] outbuf, out int outl
141141

142142
_encCircularBuffer.Put(buf, 0, length);
143143
outlength = 0;
144-
logger.Debug("---Start Encryption");
144+
logger.Trace("---Start Encryption");
145145
if (! _encryptSaltSent) {
146146
_encryptSaltSent = true;
147147
// Generate salt
@@ -150,7 +150,7 @@ public override void Encrypt(byte[] buf, int length, byte[] outbuf, out int outl
150150
InitCipher(saltBytes, true, false);
151151
Array.Copy(saltBytes, 0, outbuf, 0, saltLen);
152152
outlength = saltLen;
153-
logger.Debug($"_encryptSaltSent outlength {outlength}");
153+
logger.Trace($"_encryptSaltSent outlength {outlength}");
154154
}
155155

156156
if (! _tcpRequestSent) {
@@ -163,7 +163,7 @@ public override void Encrypt(byte[] buf, int length, byte[] outbuf, out int outl
163163
Debug.Assert(encAddrBufLength == AddrBufLength + tagLen * 2 + CHUNK_LEN_BYTES);
164164
Array.Copy(encAddrBufBytes, 0, outbuf, outlength, encAddrBufLength);
165165
outlength += encAddrBufLength;
166-
logger.Debug($"_tcpRequestSent outlength {outlength}");
166+
logger.Trace($"_tcpRequestSent outlength {outlength}");
167167
}
168168

169169
// handle other chunks
@@ -178,15 +178,15 @@ public override void Encrypt(byte[] buf, int length, byte[] outbuf, out int outl
178178
Debug.Assert(encChunkLength == chunklength + tagLen * 2 + CHUNK_LEN_BYTES);
179179
Buffer.BlockCopy(encChunkBytes, 0, outbuf, outlength, encChunkLength);
180180
outlength += encChunkLength;
181-
logger.Debug("chunks enc outlength " + outlength);
181+
logger.Trace("chunks enc outlength " + outlength);
182182
// check if we have enough space for outbuf
183183
if (outlength + TCPHandler.ChunkOverheadSize > TCPHandler.BufferSize) {
184-
logger.Debug("enc outbuf almost full, giving up");
184+
logger.Trace("enc outbuf almost full, giving up");
185185
return;
186186
}
187187
bufSize = (uint)_encCircularBuffer.Size;
188188
if (bufSize <= 0) {
189-
logger.Debug("No more data to encrypt, leaving");
189+
logger.Trace("No more data to encrypt, leaving");
190190
return;
191191
}
192192
}
@@ -201,7 +201,7 @@ public override void Decrypt(byte[] buf, int length, byte[] outbuf, out int outl
201201
// drop all into buffer
202202
_decCircularBuffer.Put(buf, 0, length);
203203

204-
logger.Debug("---Start Decryption");
204+
logger.Trace("---Start Decryption");
205205
if (! _decryptSaltReceived) {
206206
bufSize = _decCircularBuffer.Size;
207207
// check if we get the leading salt
@@ -212,15 +212,15 @@ public override void Decrypt(byte[] buf, int length, byte[] outbuf, out int outl
212212
_decryptSaltReceived = true;
213213
byte[] salt = _decCircularBuffer.Get(saltLen);
214214
InitCipher(salt, false, false);
215-
logger.Debug("get salt len " + saltLen);
215+
logger.Trace("get salt len " + saltLen);
216216
}
217217

218218
// handle chunks
219219
while (true) {
220220
bufSize = _decCircularBuffer.Size;
221221
// check if we have any data
222222
if (bufSize <= 0) {
223-
logger.Debug("No data in _decCircularBuffer");
223+
logger.Trace("No data in _decCircularBuffer");
224224
return;
225225
}
226226

@@ -246,10 +246,10 @@ public override void Decrypt(byte[] buf, int length, byte[] outbuf, out int outl
246246
logger.Error($"Invalid chunk length: {chunkLen}");
247247
throw new CryptoErrorException();
248248
}
249-
logger.Debug("Get the real chunk len:" + chunkLen);
249+
logger.Trace("Get the real chunk len:" + chunkLen);
250250
bufSize = _decCircularBuffer.Size;
251251
if (bufSize < CHUNK_LEN_BYTES + tagLen /* we haven't remove them */+ chunkLen + tagLen) {
252-
logger.Debug("No more data to decrypt one chunk");
252+
logger.Trace("No more data to decrypt one chunk");
253253
return;
254254
}
255255
IncrementNonce(false);
@@ -269,16 +269,16 @@ public override void Decrypt(byte[] buf, int length, byte[] outbuf, out int outl
269269
// output to outbuf
270270
Buffer.BlockCopy(decChunkBytes, 0, outbuf, outlength, (int) decChunkLen);
271271
outlength += (int)decChunkLen;
272-
logger.Debug("aead dec outlength " + outlength);
272+
logger.Trace("aead dec outlength " + outlength);
273273
if (outlength + 100 > TCPHandler.BufferSize)
274274
{
275-
logger.Debug("dec outbuf almost full, giving up");
275+
logger.Trace("dec outbuf almost full, giving up");
276276
return;
277277
}
278278
bufSize = _decCircularBuffer.Size;
279279
// check if we already done all of them
280280
if (bufSize <= 0) {
281-
logger.Debug("No data in _decCircularBuffer, already all done");
281+
logger.Trace("No data in _decCircularBuffer, already all done");
282282
return;
283283
}
284284
}

shadowsocks-csharp/Model/Configuration.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ public class Configuration
4545
NLogConfig nLogConfig;
4646

4747
private static readonly string CONFIG_FILE = "gui-config.json";
48+
private static readonly NLogConfig.LogLevel verboseLogLevel =
49+
#if DEBUG
50+
NLogConfig.LogLevel.Trace;
51+
#else
52+
NLogConfig.LogLevel.Debug;
53+
#endif
54+
4855

4956
[JsonIgnore]
5057
public bool updated = false;
@@ -185,10 +192,10 @@ public static void Save(Configuration config)
185192
try
186193
{
187194
// apply changs to NLog.config
188-
config.nLogConfig.SetLogLevel(config.isVerboseLogging? NLogConfig.LogLevel.Trace: NLogConfig.LogLevel.Info);
195+
config.nLogConfig.SetLogLevel(config.isVerboseLogging? verboseLogLevel : NLogConfig.LogLevel.Info);
189196
NLogConfig.SaveXML(config.nLogConfig);
190197
}
191-
catch(Exception e)
198+
catch (Exception e)
192199
{
193200
logger.Error(e, "Cannot set the log level to NLog config file. Please check if the nlog config file exists with corresponding XML nodes.");
194201
}

shadowsocks-csharp/Proxy/HttpProxy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private void OnException(Exception ex, object state)
182182

183183
private bool OnLineRead(string line, object state)
184184
{
185-
logger.Debug(line);
185+
logger.Trace(line);
186186

187187
if (_respondLineCount == 0)
188188
{

0 commit comments

Comments
 (0)