added: SLog class -- session logger
messages are displayed in the browser (with locales) changed: MountParser now if there is an error in a line -- the line is simply skipped git-svn-id: svn://ttmath.org/publicrep/winix/trunk@741 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
133
templates/slog.cpp
Executable file
133
templates/slog.cpp
Executable file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "core/slog.h"
|
||||
#include "templates.h"
|
||||
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
static size_t slog_index = 0;
|
||||
static LogManipulators slog_last_type;
|
||||
|
||||
|
||||
|
||||
bool slog_is()
|
||||
{
|
||||
if( !cur->session )
|
||||
return false;
|
||||
|
||||
return slog_index < cur->session->log_buffer.Size();
|
||||
}
|
||||
|
||||
|
||||
void slog_skipline()
|
||||
{
|
||||
if( !cur->session )
|
||||
return;
|
||||
|
||||
TextStream<std::wstring> & buf = cur->session->log_buffer;
|
||||
|
||||
while( slog_index < buf.Size() && buf[slog_index]!=10 )
|
||||
slog_index += 1;
|
||||
|
||||
if( slog_index < buf.Size() )
|
||||
slog_index += 1; // skipping the '\n'
|
||||
}
|
||||
|
||||
|
||||
void slog_settype()
|
||||
{
|
||||
if( !slog_is() )
|
||||
return;
|
||||
|
||||
TextStream<std::wstring> & buf = cur->session->log_buffer;
|
||||
slog_last_type = static_cast<LogManipulators>(buf[slog_index]);
|
||||
|
||||
switch( slog_last_type )
|
||||
{
|
||||
case loginfo:
|
||||
case logwarning:
|
||||
case logerror:
|
||||
slog_index += 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
slog_last_type = loginfo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void slog_tab(Info & i)
|
||||
{
|
||||
if( i.iter == 0 )
|
||||
slog_index = 0;
|
||||
else
|
||||
slog_skipline();
|
||||
|
||||
// the type is written as the first character (after '\n' or at the beginning of the string)
|
||||
slog_settype();
|
||||
|
||||
i.res = slog_is();
|
||||
|
||||
if( cur->session && !i.res )
|
||||
cur->session->log_buffer.Clear(); // the session log has been printed
|
||||
}
|
||||
|
||||
|
||||
void slog_tab_is_info(Info & i)
|
||||
{
|
||||
if( !slog_is() )
|
||||
return;
|
||||
|
||||
i.res = (slog_last_type == loginfo);
|
||||
}
|
||||
|
||||
|
||||
void slog_tab_is_warning(Info & i)
|
||||
{
|
||||
if( !slog_is() )
|
||||
return;
|
||||
|
||||
i.res = (slog_last_type == logwarning);
|
||||
}
|
||||
|
||||
|
||||
void slog_tab_is_error(Info & i)
|
||||
{
|
||||
if( !slog_is() )
|
||||
return;
|
||||
|
||||
i.res = (slog_last_type == logerror);
|
||||
}
|
||||
|
||||
|
||||
void slog_tab_print(Info & i)
|
||||
{
|
||||
if( !slog_is() )
|
||||
return;
|
||||
|
||||
TextStream<std::wstring> & buf = cur->session->log_buffer;
|
||||
|
||||
while( slog_index < buf.Size() && buf[slog_index]!=10 )
|
||||
{
|
||||
i.out << buf[slog_index];
|
||||
slog_index += 1;
|
||||
}
|
||||
|
||||
// don't skip the last '\n' here
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
Reference in New Issue
Block a user