Skip to content

Replace hardcoded logging config with classpath-based Log4j2 auto-discovery - #1406

Open
arturowczarek wants to merge 1 commit into
unitycatalog:mainfrom
arturowczarek:fix-logging
Open

arturowczarek wants to merge 1 commit into
unitycatalog:mainfrom
arturowczarek:fix-logging

Conversation

@arturowczarek

@arturowczarek arturowczarek commented Mar 19, 2026 •

Copy link
Copy Markdown

PR Checklist

  • A description of the changes is added to the description of this PR.
  • If there is a related issue, make sure it is linked to this PR.
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added or modified a feature, documentation in docs is updated

Description of changes

Replace hardcoded logging config with classpath-based Log4j2 auto-discovery

Solves #1407


The server and CLI used static {} initializer blocks to hardcode Log4j2 configuration to
etc/conf/server.log4j2.properties via Configurator.initialize(). This caused several
problems:

  • Tests had no control over logging — the static block fired on class load, locking logging to a production file-based config with no console output
  • Relative etc/conf/ path was fragile — broke when CWD wasn't the project root (IDE runs, Docker, embedding the server as a library)
  • No runtime configurability — changing log level or directory required editing a file; no system property overrides
  • Errors hidden in tests — the file-only appender wrote to etc/logs/server.log where nobody checked during test runs

Changes

Core logging changes:

  • Remove static {} blocks and Configurator import from UnityCatalogServer and UnityCatalogCli
  • Add server/src/main/resources/log4j2.properties — classpath-based config with console + rolling file appenders, system property overrides (uc.log.level, uc.log.dir), and per-package level tuning for noisy libraries (Hibernate, H2, Armeria)
  • Add server/src/test/resources/log4j2-test.properties — console-only, quieter config auto-discovered by Log4j2's naming convention
  • Add examples/cli/src/main/resources/log4j2.properties — console-only config for CLI

Dependency fixes in build.sbt:

  • Remove slf4j-log4j12 (Log4j 1.x bridge that conflicted with the Log4j2 setup)
  • Add log4j-core (required runtime dependency, was only transitively available)

Helm chart updates:

  • Remove log4j2ConfigTemplate from _config.tpl and its ConfigMap entry. How Helm uses the default
  • Remove envsubst step for server.log4j2.properties in init container
  • Add JAVA_OPTS env var with -Duc.log.level to the server container, driven by existing server.logLevel Helm value.

Removed files:

  • etc/conf/server.log4j2.properties
  • etc/conf/cli.log4j2.properties
    They are no longer needed. Either the auto-discovered defaults are used or the ones configured as system properties.

Test plan

  • sbt compile passes
  • sbt "server/testOnly io.unitycatalog.server.sdk.catalog.SdkCatalogCRUDTest" passes
    with correct console output (UC logs at INFO, Hibernate/H2 quiet)
  • Verify JAVA_OPTS=-Duc.log.level=debug bin/start-uc-server produces debug output
  • Verify bin/start-uc-server without JAVA_OPTS uses info level defaults
  • When used in other project the configuration file with .test is used
  • Helm template renders correctly (helm template dry-run)

@arturowczarek
arturowczarek marked this pull request as draft March 19, 2026 08:51
… paths

Replace the static initializer blocks in UnityCatalogServer and UnityCatalogCli that hardcoded etc/conf/*.log4j2.properties paths with standard Log4j2 classpath-based auto-discovery. This makes logging configurable via system properties (-Duc.log.level, -Duc.log.dir) and gives tests a dedicated console-only config.

Signed-off-by: Artur Owczarek <[email protected]>
@arturowczarek arturowczarek changed the title Make logging more configurable Replace hardcoded logging config with classpath-based Log4j2 auto-discovery Mar 19, 2026
@arturowczarek
arturowczarek marked this pull request as ready for review March 19, 2026 10:39
@arturowczarek

Copy link
Copy Markdown
Author

@openinx Do you mind doing a review and merging it? Logging has been set up in the second commit in this repository and deserves an update.

@yili-db
yili-db requested review from openinx and timothyw553 July 31, 2026 23:43

@timothyw553 timothyw553 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some review comments, please take a look :) @arturowczarek

Comment on lines +13 to +14
appender.rolling.fileName = ${sys:uc.log.dir:-logs}/server.log
appender.rolling.filePattern = ${sys:uc.log.dir:-logs}/server-%d{yyyy-MM-dd}-%i.log.gz

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is $HOME/logs writable by the runtime user? I'm not totally sure, could you verify or perhaps write to $HOME/etc? and could you add a packaged-image test that starts the server and verifies the log file is created.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
appender.rolling.fileName = ${sys:uc.log.dir:-logs}/server.log
appender.rolling.filePattern = ${sys:uc.log.dir:-logs}/server-%d{yyyy-MM-dd}-%i.log.gz
appender.rolling.fileName = ${sys:uc.log.dir:-etc/logs}/server.log
appender.rolling.filePattern = ${sys:uc.log.dir:-etc/logs}/server-%d{yyyy-MM-dd}-%i.log.gz

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps can we rename this to examples/cli/src/main/resources/log4j2-cli.properties

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we rename this to examples/cli/src/main/resources/log4j2-server.properties

Comment thread docs/server/logging.md
Comment on lines +17 to +44
```sh
bin/start-uc-server -Duc.log.level=debug
```

Or, when running the server directly with Java:

```sh
java -Duc.log.level=debug -jar server.jar
```

Supported levels (from most to least verbose): `trace`, `debug`, `info`, `warn`, `error`.

## Changing the Log Directory

By default, log files are written to `logs/` relative to the working directory. Override
this with the `uc.log.dir` system property:

```sh
bin/start-uc-server -Duc.log.dir=/var/log/unitycatalog
```

## Using a Custom Configuration File

For full control over logging (appenders, filters, per-package levels), provide your own
Log4j2 configuration file using the standard `log4j.configurationFile` system property:

```sh
bin/start-uc-server -Dlog4j.configurationFile=/path/to/my-log4j2.properties

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should it be JAVA_OPTS="-Duc.log.level=debug" bin/start-uc-server for example? and for others

  • JAVA_OPTS="-Duc.log.dir=/var/log/unitycatalog" bin/start-uc-server
  • JAVA_OPTS="-Duc.log.level=debug" bin/uc <command>
  • CLI_JAVA_COMMAND="java $JAVA_OPTS -cp $(cat "$1") io.unitycatalog.cli.UnityCatalogCli"


# UC server logs at info level during tests
logger.uc.name = io.unitycatalog
logger.uc.level = info

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be like this?

Suggested change
logger.uc.level = info
logger.uc.level = ${sys:uc.log.level:-info}

and perhaps change build.sbt correspondingly

  Test / javaOptions ++=
    sys.props.get("uc.log.level").map(v => s"-Duc.log.level=$v").toSeq

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and add a test asserting the effective logger level with and without the override

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants