Skip to content

Commit

Permalink
Fix always written log. Now written only if trace=on or debug build (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
proller authored Jun 11, 2019
1 parent e445790 commit 2b553fb
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 38 deletions.
5 changes: 4 additions & 1 deletion debian/.pbuilderrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
#
# ubuntu:
# prepare old (trusty or earlier) host system:

# sudo ln -s gutsy /usr/share/debootstrap/scripts/eoan
# sudo ln -s gutsy /usr/share/debootstrap/scripts/disco
# sudo ln -s gutsy /usr/share/debootstrap/scripts/cosmic
# sudo ln -s gutsy /usr/share/debootstrap/scripts/artful
# sudo ln -s gutsy /usr/share/debootstrap/scripts/bionic
# sudo ln -s sid /usr/share/debootstrap/scripts/buster
# build ubuntu:
# sudo DIST=trusty pbuilder create --configfile debian/.pbuilderrc && DIST=trusty pdebuild --configfile debian/.pbuilderrc
# sudo DIST=xenial pbuilder create --configfile debian/.pbuilderrc && DIST=xenial pdebuild --configfile debian/.pbuilderrc
Expand Down Expand Up @@ -56,7 +59,7 @@ DEBIAN_SUITES=($UNSTABLE_CODENAME $TESTING_CODENAME $STABLE_CODENAME $STABLE_BAC
"experimental" "unstable" "testing" "stable")

# List of Ubuntu suites. Update these when needed.
UBUNTU_SUITES=("disco" "cosmic" "bionic" "artful" "zesty" "xenial" "trusty" "devel")
UBUNTU_SUITES=("eoan" "disco" "cosmic" "bionic" "artful" "zesty" "xenial" "trusty" "devel")

# Set a default distribution if none is used. Note that you can set your own default (i.e. ${DIST:="unstable"}).
HOST_DIST=`lsb_release --short --codename`
Expand Down
6 changes: 5 additions & 1 deletion driver/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,13 @@ void Connection::loadConfiguration() {
auto str = stringFromMYTCHAR(ci.trace);
if (!str.empty())
log_enabled = !(str == "0" || str == "No" || str == "no");
if (log_enabled && !tracefile.empty() && tracefile != log_file) {
if (log_enabled && !tracefile.empty() && (tracefile != log_file || !log_stream.is_open())) {
log_file = tracefile;
log_stream = std::ofstream(log_file, std::ios::out | std::ios::app);
if (!log_header.empty()) {
LOG(log_header);
log_header.clear();
}
}
}
if (url.empty())
Expand Down
33 changes: 18 additions & 15 deletions driver/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,46 +79,49 @@ Environment::Environment() {
LOG(std::endl << mbstr);
}

std::string report;
report += " VERSION=" + std::string {VERSION_STRING};
log_header = " === Driver started ===";
log_header += " VERSION=" + std::string {VERSION_STRING};
#if defined(_win64_)
report += " WIN64";
log_header += " WIN64";
#elif defined(_win32_)
report += " WIN32";
log_header += " WIN32";
#endif
#if ODBC_IODBC
report += " ODBC_IODBC";
log_header += " ODBC_IODBC";
#endif
#if ODBC_CHAR16
report += " ODBC_CHAR16";
log_header += " ODBC_CHAR16";
#endif
#if ODBC_UNIXODBC
report += " ODBC_UNIXODBC";
log_header += " ODBC_UNIXODBC";
#endif

#if defined(UNICODE)
report += " UNICODE=" + std::to_string(UNICODE);
log_header += " UNICODE=" + std::to_string(UNICODE);
# if defined(ODBC_WCHAR)
report += " ODBC_WCHAR=" + std::to_string(ODBC_WCHAR);
log_header += " ODBC_WCHAR=" + std::to_string(ODBC_WCHAR);
# endif
report += " sizeof(SQLTCHAR)=" + std::to_string(sizeof(SQLTCHAR)) + " sizeof(wchar_t)=" + std::to_string(sizeof(wchar_t));
log_header += " sizeof(SQLTCHAR)=" + std::to_string(sizeof(SQLTCHAR)) + " sizeof(wchar_t)=" + std::to_string(sizeof(wchar_t));
#endif
#if defined(SQL_WCHART_CONVERT)
report += " SQL_WCHART_CONVERT";
log_header += " SQL_WCHART_CONVERT";
#endif
#if ODBCVER
std::stringstream strm;
strm << " ODBCVER=" << std::hex << ODBCVER << std::dec;
report += strm.str();
log_header += strm.str();
#endif
#if defined(ODBC_LIBRARIES)
report += " ODBC_LIBRARIES=" + std::string {ODBC_LIBRARIES};
log_header += " ODBC_LIBRARIES=" + std::string {ODBC_LIBRARIES};
#endif
#if defined(ODBC_INCLUDE_DIRECTORIES)
report += " ODBC_INCLUDE_DIRECTORIES=" + std::string {ODBC_INCLUDE_DIRECTORIES};
log_header += " ODBC_INCLUDE_DIRECTORIES=" + std::string {ODBC_INCLUDE_DIRECTORIES};
#endif

LOG(" === Driver started ===" << report);
if (log_stream.is_open()) {
LOG(log_header);
log_header.clear();
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion driver/log/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ bool log_enabled =
;

std::string log_file = LOG_DEFAULT_FILE;
std::ofstream log_stream(log_file, std::ios::out | std::ios::app);
std::ofstream log_stream = log_enabled ? std::ofstream(log_file, std::ios::out | std::ios::app) : std::ofstream();
std::string log_header;

std::chrono::high_resolution_clock hr_clock;

Expand Down
6 changes: 4 additions & 2 deletions driver/log/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ extern bool log_enabled;

extern std::ofstream log_stream;
extern std::string log_file;
extern std::string log_header;

std::ostream & log_prefix(std::ofstream & stream);

#define LOG(message) \
do { \
if (log_enabled) \
if (log_enabled) { \
log_prefix(log_stream); \
log_stream << __FILE__ << ":" << __LINE__ << " " << message << std::endl; \
log_stream << __FILE__ << ":" << __LINE__ << " " << message << std::endl; \
} \
} while (false)
3 changes: 2 additions & 1 deletion driver/read_helpers.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "read_helpers.h"

#include <stdexcept>

void readSize(std::istream & istr, int32_t & res) {
Expand All @@ -20,5 +21,5 @@ void readString(std::istream & istr, std::string & res, bool * is_null) {
}

if (!istr.good())
throw std::runtime_error("Incomplete result received.");
throw std::runtime_error("Incomplete result received. Want size=" + std::to_string(size) + ".");
}
4 changes: 0 additions & 4 deletions driver/result_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,3 @@ bool ResultSet::readNextBlock() {
iterator = current_block.data.begin();
return !current_block.data.empty();
}

void ResultSet::throwIncompleteResult() const {
throw std::runtime_error("Incomplete result received.");
}
2 changes: 0 additions & 2 deletions driver/result_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ class ResultSet {
private:
std::istream & in();

void throwIncompleteResult() const;

bool readNextBlock();
bool readNextBlockCache();

Expand Down
3 changes: 0 additions & 3 deletions driver/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ RETCODE fillOutputStringImpl(
*out_value_length = symbols;
}

LOG("fillOutputStringImpl: " << symbols << " = " /* << value*/ );


if (out_value_max_length < 0)
return SQL_ERROR;

Expand Down
8 changes: 4 additions & 4 deletions test/test_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
set -x

cd ..
for compiler in "" _gcc _clang; do
for compiler in ${USE_COMPILER=_gcc _clang}; do
if [ "$compiler" = "_clang" ]; then
CMAKE_COMPILER_FLAGS="-DCMAKE_CXX_COMPILER=`which clang++-7 clang++-6.0 clang++-5.0 clang++60 clang++50 clang++ | head -n1` -DCMAKE_C_COMPILER=`which clang-7 clang-6.0 clang-5.0 clang60 clang50 clang | head -n1`"
CMAKE_COMPILER_FLAGS="-DCMAKE_CXX_COMPILER=`which clang++-8 clang++-7 clang++-6.0 clang++-5.0 clang++60 clang++50 clang++ | head -n1` -DCMAKE_C_COMPILER=`which clang-8 clang-7 clang-6.0 clang-5.0 clang60 clang50 clang | head -n1`"
fi
if [ "$compiler" = "_gcc" ]; then
CMAKE_COMPILER_FLAGS="-DCMAKE_CXX_COMPILER=`which g++-8 g++-7 g++8 g++7 g++ | head -n1` -DCMAKE_C_COMPILER=`which gcc-8 gcc-7 gcc8 gcc7 gcc | head -n1`"
CMAKE_COMPILER_FLAGS="-DCMAKE_CXX_COMPILER=`which g++-9 g++-8 g++-7 g++9 g++8 g++7 g++ | head -n1` -DCMAKE_C_COMPILER=`which gcc-9 gcc-8 gcc-7 gcc9 gcc8 gcc7 gcc | head -n1`"
fi
for type in ${USE_TYPES=debug asan tsan ubsan release relwithdebinfo}; do
for type in ${USE_TYPE=debug asan tsan ubsan release relwithdebinfo}; do
for option in ""; do
CTEST_ENV0=""
if [ "$type" = "asan" ]; then
Expand Down
7 changes: 3 additions & 4 deletions test/test_unicode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ elif [ `which apt` ]; then
sudo apt install -y unixodbc-dev unixodbc
fi
fi

for compiler in ""; do
if [ "$compiler" = "_clang" ]; then
CMAKE_COMPILER_FLAGS="-DCMAKE_CXX_COMPILER=`which clang++-6.0 clang++-5.0 clang++60 clang++50 clang++ | head -n1` -DCMAKE_C_COMPILER=`which clang-6.0 clang-5.0 clang60 clang50 clang | head -n1`"
CMAKE_COMPILER_FLAGS="-DCMAKE_CXX_COMPILER=`which clang++-8 clang++-7 clang++-6.0 clang++-5.0 clang++60 clang++50 clang++ | head -n1` -DCMAKE_C_COMPILER=`which clang-8 clang-7 clang-6.0 clang-5.0 clang60 clang50 clang | head -n1`"
fi
if [ "$compiler" = "_gcc" ]; then
CMAKE_COMPILER_FLAGS="-DCMAKE_CXX_COMPILER=`which g++-8 g++-7 g++8 g++7 g++ | head -n1` -DCMAKE_C_COMPILER=`which gcc-7 gcc-8 gcc8 gcc7 gcc | head -n1`"
CMAKE_COMPILER_FLAGS="-DCMAKE_CXX_COMPILER=`which g++-9 g++-8 g++-7 g++9 g++8 g++7 g++ | head -n1` -DCMAKE_C_COMPILER=`which gcc-9 gcc-8 gcc-7 gcc9 gcc8 gcc7 gcc | head -n1`"
fi
for type in debug; do
for type in ${USE_TYPE=debug}; do
for option in ""; do
build_dir=build${compiler}_$type$option
echo build $compiler $type $option in ${build_dir}
Expand Down

0 comments on commit 2b553fb

Please sign in to comment.