Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log process ID in each log entry #949

Merged
merged 3 commits into from
Nov 8, 2023
Merged

Log process ID in each log entry #949

merged 3 commits into from
Nov 8, 2023

Conversation

ilia-db
Copy link
Contributor

@ilia-db ilia-db commented Nov 6, 2023

Changes

This will help differentiate multiple cli commands that write to the same log file.
Noticed that the root module wasn't using the common log utilities, refactored it to avoid missing log arguments.
Relevant PR on the databricks vscode extension side: databricks/databricks-vscode#923

Tests

Tested manually for sdk and cli loggers

This will help differentiate multiple cli commands that write to the same log file.
Noticed that the root module wasn't using the common log utilities, refactored
it to avoid missing log arguments
cmd/root/root.go Outdated Show resolved Hide resolved
cmd/root/root.go Outdated Show resolved Hide resolved
@@ -25,6 +26,7 @@ func log(logger *slog.Logger, ctx context.Context, level slog.Level, msg string)
// skip [runtime.Callers, this function, this function's caller].
runtime.Callers(3, pcs[:])
r := slog.NewRecord(time.Now(), level, msg, pcs[0])
r.AddAttrs(slog.Int("pid", os.Getpid()))
Copy link
Contributor

Choose a reason for hiding this comment

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

You can cache the slog.Attr. I propose adding a pidAttr function (can be separate file because it is used from 2 places) that uses sync.Once to initialize a global that contains it. The PID doesn't change once a process has started, so it's not necessary to make the system call more than once.

Copy link
Contributor Author

@ilia-db ilia-db Nov 6, 2023

Choose a reason for hiding this comment

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

After reading the code and the docs, I've moved the pid attribute to the cmd/root/logger::initializeContext. With that change we aren't limited to using only our own libs/log/logger wrappers, but can also use logger instances from the context (as we do in the cmd/root)

@ilia-db ilia-db marked this pull request as ready for review November 6, 2023 18:28
@ilia-db ilia-db requested a review from pietern November 7, 2023 08:41
@pietern pietern changed the title Log process id in each log entry Log process ID in each log entry Nov 7, 2023
@ilia-db ilia-db added this pull request to the merge queue Nov 8, 2023
Merged via the queue into main with commit 65dd9c5 Nov 8, 2023
4 checks passed
@ilia-db ilia-db deleted the log-pid branch November 8, 2023 08:57
andrewnester added a commit that referenced this pull request Nov 8, 2023
CLI:
 * Hide `--progress-format` global flag ([#965](#965)).
 * Make configure command visible + fix bundle command description ([#961](#961)).
 * Log process ID in each log entry ([#949](#949)).
 * Improve error message when `--json` flag is specified ([#933](#933)).

Bundles:
 * Remove validation for default value against pattern ([#959](#959)).
 * Bundle path rewrites for dbt and SQL file tasks ([#962](#962)).
 * Initialize variable definitions that are defined without properties ([#966](#966)).

Internal:
 * Remove mention of Lakehouse apps from the changelog ([#945](#945)).
 * Function to merge two instances of `config.Value` ([#938](#938)).
 * Make to/from string methods private to the jsonschema package ([#942](#942)).
 * Make Cobra runner compatible with testing interactive flows ([#957](#957)).
 * Added `env.UserHomeDir(ctx)` for parallel-friendly tests ([#955](#955)).

Dependency updates:
 * Bump golang.org/x/mod from 0.13.0 to 0.14.0 ([#954](#954)).
 * Bump golang.org/x/text from 0.13.0 to 0.14.0 ([#953](#953)).
 * Bump golang.org/x/sync from 0.4.0 to 0.5.0 ([#951](#951)).
 * Bump github.com/spf13/cobra from 1.7.0 to 1.8.0 ([#950](#950)).
 * Bump github.com/fatih/color from 1.15.0 to 1.16.0 ([#952](#952)).
@andrewnester andrewnester mentioned this pull request Nov 8, 2023
github-merge-queue bot pushed a commit that referenced this pull request Nov 8, 2023
CLI:
* Hide `--progress-format` global flag
([#965](#965)).
* Make configure command visible + fix bundle command description
([#961](#961)).
* Log process ID in each log entry
([#949](#949)).
* Improve error message when `--json` flag is specified
([#933](#933)).

Bundles:
* Remove validation for default value against pattern
([#959](#959)).
* Bundle path rewrites for dbt and SQL file tasks
([#962](#962)).
* Initialize variable definitions that are defined without properties
([#966](#966)).

Internal:
* Function to merge two instances of `config.Value`
([#938](#938)).
* Make to/from string methods private to the jsonschema package
([#942](#942)).
* Make Cobra runner compatible with testing interactive flows
([#957](#957)).
* Added `env.UserHomeDir(ctx)` for parallel-friendly tests
([#955](#955)).


Dependency updates:
* Bump golang.org/x/mod from 0.13.0 to 0.14.0
([#954](#954)).
* Bump golang.org/x/text from 0.13.0 to 0.14.0
([#953](#953)).
* Bump golang.org/x/sync from 0.4.0 to 0.5.0
([#951](#951)).
* Bump github.com/spf13/cobra from 1.7.0 to 1.8.0
([#950](#950)).
* Bump github.com/fatih/color from 1.15.0 to 1.16.0
([#952](#952)).
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.

3 participants