1
0
mirror of https://github.com/winscp/winscp.git synced 2026-10-24 02:28:55 +03:00

Bug 1637: Low logging level

https://winscp.net/tracker/1637

Source commit: 77c4bd8361dc2604b244964b6b60240465ece323
This commit is contained in:
Martin Prikryl
2018-04-20 10:23:10 +00:00
parent 0739b41c7f
commit c7a55143cb
13 changed files with 103 additions and 37 deletions

View File

@@ -330,7 +330,7 @@ namespace WinSCP
private void SetLogLevel(int value)
{
if ((value < 0) || (value > 2))
if ((value < -1) || (value > 2))
{
throw WriteException(new ArgumentOutOfRangeException(string.Format(CultureInfo.CurrentCulture, "Logging level has to be in range 0-2")));
}

View File

@@ -261,6 +261,7 @@ __fastcall TFTPFileSystem::TFTPFileSystem(TTerminal * ATerminal):
FPrivateKey = NULL;
FBytesAvailable = -1;
FBytesAvailableSuppoted = false;
FLoggedIn = false;
FChecksumAlgs.reset(new TStringList());
FChecksumCommands.reset(new TStringList());
@@ -316,6 +317,7 @@ void __fastcall TFTPFileSystem::Open()
ResetCaches();
FReadCurrentDirectory = true;
FHomeDirectory = L"";
FLoggedIn = false;
FLastDataSent = Now();
@@ -332,6 +334,10 @@ void __fastcall TFTPFileSystem::Open()
switch (FTerminal->Configuration->ActualLogProtocol)
{
default:
case -1:
LogLevel = TFileZillaIntf::LOG_WARNING;
break;
case 0:
case 1:
LogLevel = TFileZillaIntf::LOG_PROGRESS;
@@ -516,6 +522,7 @@ void __fastcall TFTPFileSystem::Open()
FSessionInfo.SCCipher = FSessionInfo.CSCipher;
UnicodeString TlsVersionStr = FFileZillaIntf->GetTlsVersionStr().c_str();
AddToList(FSessionInfo.SecurityProtocolName, TlsVersionStr, L", ");
FLoggedIn = true;
}
//---------------------------------------------------------------------------
void __fastcall TFTPFileSystem::Close()
@@ -2623,7 +2630,7 @@ int __fastcall TFTPFileSystem::GetOptionVal(int OptionID) const
break;
case OPTION_DEBUGSHOWLISTING:
Result = true;
Result = (FTerminal->Configuration->ActualLogProtocol >= 0);
break;
case OPTION_PASV:
@@ -3437,7 +3444,10 @@ bool __fastcall TFTPFileSystem::HandleStatus(const wchar_t * AStatus, int Type)
{
FLastCommand = CMD_UNKNOWN;
}
LogType = llInput;
if (!FLoggedIn || (FTerminal->Configuration->ActualLogProtocol >= 0))
{
LogType = llInput;
}
break;
case TFileZillaIntf::LOG_ERROR:
@@ -3474,7 +3484,10 @@ bool __fastcall TFTPFileSystem::HandleStatus(const wchar_t * AStatus, int Type)
case TFileZillaIntf::LOG_REPLY:
HandleReplyStatus(AStatus);
LogType = llOutput;
if (!FLoggedIn || (FTerminal->Configuration->ActualLogProtocol >= 0))
{
LogType = llOutput;
}
break;
case TFileZillaIntf::LOG_INFO:

View File

@@ -290,6 +290,7 @@ private:
bool FMVS;
bool FVMS;
bool FFileTransferAny;
bool FLoggedIn;
mutable UnicodeString FOptionScratch;
};
//---------------------------------------------------------------------------

View File

@@ -2101,7 +2101,10 @@ void __fastcall TSCPFileSystem::CopyToLocal(TStrings * FilesToCopy,
FTerminal->LogEvent(FORMAT(L"Copying %d files/directories to local directory "
"\"%s\"", (FilesToCopy->Count, TargetDir)));
FTerminal->LogEvent(CopyParam->LogStr);
if (FTerminal->Configuration->ActualLogProtocol >= 0)
{
FTerminal->LogEvent(CopyParam->LogStr);
}
try
{
@@ -2516,8 +2519,11 @@ void __fastcall TSCPFileSystem::SCPSink(const UnicodeString TargetDir,
// Will we use ASCII of BINARY file transfer?
OperationProgress->SetAsciiTransfer(
CopyParam->UseAsciiTransfer(BaseFileName, osRemote, MaskParams));
FTerminal->LogEvent(UnicodeString((OperationProgress->AsciiTransfer ? L"Ascii" : L"Binary")) +
L" transfer mode selected.");
if (FTerminal->Configuration->ActualLogProtocol >= 0)
{
FTerminal->LogEvent(UnicodeString((OperationProgress->AsciiTransfer ? L"Ascii" : L"Binary")) +
L" transfer mode selected.");
}
try
{

View File

@@ -1180,7 +1180,10 @@ UnicodeString __fastcall TSecureShell::ConvertInput(const RawByteString & Input)
//---------------------------------------------------------------------------
void __fastcall TSecureShell::SendSpecial(int Code)
{
LogEvent(FORMAT(L"Sending special code: %d", (Code)));
if (Configuration->ActualLogProtocol >= 0)
{
LogEvent(FORMAT(L"Sending special code: %d", (Code)));
}
CheckConnection();
FBackend->special(FBackendHandle, (Telnet_Special)Code);
CheckConnection();

View File

@@ -1063,7 +1063,11 @@ void __fastcall TSessionLog::DoAddStartupInfo(TSessionData * Data)
wcscpy(UserName, L"<Failed to retrieve username>");
}
UnicodeString LogStr;
if (FConfiguration->LogProtocol <= 0)
if (FConfiguration->LogProtocol <= -1)
{
LogStr = L"Reduced";
}
else if (FConfiguration->LogProtocol <= 0)
{
LogStr = L"Normal";
}

View File

@@ -2277,7 +2277,7 @@ void __fastcall TSFTPFileSystem::SendPacket(const TSFTPPacket * Packet)
BusyStart();
try
{
if (FTerminal->Log->Logging)
if (FTerminal->Log->Logging && (FTerminal->Configuration->ActualLogProtocol >= 0))
{
if ((FPreviousLoggedPacket != SSH_FXP_READ &&
FPreviousLoggedPacket != SSH_FXP_WRITE) ||
@@ -2397,7 +2397,8 @@ unsigned long __fastcall TSFTPFileSystem::GotStatusPacket(TSFTPPacket * Packet,
{
ServerMessage = LoadStr(SFTP_SERVER_MESSAGE_UNSUPPORTED);
}
if (FTerminal->Log->Logging)
if (FTerminal->Log->Logging &&
(FTerminal->Configuration->ActualLogProtocol >= 0))
{
FTerminal->Log->Add(llOutput, FORMAT(L"Status code: %d, Message: %d, Server: %s, Language: %s ",
(int(Code), (int)Packet->MessageNumber, ServerMessage, LanguageTag)));
@@ -2431,7 +2432,10 @@ unsigned long __fastcall TSFTPFileSystem::GotStatusPacket(TSFTPPacket * Packet,
{
if (!FNotLoggedPackets || Code)
{
FTerminal->Log->Add(llOutput, FORMAT(L"Status code: %d", ((int)Code)));
if (FTerminal->Configuration->ActualLogProtocol >= 0)
{
FTerminal->Log->Add(llOutput, FORMAT(L"Status code: %d", ((int)Code)));
}
}
return Code;
}
@@ -2515,7 +2519,7 @@ int __fastcall TSFTPFileSystem::ReceivePacket(TSFTPPacket * Packet,
FSecureShell->Receive(Packet->Data, Length);
Packet->DataUpdated(Length);
if (FTerminal->Log->Logging)
if (FTerminal->Log->Logging && (FTerminal->Configuration->ActualLogProtocol >= 0))
{
if ((FPreviousLoggedPacket != SSH_FXP_READ &&
FPreviousLoggedPacket != SSH_FXP_WRITE) ||
@@ -2555,12 +2559,18 @@ int __fastcall TSFTPFileSystem::ReceivePacket(TSFTPPacket * Packet,
IsReserved = true;
if (ReservedPacket)
{
FTerminal->LogEvent(L"Storing reserved response");
if (FTerminal->Configuration->ActualLogProtocol >= 0)
{
FTerminal->LogEvent(L"Storing reserved response");
}
*ReservedPacket = *Packet;
}
else
{
FTerminal->LogEvent(L"Discarding reserved response");
if (FTerminal->Configuration->ActualLogProtocol >= 0)
{
FTerminal->LogEvent(L"Discarding reserved response");
}
RemoveReservation(Index);
if ((Reservation >= 0) && (Reservation > Index))
{
@@ -2695,8 +2705,10 @@ UnicodeString __fastcall TSFTPFileSystem::RealPath(const UnicodeString Path)
{
try
{
FTerminal->LogEvent(FORMAT(L"Getting real path for '%s'",
(Path)));
if (FTerminal->Configuration->ActualLogProtocol >= 0)
{
FTerminal->LogEvent(FORMAT(L"Getting real path for '%s'", (Path)));
}
TSFTPPacket Packet(SSH_FXP_REALPATH);
Packet.AddPathString(Path, FUtfStrings);
@@ -2742,7 +2754,10 @@ UnicodeString __fastcall TSFTPFileSystem::RealPath(const UnicodeString Path)
UnicodeString RealDir = UnixExcludeTrailingBackslash(Packet.GetPathString(FUtfStrings));
// ignore rest of SSH_FXP_NAME packet
FTerminal->LogEvent(FORMAT(L"Real path is '%s'", (RealDir)));
if (FTerminal->Configuration->ActualLogProtocol >= 0)
{
FTerminal->LogEvent(FORMAT(L"Real path is '%s'", (RealDir)));
}
return RealDir;
}
@@ -3127,8 +3142,11 @@ void __fastcall TSFTPFileSystem::DoStartup()
}
else
{
FTerminal->LogEvent(FORMAT(L"Unknown server extension %s=%s",
(ExtensionName, ExtensionDisplayData)));
if (FTerminal->Configuration->ActualLogProtocol >= 0)
{
FTerminal->LogEvent(FORMAT(L"Unknown server extension %s=%s",
(ExtensionName, ExtensionDisplayData)));
}
}
FExtensions->Values[ExtensionName] = ExtensionDisplayData;
}
@@ -4573,7 +4591,10 @@ void __fastcall TSFTPFileSystem::Source(
OpenParams.FileParams = &FileParams;
OpenParams.Confirmed = false;
FTerminal->LogEvent(L"Opening remote file.");
if (FTerminal->Configuration->ActualLogProtocol >= 0)
{
FTerminal->LogEvent(L"Opening remote file.");
}
FTerminal->FileOperationLoop(SFTPOpenRemote, OperationProgress, folAllowSkip,
FMTLOAD(SFTP_CREATE_FILE_ERROR, (OpenParams.RemoteFileName)),
&OpenParams);

View File

@@ -3443,7 +3443,7 @@ void __fastcall TTerminal::CustomReadDirectory(TRemoteFileList * FileList)
while (RobustLoop.Retry());
if (Log->Logging)
if (Log->Logging && (Configuration->ActualLogProtocol >= 0))
{
for (int Index = 0; Index < FileList->Count; Index++)
{
@@ -5519,13 +5519,19 @@ void __fastcall TTerminal::DoSynchronizeCollectDirectory(const UnicodeString Loc
FileData->Modified = false;
Data.LocalFileList->AddObject(FileName,
reinterpret_cast<TObject*>(FileData));
LogEvent(FORMAT(L"Local file %s included to synchronization",
(FormatFileDetailsForLog(FullLocalFileName, Modification, Size))));
if (Configuration->ActualLogProtocol >= 0)
{
LogEvent(FORMAT(L"Local file %s included to synchronization",
(FormatFileDetailsForLog(FullLocalFileName, Modification, Size))));
}
}
else
{
LogEvent(FORMAT(L"Local file %s excluded from synchronization",
(FormatFileDetailsForLog(FullLocalFileName, Modification, Size))));
if (Configuration->ActualLogProtocol >= 0)
{
LogEvent(FORMAT(L"Local file %s excluded from synchronization",
(FormatFileDetailsForLog(FullLocalFileName, Modification, Size))));
}
}
FILE_OPERATION_LOOP_BEGIN
@@ -5862,8 +5868,11 @@ void __fastcall TTerminal::DoSynchronizeCollectFile(const UnicodeString FileName
}
else
{
LogEvent(FORMAT(L"Remote file %s excluded from synchronization",
(FormatFileDetailsForLog(FullRemoteFileName, File->Modification, File->Size))));
if (Configuration->ActualLogProtocol >= 0)
{
LogEvent(FORMAT(L"Remote file %s excluded from synchronization",
(FormatFileDetailsForLog(FullRemoteFileName, File->Modification, File->Size))));
}
}
}
//---------------------------------------------------------------------------
@@ -6490,7 +6499,10 @@ void __fastcall TTerminal::LogTotalTransferDetails(
S += FORMAT(L" - total size: %s", (FormatSize(OperationProgress->TotalSize)));
}
LogEvent(S);
LogEvent(CopyParam->LogStr);
if (Configuration->ActualLogProtocol >= 0)
{
LogEvent(CopyParam->LogStr);
}
}
}
//---------------------------------------------------------------------------
@@ -6844,8 +6856,11 @@ void __fastcall TTerminal::SelectTransferMode(
const TFileMasks::TParams & MaskParams)
{
OperationProgress->SetAsciiTransfer(CopyParam->UseAsciiTransfer(BaseFileName, Side, MaskParams));
UnicodeString ModeName = (OperationProgress->AsciiTransfer ? L"Ascii" : L"Binary");
LogEvent(FORMAT(L"%s transfer mode selected.", (ModeName)));
if (Configuration->ActualLogProtocol >= 0)
{
UnicodeString ModeName = (OperationProgress->AsciiTransfer ? L"Ascii" : L"Binary");
LogEvent(FORMAT(L"%s transfer mode selected.", (ModeName)));
}
}
//---------------------------------------------------------------------------
void __fastcall TTerminal::SelectSourceTransferMode(const TLocalFileHandle & Handle, const TCopyParamType * CopyParam)

View File

@@ -1649,7 +1649,7 @@ void CAsyncSslSocketLayer::PrintSessionInfo()
m_TlsVersionStr.c_str(),
m_CipherName.c_str());
USES_CONVERSION;
LogSocketMessageRaw(FZ_LOG_WARNING, A2T(buffer));
LogSocketMessageRaw(FZ_LOG_PROGRESS, A2T(buffer));
delete [] buffer;
delete [] buffer2;
}

View File

@@ -966,7 +966,7 @@ int CTransferSocket::OnLayerCallback(std::list<t_callbackMsg>& callbacks)
switch (iter->nParam1)
{
case PROXYERROR_NOERROR:
m_pOwner->ShowStatus(IDS_PROXY_CONNECTED, FZ_LOG_STATUS);
m_pOwner->ShowStatus(IDS_PROXY_CONNECTED, FZ_LOG_PROGRESS);
break;
case PROXYERROR_NOCONN:
m_pOwner->ShowStatus(IDS_ERRORMSG_PROXY_NOCONN, FZ_LOG_ERROR);
@@ -1001,7 +1001,7 @@ int CTransferSocket::OnLayerCallback(std::list<t_callbackMsg>& callbacks)
CloseAndEnsureSendClose(0);
break;
case SSL_INFO_ESTABLISHED:
m_pOwner->ShowStatus(IDS_STATUSMSG_SSLESTABLISHEDTRANSFER, FZ_LOG_STATUS);
m_pOwner->ShowStatus(IDS_STATUSMSG_SSLESTABLISHEDTRANSFER, FZ_LOG_PROGRESS);
TriggerEvent(FD_FORCEREAD);
break;
}

View File

@@ -35,6 +35,8 @@
#pragma resource "*.dfm"
#endif
//---------------------------------------------------------------------
const int BelowNormalLogLevels = 1;
//---------------------------------------------------------------------
bool __fastcall DoPreferencesDialog(TPreferencesMode APreferencesMode,
TPreferencesDialogData * DialogData)
{
@@ -588,7 +590,7 @@ void __fastcall TPreferencesDialog::LoadConfiguration()
// logging
EnableLoggingCheck->Checked = Configuration->Logging;
LogProtocolCombo->ItemIndex = Configuration->LogProtocol;
LogProtocolCombo->ItemIndex = Configuration->LogProtocol + BelowNormalLogLevels;
LogFileNameEdit3->Text =
!Configuration->LogFileName.IsEmpty() ? Configuration->LogFileName : Configuration->DefaultLogFileName;
if (Configuration->LogFileAppend)
@@ -882,7 +884,7 @@ void __fastcall TPreferencesDialog::SaveConfiguration()
// logging
Configuration->Logging = EnableLoggingCheck->Checked && !LogFileNameEdit3->Text.IsEmpty();
Configuration->LogProtocol = LogProtocolCombo->ItemIndex;
Configuration->LogProtocol = LogProtocolCombo->ItemIndex - BelowNormalLogLevels;
Configuration->LogFileName = LogFileNameEdit3->Text;
Configuration->LogFileAppend = LogFileAppendButton->Checked;
__int64 LogMaxSize;

View File

@@ -344,6 +344,7 @@ object PreferencesDialog: TPreferencesDialog
TabOrder = 1
OnChange = ControlChange
Items.Strings = (
'Reduced'
'Normal'
'Debug 1'
'Debug 2')

View File

@@ -737,7 +737,7 @@ int __fastcall Execute()
Configuration->TemporaryLogSensitive(LogSensitive);
}
int LogProtocol;
if (!SwitchValue.IsEmpty() && TryStrToInt(SwitchValue, LogProtocol) && (LogProtocol >= 0))
if (!SwitchValue.IsEmpty() && TryStrToInt(SwitchValue, LogProtocol) && (LogProtocol >= -1))
{
Configuration->TemporaryLogProtocol(LogProtocol);
}