Skip to content

Commit

Permalink
Bug 1637: Low logging level
Browse files Browse the repository at this point in the history
https://winscp.net/tracker/1637

Source commit: 77c4bd8361dc2604b244964b6b60240465ece323
  • Loading branch information
martinprikryl committed Apr 21, 2018
1 parent 0739b41 commit c7a5514
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 37 deletions.
2 changes: 1 addition & 1 deletion dotnet/internal/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public static string LastWin32ErrorMessage()

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")));
}
Expand Down
19 changes: 16 additions & 3 deletions source/core/FtpFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -316,6 +317,7 @@ void __fastcall TFTPFileSystem::Open()
ResetCaches();
FReadCurrentDirectory = true;
FHomeDirectory = L"";
FLoggedIn = false;

FLastDataSent = Now();

Expand All @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions source/core/FtpFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ friend class TFileListHelper;
bool FMVS;
bool FVMS;
bool FFileTransferAny;
bool FLoggedIn;
mutable UnicodeString FOptionScratch;
};
//---------------------------------------------------------------------------
Expand Down
12 changes: 9 additions & 3 deletions source/core/ScpFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down
5 changes: 4 additions & 1 deletion source/core/SecureShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion source/core/SessionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
45 changes: 33 additions & 12 deletions source/core/SftpFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) ||
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
35 changes: 25 additions & 10 deletions source/core/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))));
}
}
}
//---------------------------------------------------------------------------
Expand Down Expand Up @@ -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);
}
}
}
//---------------------------------------------------------------------------
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion source/filezilla/AsyncSslSocketLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions source/filezilla/TransferSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions source/forms/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#pragma resource "*.dfm"
#endif
//---------------------------------------------------------------------
const int BelowNormalLogLevels = 1;
//---------------------------------------------------------------------
bool __fastcall DoPreferencesDialog(TPreferencesMode APreferencesMode,
TPreferencesDialogData * DialogData)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions source/forms/Preferences.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ object PreferencesDialog: TPreferencesDialog
TabOrder = 1
OnChange = ControlChange
Items.Strings = (
'Reduced'
'Normal'
'Debug 1'
'Debug 2')
Expand Down
2 changes: 1 addition & 1 deletion source/windows/WinMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit c7a5514

Please sign in to comment.