Repository navigation
Replace hardcoded logging config with classpath-based Log4j2 auto-discovery - #1406
arturowczarek wants to merge 1 commit into
Conversation
… 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]>
57db83d to
8911c18
Compare
|
@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. |
timothyw553
left a comment
There was a problem hiding this comment.
I left some review comments, please take a look :) @arturowczarek
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
| 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 |
There was a problem hiding this comment.
perhaps can we rename this to examples/cli/src/main/resources/log4j2-cli.properties
There was a problem hiding this comment.
can we rename this to examples/cli/src/main/resources/log4j2-server.properties
| ```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 |
There was a problem hiding this comment.
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-serverJAVA_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 |
There was a problem hiding this comment.
should it be like this?
| 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").toSeqThere was a problem hiding this comment.
and add a test asserting the effective logger level with and without the override
PR Checklist
docsis updatedDescription 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 toetc/conf/server.log4j2.propertiesviaConfigurator.initialize(). This caused severalproblems:
etc/conf/path was fragile — broke when CWD wasn't the project root (IDE runs, Docker, embedding the server as a library)etc/logs/server.logwhere nobody checked during test runsChanges
Core logging changes:
static {}blocks andConfiguratorimport fromUnityCatalogServerandUnityCatalogCliserver/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)server/src/test/resources/log4j2-test.properties— console-only, quieter config auto-discovered by Log4j2's naming conventionexamples/cli/src/main/resources/log4j2.properties— console-only config for CLIDependency fixes in
build.sbt:slf4j-log4j12(Log4j 1.x bridge that conflicted with the Log4j2 setup)log4j-core(required runtime dependency, was only transitively available)Helm chart updates:
log4j2ConfigTemplatefrom_config.tpland its ConfigMap entry. How Helm uses the defaultenvsubststep forserver.log4j2.propertiesin init containerJAVA_OPTSenv var with-Duc.log.levelto the server container, driven by existingserver.logLevelHelm value.Removed files:
etc/conf/server.log4j2.propertiesetc/conf/cli.log4j2.propertiesThey are no longer needed. Either the auto-discovered defaults are used or the ones configured as system properties.
Test plan
sbt compilepassessbt "server/testOnly io.unitycatalog.server.sdk.catalog.SdkCatalogCRUDTest"passeswith correct console output (UC logs at INFO, Hibernate/H2 quiet)
JAVA_OPTS=-Duc.log.level=debug bin/start-uc-serverproduces debug outputbin/start-uc-serverwithout JAVA_OPTS uses info level defaults.testis usedhelm templatedry-run)