Skip to content

Commit 8d4e38c

Browse files
Patch Logger (#2117)
<!-- REMOVE IRRELEVANT COMMENTS BEFORE CREATING A PULL REQUEST --> ## Changes <!-- Summary of your changes that are easy to understand. Add screenshots when necessary, they're helpful to illustrate the before and after state --> ### What does this PR do? An Attempt to improve current info logging and fix failing tests since pytest default the level to warn instead of debug which is required by the test. ### Relevant implementation details ### Caveats/things to watch out for when reviewing: ### Linked issues <!-- DOC: Link issue with a keyword: close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved. See https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword --> Resolves #.. closes #2116 ### Functionality - [ ] added relevant user documentation - [ ] added new CLI command - [ ] modified existing command: `databricks labs lakebridge ...` - [ ] ... +add your own ### Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [ ] manually tested - [ ] added unit tests - [ ] added integration tests
1 parent 3d54bc0 commit 8d4e38c

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/databricks/labs/lakebridge/base_install.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import sys
22

3-
from databricks.labs.blueprint.logger import install_logger
4-
from databricks.labs.blueprint.entrypoint import get_logger
53
from databricks.sdk.core import with_user_agent_extra
64

75
from databricks.labs.lakebridge.cli import lakebridge
@@ -10,11 +8,9 @@
108

119

1210
def main() -> None:
13-
install_logger()
1411
with_user_agent_extra("cmd", "install")
1512

16-
logger = get_logger(__file__)
17-
logger.setLevel("INFO")
13+
logger = lakebridge.get_logger()
1814

1915
installer = _installer(
2016
ws=lakebridge.create_workspace_client(),

src/databricks/labs/lakebridge/cli.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from databricks.sdk import WorkspaceClient
1616

1717
from databricks.labs.blueprint.cli import App
18-
from databricks.labs.blueprint.entrypoint import get_logger, is_in_debug
18+
from databricks.labs.blueprint.entrypoint import is_in_debug
1919
from databricks.labs.blueprint.installation import RootJsonValue, JsonObject, JsonValue
2020
from databricks.labs.blueprint.tui import Prompts
2121

@@ -43,6 +43,8 @@
4343

4444
# Subclass to allow controlled access to protected methods.
4545
class Lakebridge(App):
46+
_logger_instance: logging.Logger | None = None
47+
4648
def create_workspace_client(self) -> WorkspaceClient:
4749
"""Create a workspace client, with the appropriate product and version information.
4850
@@ -51,9 +53,15 @@ def create_workspace_client(self) -> WorkspaceClient:
5153
self._patch_databricks_host()
5254
return self._workspace_client()
5355

56+
def get_logger(self) -> logging.Logger:
57+
if self._logger_instance is None:
58+
self._logger_instance = self._logger
59+
self._logger_instance.setLevel(logging.INFO)
60+
return self._logger_instance
61+
5462

5563
lakebridge = Lakebridge(__file__)
56-
logger = get_logger(__file__)
64+
logger = lakebridge.get_logger()
5765

5866

5967
def raise_validation_exception(msg: str) -> NoReturn:
@@ -811,6 +819,8 @@ def analyze(
811819

812820

813821
if __name__ == "__main__":
814-
lakebridge()
822+
app = lakebridge
823+
logger = app.get_logger()
815824
if is_in_debug():
816825
logger.setLevel(logging.DEBUG)
826+
app()

tests/unit/test_install.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,8 @@ def test_no_reconfigure_if_noninteractive(
15491549
),
15501550
)
15511551

1552+
logging.getLogger("databricks.labs.lakebridge").setLevel(logging.DEBUG)
1553+
15521554
installer = ws_installer(
15531555
ctx.workspace_client,
15541556
ctx.prompts,

0 commit comments

Comments
 (0)