Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:eomsoft/teleport into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	server/tp_core/core/main.cpp
#	server/tp_core/core/ts_env.cpp
#	server/tp_core/core/ts_env.h
#	server/www/teleport/app/eom_app/app/db.py
  • Loading branch information
apexliu committed Mar 27, 2017
2 parents 9af9964 + b3a6176 commit c473b19
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 130 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CMakeFiles
cmake_install.cmake
Makefile
cmake-build
cmake-build-debug

# for Python
__pycache__
Expand Down
2 changes: 1 addition & 1 deletion build/build-py-static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
VER_PYTHON="3.4.4"
VER_PYTHON_SHORT="3.4"
VER_OPENSSL="1.0.2h"
VER_SQLITE="3160200"
VER_SQLITE="3170000"
VER_PSUTIL="4.2.0"
VER_PYTHON_LIB="${VER_PYTHON_SHORT}m"

Expand Down
4 changes: 2 additions & 2 deletions common/libex/include/ex/ex_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class ExLogger
bool set_log_file(const ex_wstr& log_path, const ex_wstr& log_name, ex_u32 max_filesize, ex_u8 max_count);
void log_a(int level, const char* fmt, va_list valist);
void log_w(int level, const wchar_t* fmt, va_list valist);
bool write(const char* buf);
bool write(const wchar_t* buf);
bool write_a(const char* buf);
bool write_w(const wchar_t* buf);

protected:
bool _open_file();
Expand Down
120 changes: 73 additions & 47 deletions common/libex/src/ex_log.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
#include <ex/ex_log.h>
#include <ex/ex_path.h>
#include <ex/ex_thread.h>
#include <vector>
#include <deque>
#include <algorithm>
//#include <ex/ex_thread.h>
//#include <vector>
//#include <deque>
//#include <algorithm>

#ifdef EX_OS_WIN32
# include <io.h>
# include <stdio.h>
# include <direct.h>
#else
# include <dirent.h>
# include <sys/time.h>
//# include <dirent.h>
//# include <sys/time.h>
#endif

#define EX_LOG_CONTENT_MAX_LEN 2048

//typedef std::deque<unsigned long long> log_file_deque;

//ExLogger g_ex_logger;
static ExLogger* g_exlog = NULL;//&g_ex_logger;
static ExLogger* g_exlog = NULL;

void EXLOG_USE_LOGGER(ExLogger* logger)
{
// if (NULL == logger)
// g_exlog = &g_ex_logger;
// else
// g_exlog = logger;

g_exlog = logger;
}

Expand Down Expand Up @@ -99,7 +93,7 @@ void ExLogger::log_a(int level, const char* fmt, va_list valist)
return;

char szTmp[4096] = { 0 };
int offset = 0;
size_t offset = 0;

if (level == EX_LOG_LEVEL_ERROR)
{
Expand All @@ -112,22 +106,39 @@ void ExLogger::log_a(int level, const char* fmt, va_list valist)

#ifdef EX_OS_WIN32
vsnprintf_s(szTmp+offset, 4096-offset, 4095-offset, fmt, valist);
if (NULL != console_handle)
{
printf_s("%s", szTmp);
fflush(stdout);
}
else
if(to_console)
{
OutputDebugStringA(szTmp);
if (NULL != console_handle)
{
printf_s("%s", szTmp);
fflush(stdout);
}
else
{
if(debug_mode)
OutputDebugStringA(szTmp);
}
}
#else
vsnprintf(szTmp+offset, 4095-offset, fmt, valist);
printf("%s", szTmp);
fflush(stdout);
if(to_console)
{
// On linux, the stdout only output the first time output format (char or wchar_t).
// e.g.: first time you use printf(), then after that, every wprintf() not work, and vice versa.
// so we always use wprintf() to fix that.

ex_astr tmp(szTmp);
ex_wstr _tmp;
ex_astr2wstr(tmp, _tmp);
wprintf(L"%ls", _tmp.c_str());
fflush(stdout);

// printf("%s", szTmp);
// fflush(stdout);
}
#endif

write(szTmp);
write_a(szTmp);
}

void ExLogger::log_w(int level, const wchar_t* fmt, va_list valist)
Expand All @@ -136,7 +147,7 @@ void ExLogger::log_w(int level, const wchar_t* fmt, va_list valist)
return;

wchar_t szTmp[4096] = { 0 };
int offset = 0;
size_t offset = 0;

if (level == EX_LOG_LEVEL_ERROR)
{
Expand All @@ -149,25 +160,32 @@ void ExLogger::log_w(int level, const wchar_t* fmt, va_list valist)

#ifdef EX_OS_WIN32
_vsnwprintf_s(szTmp+offset, 4096-offset, 4095-offset, fmt, valist);
if (NULL != console_handle)
{
wprintf_s(_T("%s"), szTmp);
fflush(stdout);
}
else
if(to_console)
{
OutputDebugStringW(szTmp);
if (NULL != console_handle)
{
wprintf_s(_T("%s"), szTmp);
fflush(stdout);
}
else
{
if(debug_mode)
OutputDebugStringW(szTmp);
}
}
#else
vswprintf(szTmp+offset, 4095-offset, fmt, valist);
wprintf(L"%ls", szTmp);
fflush(stdout);
if(to_console)
{
wprintf(L"%ls", szTmp);
fflush(stdout);
}
#endif

write(szTmp);
write_w(szTmp);
}

#define EX_PRINTF_X(fn, level) \
#define EX_PRINTF_XA(fn, level) \
void fn(const char* fmt, ...) \
{ \
if(NULL == g_exlog) \
Expand All @@ -179,7 +197,9 @@ void fn(const char* fmt, ...) \
va_start(valist, fmt); \
g_exlog->log_a(level, fmt, valist); \
va_end(valist); \
} \
}

#define EX_PRINTF_XW(fn, level) \
void fn(const wchar_t* fmt, ...) \
{ \
if(NULL == g_exlog) \
Expand All @@ -193,11 +213,17 @@ void fn(const wchar_t* fmt, ...) \
va_end(valist); \
}

EX_PRINTF_X(ex_printf_d, EX_LOG_LEVEL_DEBUG)
EX_PRINTF_X(ex_printf_v, EX_LOG_LEVEL_VERBOSE)
EX_PRINTF_X(ex_printf_i, EX_LOG_LEVEL_INFO)
EX_PRINTF_X(ex_printf_w, EX_LOG_LEVEL_WARN)
EX_PRINTF_X(ex_printf_e, EX_LOG_LEVEL_ERROR)
EX_PRINTF_XA(ex_printf_d, EX_LOG_LEVEL_DEBUG)
EX_PRINTF_XA(ex_printf_v, EX_LOG_LEVEL_VERBOSE)
EX_PRINTF_XA(ex_printf_i, EX_LOG_LEVEL_INFO)
EX_PRINTF_XA(ex_printf_w, EX_LOG_LEVEL_WARN)
EX_PRINTF_XA(ex_printf_e, EX_LOG_LEVEL_ERROR)

EX_PRINTF_XW(ex_printf_d, EX_LOG_LEVEL_DEBUG)
EX_PRINTF_XW(ex_printf_v, EX_LOG_LEVEL_VERBOSE)
EX_PRINTF_XW(ex_printf_i, EX_LOG_LEVEL_INFO)
EX_PRINTF_XW(ex_printf_w, EX_LOG_LEVEL_WARN)
EX_PRINTF_XW(ex_printf_e, EX_LOG_LEVEL_ERROR)


#ifdef EX_OS_WIN32
Expand Down Expand Up @@ -268,7 +294,7 @@ void ex_printf_bin(const ex_u8* bin_data, size_t bin_size, const char* fmt, ...)
unsigned int i = 0;

char szTmp[128] = { 0 };
int _offset = 0;
size_t _offset = 0;

while (offset < bin_size)
{
Expand Down Expand Up @@ -529,7 +555,7 @@ bool ExLogFile::_backup_file()
}
#endif // if 0

bool ExLogger::write(const char* buf)
bool ExLogger::write_a(const char* buf)
{
if (NULL == m_file)
return false;
Expand Down Expand Up @@ -561,7 +587,7 @@ bool ExLogger::write(const char* buf)
return false;
sprintf(szTime, "[%04d-%02d-%02d %02d:%02d:%02d] ", p->tm_year + 1900, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);

int lenTime = strlen(szTime);
size_t lenTime = strlen(szTime);
fwrite(szTime, lenTime, 1, m_file);
m_filesize += lenTime;
fwrite(buf, len, 1, m_file);
Expand All @@ -573,11 +599,11 @@ bool ExLogger::write(const char* buf)
return _rotate_file();
}

bool ExLogger::write(const wchar_t* buf)
bool ExLogger::write_w(const wchar_t* buf)
{
ex_astr _buf;
ex_wstr2astr(buf, _buf, EX_CODEPAGE_UTF8);
return write(_buf.c_str());
return write_a(_buf.c_str());
}


Expand Down
11 changes: 6 additions & 5 deletions server/share/etc/core.ini.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ log-level=0

; 'replay-path' define the replay file location. if not set, default location
; to $INSTDIR%/data/replay/
;replay-path=/usr/local/eom/teleport/data/replay
;replay-path=/var/lib/teleport/data/replay

web-server-rpc=http://127.0.0.1:7190/rpc

[rpc]
; Request by web server. `ip` should be the ip of core server, default to
; 127.0.0.1 because web server and core server running at the same machine.
;ip=127.0.0.1
port=52080
; Request by web server. `bind-ip` should be the ip of core server. If
; web server and core server running at the same machine, it should be
; 127.0.0.1
bind-ip=127.0.0.1
bind-port=52080

[protocol-ssh]
enabled=true
Expand Down
Loading

0 comments on commit c473b19

Please sign in to comment.