Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
Expose both java and c++ log paths in pyhdk
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbaden committed Jun 26, 2023
1 parent 8d1ff77 commit 050e17d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ jobs:
- name: Run pytest
run: |
$CONDA/bin/conda run -n ${{ env.CONDA_ENV }} pytest python/tests/ --ignore=python/tests/modin
$CONDA/bin/conda run -n ${{ env.CONDA_ENV }} pytest -s python/tests/ --ignore=python/tests/modin
4 changes: 2 additions & 2 deletions omniscidb/Logger/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ std::string filename(char const* path) {
return boost::filesystem::path(path).filename().string();
}

LogOptions::LogOptions(char const* argv0)
: log_dir_(std::make_unique<boost::filesystem::path>("hdk_log")) {
LogOptions::LogOptions(char const* argv0, const std::string& default_log_path)
: log_dir_(std::make_unique<boost::filesystem::path>(default_log_path)) {
// Log file base_name matches name of program.
std::string const base_name =
argv0 == nullptr ? std::string("omnisci_server") : filename(argv0);
Expand Down
2 changes: 1 addition & 1 deletion omniscidb/Logger/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class LogOptions {
bool rotate_daily_{true};
size_t rotation_size_{10 << 20};

LogOptions(char const* argv0);
LogOptions(char const* argv0, const std::string& default_log_path = "hdk_log");
~LogOptions(); // Needed to allow forward declarations within std::unique_ptr.
boost::filesystem::path full_log_dir() const;
boost::program_options::options_description const& get_options() const;
Expand Down
3 changes: 2 additions & 1 deletion python/pyhdk/_common.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ cdef extern from "omniscidb/Logger/Logger.h" namespace "logger":
_NSEVERITIES = 8

cdef cppclass CLogOptions "logger::LogOptions":
CLogOptions(const char*)
CLogOptions(const char*, const string&)
void parse_command_line(const string&, const string&)
void set_log_dir(const string&)
CSeverity severity_

cdef void CInitLogger "logger::init"(const CLogOptions &)
Expand Down
8 changes: 5 additions & 3 deletions python/pyhdk/_common.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ cdef class TypeInfo:
return self.c_type_info.toString()


def buildConfig(*, enable_debug_timer=None, enable_union=False, **kwargs):
def buildConfig(*, enable_debug_timer=None, enable_union=False, log_dir="hdk_log", **kwargs):
global g_enable_debug_timer
if enable_debug_timer is not None:
g_enable_debug_timer = enable_debug_timer
Expand All @@ -201,12 +201,14 @@ def buildConfig(*, enable_debug_timer=None, enable_union=False, **kwargs):
builder.parseCommandLineArgs(app, cmd_str, False)
cdef Config config = Config()
config.c_config = builder.config()
config.c_config.get().debug.log_dir = log_dir
return config

def initLogger(*, debug_logs=False, **kwargs):
def initLogger(*, debug_logs=False, log_dir="hdk_log", **kwargs):
argv0 = "PyHDK".encode('UTF-8')
cdef char *cargv0 = argv0
cdef unique_ptr[CLogOptions] opts = make_unique[CLogOptions](cargv0)
cdef string default_log_dir = log_dir
cdef unique_ptr[CLogOptions] opts = make_unique[CLogOptions](cargv0, default_log_dir)
cmd_str = "".join(' --%s %r' % arg for arg in kwargs.iteritems())
cmd_str = cmd_str.replace("_", "-")
opts.get().parse_command_line(argv0, cmd_str)
Expand Down
27 changes: 27 additions & 0 deletions python/tests/test_work_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,37 @@
# SPDX-License-Identifier: Apache-2.0

import os
import shutil
import pyhdk
import time
import pytest

import pyhdk


class TestWorkDir:
def test_work_dir(self):
assert os.path.exists(
"python/tests/test_dir_token"
), "Run pytest from the HDK root dir."

def test_log_dir(self):
log_dir = "pyhdk_test_dir"
pyhdk.initLogger(log_dir=log_dir)
assert os.path.exists("pyhdk_test_dir")

# The Calcite initialization test below can fail to detect the log4j.log file when this test is run as part of all other pyhdk tests. Mark it as xfail and expect a failure when run in that context.
@pytest.mark.xfail
def test_calcite_log_dir(self):
log_dir = "pyhdk_test_dir"
config = pyhdk.buildConfig(log_dir=log_dir)
storage = pyhdk.storage.ArrowStorage(1, config)

calcite = pyhdk.sql.Calcite(storage, config)

assert os.path.exists("pyhdk_test_dir")
assert os.path.isfile("pyhdk_test_dir/log4j.log")

@classmethod
def teardown_class(cls):
shutil.rmtree("pyhdk_test_dir")

0 comments on commit 050e17d

Please sign in to comment.