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

Machine friendly logs #68

Closed
1 task
nirs opened this issue Jan 14, 2025 · 0 comments · Fixed by #69
Closed
1 task

Machine friendly logs #68

nirs opened this issue Jan 14, 2025 · 0 comments · Fixed by #69
Labels
enhancement New feature or request
Milestone

Comments

@nirs
Copy link
Owner

nirs commented Jan 14, 2025

When kubectl gather is run by another program, it will be useful to be able to log the gather logs in the program. The text log format makes this harder to do. Providing json format logs will make this very easy to consume by another program.

Similar lima change:
lima-vm/lima#2584

Tasks:

  • Add a --log-format option with "text" (default) and "json" options
nirs added a commit that referenced this issue Jan 14, 2025
Add --log-format with "text" (default) and "json" options. When using
text format we disable caller info and stacktraces in the console logs
bug keep them enabled in the log file. When using json logs we enable
everything so a program can consume what it needs.

Replace the DevelopmentConfig with ProductionConfig that have nicer keys
(e.g. "level" instead of "L").

Example text logs (default):

    % ./kubectl-gather --contexts dr1,dr2,hub --log-format text -d gather.text
    2025-01-14T16:33:01.901+0200	INFO	gather	Using kubeconfig "/Users/nir/.kube/config"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from all namespaces
    2025-01-14T16:33:01.904+0200	INFO	gather	Using all addons
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "dr1"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "dr2"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "hub"
    2025-01-14T16:33:03.445+0200	INFO	gather	Gathered 1167 resources from cluster "hub" in 1.541 seconds
    2025-01-14T16:33:04.397+0200	INFO	gather	Gathered 1294 resources from cluster "dr2" in 2.493 seconds
    2025-01-14T16:33:04.399+0200	INFO	gather	Gathered 1258 resources from cluster "dr1" in 2.495 seconds
    2025-01-14T16:33:04.399+0200	INFO	gather	Gathered 3719 resources from 3 clusters in 2.495 seconds

Example json logs:

    % ./kubectl-gather --contexts dr1,dr2,hub --log-format json -d gather.json
    {"level":"INFO","ts":"2025-01-14T16:33:11.725+0200","logger":"gather","msg":"Using kubeconfig \"/Users/nir/.kube/config\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from all namespaces"}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Using all addons"}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"dr1\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"dr2\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"hub\""}
    {"level":"INFO","ts":"2025-01-14T16:33:13.134+0200","logger":"gather","msg":"Gathered 1167 resources from cluster \"hub\" in 1.408 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.439+0200","logger":"gather","msg":"Gathered 1298 resources from cluster \"dr2\" in 2.712 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.445+0200","logger":"gather","msg":"Gathered 1262 resources from cluster \"dr1\" in 2.718 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.445+0200","logger":"gather","msg":"Gathered 3727 resources from 3 clusters in 2.718 seconds"}

Fixes #68
nirs added a commit that referenced this issue Jan 14, 2025
Add --log-format with "text" (default) and "json" options. When using
text format we disable caller info and stacktraces in the console logs
bug keep them enabled in the log file. When using json logs we enable
everything so a program can consume what it needs.

Replace the DevelopmentConfig with ProductionConfig that have nicer keys
(e.g. "level" instead of "L").

Example text logs (default):

    % ./kubectl-gather --contexts dr1,dr2,hub --log-format text -d gather.text
    2025-01-14T16:33:01.901+0200	INFO	gather	Using kubeconfig "/Users/nir/.kube/config"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from all namespaces
    2025-01-14T16:33:01.904+0200	INFO	gather	Using all addons
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "dr1"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "dr2"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "hub"
    2025-01-14T16:33:03.445+0200	INFO	gather	Gathered 1167 resources from cluster "hub" in 1.541 seconds
    2025-01-14T16:33:04.397+0200	INFO	gather	Gathered 1294 resources from cluster "dr2" in 2.493 seconds
    2025-01-14T16:33:04.399+0200	INFO	gather	Gathered 1258 resources from cluster "dr1" in 2.495 seconds
    2025-01-14T16:33:04.399+0200	INFO	gather	Gathered 3719 resources from 3 clusters in 2.495 seconds

Example json logs:

    % ./kubectl-gather --contexts dr1,dr2,hub --log-format json -d gather.json
    {"level":"INFO","ts":"2025-01-14T16:33:11.725+0200","logger":"gather","msg":"Using kubeconfig \"/Users/nir/.kube/config\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from all namespaces"}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Using all addons"}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"dr1\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"dr2\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"hub\""}
    {"level":"INFO","ts":"2025-01-14T16:33:13.134+0200","logger":"gather","msg":"Gathered 1167 resources from cluster \"hub\" in 1.408 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.439+0200","logger":"gather","msg":"Gathered 1298 resources from cluster \"dr2\" in 2.712 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.445+0200","logger":"gather","msg":"Gathered 1262 resources from cluster \"dr1\" in 2.718 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.445+0200","logger":"gather","msg":"Gathered 3727 resources from 3 clusters in 2.718 seconds"}

Fixes #68
nirs added a commit that referenced this issue Jan 14, 2025
Add --log-format with "text" (default) and "json" options. When using
text format we disable caller info and stacktraces in the console logs
bug keep them enabled in the log file. When using json logs we enable
everything so a program can consume what it needs.

Replace the DevelopmentConfig with ProductionConfig that have nicer keys
(e.g. "level" instead of "L").

Example text logs (default):

    % ./kubectl-gather --contexts dr1,dr2,hub --log-format text -d gather.text
    2025-01-14T16:33:01.901+0200	INFO	gather	Using kubeconfig "/Users/nir/.kube/config"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from all namespaces
    2025-01-14T16:33:01.904+0200	INFO	gather	Using all addons
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "dr1"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "dr2"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "hub"
    2025-01-14T16:33:03.445+0200	INFO	gather	Gathered 1167 resources from cluster "hub" in 1.541 seconds
    2025-01-14T16:33:04.397+0200	INFO	gather	Gathered 1294 resources from cluster "dr2" in 2.493 seconds
    2025-01-14T16:33:04.399+0200	INFO	gather	Gathered 1258 resources from cluster "dr1" in 2.495 seconds
    2025-01-14T16:33:04.399+0200	INFO	gather	Gathered 3719 resources from 3 clusters in 2.495 seconds

Example json logs:

    % ./kubectl-gather --contexts dr1,dr2,hub --log-format json -d gather.json
    {"level":"INFO","ts":"2025-01-14T16:33:11.725+0200","logger":"gather","msg":"Using kubeconfig \"/Users/nir/.kube/config\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from all namespaces"}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Using all addons"}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"dr1\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"dr2\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"hub\""}
    {"level":"INFO","ts":"2025-01-14T16:33:13.134+0200","logger":"gather","msg":"Gathered 1167 resources from cluster \"hub\" in 1.408 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.439+0200","logger":"gather","msg":"Gathered 1298 resources from cluster \"dr2\" in 2.712 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.445+0200","logger":"gather","msg":"Gathered 1262 resources from cluster \"dr1\" in 2.718 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.445+0200","logger":"gather","msg":"Gathered 3727 resources from 3 clusters in 2.718 seconds"}

Fixes #68
nirs added a commit that referenced this issue Jan 14, 2025
Add --log-format with "text" (default) and "json" options. When using
text format we disable caller info and stacktraces in the console logs
bug keep them enabled in the log file. When using json logs we enable
everything so a program can consume what it needs.

Replace the DevelopmentConfig with ProductionConfig that have nicer keys
(e.g. "level" instead of "L").

Example text logs (default):

    % ./kubectl-gather --contexts dr1,dr2,hub --log-format text -d gather.text
    2025-01-14T16:33:01.901+0200	INFO	gather	Using kubeconfig "/Users/nir/.kube/config"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from all namespaces
    2025-01-14T16:33:01.904+0200	INFO	gather	Using all addons
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "dr1"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "dr2"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "hub"
    2025-01-14T16:33:03.445+0200	INFO	gather	Gathered 1167 resources from cluster "hub" in 1.541 seconds
    2025-01-14T16:33:04.397+0200	INFO	gather	Gathered 1294 resources from cluster "dr2" in 2.493 seconds
    2025-01-14T16:33:04.399+0200	INFO	gather	Gathered 1258 resources from cluster "dr1" in 2.495 seconds
    2025-01-14T16:33:04.399+0200	INFO	gather	Gathered 3719 resources from 3 clusters in 2.495 seconds

Example json logs:

    % ./kubectl-gather --contexts dr1,dr2,hub --log-format json -d gather.json
    {"level":"INFO","ts":"2025-01-14T16:33:11.725+0200","logger":"gather","msg":"Using kubeconfig \"/Users/nir/.kube/config\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from all namespaces"}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Using all addons"}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"dr1\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"dr2\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"hub\""}
    {"level":"INFO","ts":"2025-01-14T16:33:13.134+0200","logger":"gather","msg":"Gathered 1167 resources from cluster \"hub\" in 1.408 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.439+0200","logger":"gather","msg":"Gathered 1298 resources from cluster \"dr2\" in 2.712 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.445+0200","logger":"gather","msg":"Gathered 1262 resources from cluster \"dr1\" in 2.718 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.445+0200","logger":"gather","msg":"Gathered 3727 resources from 3 clusters in 2.718 seconds"}

Fixes #68
@nirs nirs added the enhancement New feature or request label Jan 14, 2025
@nirs nirs added this to the v0.6.0 milestone Jan 14, 2025
nirs added a commit that referenced this issue Jan 14, 2025
Add --log-format with "text" (default) and "json" options. When using
text format we disable caller info and stacktraces in the console logs
bug keep them enabled in the log file. When using json logs we enable
everything so a program can consume what it needs.

Replace the DevelopmentConfig with ProductionConfig that have nicer keys
(e.g. "level" instead of "L").

Example text logs (default):

    % ./kubectl-gather --contexts dr1,dr2,hub --log-format text -d gather.text
    2025-01-14T16:33:01.901+0200	INFO	gather	Using kubeconfig "/Users/nir/.kube/config"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from all namespaces
    2025-01-14T16:33:01.904+0200	INFO	gather	Using all addons
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "dr1"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "dr2"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "hub"
    2025-01-14T16:33:03.445+0200	INFO	gather	Gathered 1167 resources from cluster "hub" in 1.541 seconds
    2025-01-14T16:33:04.397+0200	INFO	gather	Gathered 1294 resources from cluster "dr2" in 2.493 seconds
    2025-01-14T16:33:04.399+0200	INFO	gather	Gathered 1258 resources from cluster "dr1" in 2.495 seconds
    2025-01-14T16:33:04.399+0200	INFO	gather	Gathered 3719 resources from 3 clusters in 2.495 seconds

Example json logs:

    % ./kubectl-gather --contexts dr1,dr2,hub --log-format json -d gather.json
    {"level":"INFO","ts":"2025-01-14T16:33:11.725+0200","logger":"gather","msg":"Using kubeconfig \"/Users/nir/.kube/config\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from all namespaces"}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Using all addons"}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"dr1\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"dr2\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"hub\""}
    {"level":"INFO","ts":"2025-01-14T16:33:13.134+0200","logger":"gather","msg":"Gathered 1167 resources from cluster \"hub\" in 1.408 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.439+0200","logger":"gather","msg":"Gathered 1298 resources from cluster \"dr2\" in 2.712 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.445+0200","logger":"gather","msg":"Gathered 1262 resources from cluster \"dr1\" in 2.718 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.445+0200","logger":"gather","msg":"Gathered 3727 resources from 3 clusters in 2.718 seconds"}

Fixes #68
nirs added a commit that referenced this issue Jan 14, 2025
Add --log-format with "text" (default) and "json" options. When using
text format we disable caller info and stacktraces in the console logs
bug keep them enabled in the log file. When using json logs we enable
everything so a program can consume what it needs.

Replace the DevelopmentConfig with ProductionConfig that have nicer keys
(e.g. "level" instead of "L").

Example text logs (default):

    % ./kubectl-gather --contexts dr1,dr2,hub --log-format text -d gather.text
    2025-01-14T16:33:01.901+0200	INFO	gather	Using kubeconfig "/Users/nir/.kube/config"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from all namespaces
    2025-01-14T16:33:01.904+0200	INFO	gather	Using all addons
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "dr1"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "dr2"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "hub"
    2025-01-14T16:33:03.445+0200	INFO	gather	Gathered 1167 resources from cluster "hub" in 1.541 seconds
    2025-01-14T16:33:04.397+0200	INFO	gather	Gathered 1294 resources from cluster "dr2" in 2.493 seconds
    2025-01-14T16:33:04.399+0200	INFO	gather	Gathered 1258 resources from cluster "dr1" in 2.495 seconds
    2025-01-14T16:33:04.399+0200	INFO	gather	Gathered 3719 resources from 3 clusters in 2.495 seconds

Example json logs:

    % ./kubectl-gather --contexts dr1,dr2,hub --log-format json -d gather.json
    {"level":"INFO","ts":"2025-01-14T16:33:11.725+0200","logger":"gather","msg":"Using kubeconfig \"/Users/nir/.kube/config\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from all namespaces"}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Using all addons"}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"dr1\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"dr2\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"hub\""}
    {"level":"INFO","ts":"2025-01-14T16:33:13.134+0200","logger":"gather","msg":"Gathered 1167 resources from cluster \"hub\" in 1.408 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.439+0200","logger":"gather","msg":"Gathered 1298 resources from cluster \"dr2\" in 2.712 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.445+0200","logger":"gather","msg":"Gathered 1262 resources from cluster \"dr1\" in 2.718 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.445+0200","logger":"gather","msg":"Gathered 3727 resources from 3 clusters in 2.718 seconds"}

Fixes #68
nirs added a commit that referenced this issue Jan 14, 2025
Add --log-format with "text" (default) and "json" options. When using
text format we disable caller info and stacktraces in the console logs
bug keep them enabled in the log file. When using json logs we enable
everything so a program can consume what it needs.

Replace the DevelopmentConfig with ProductionConfig that have nicer keys
(e.g. "level" instead of "L").

Example text logs (default):

    % ./kubectl-gather --contexts dr1,dr2,hub --log-format text -d gather.text
    2025-01-14T16:33:01.901+0200	INFO	gather	Using kubeconfig "/Users/nir/.kube/config"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from all namespaces
    2025-01-14T16:33:01.904+0200	INFO	gather	Using all addons
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "dr1"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "dr2"
    2025-01-14T16:33:01.904+0200	INFO	gather	Gathering from cluster "hub"
    2025-01-14T16:33:03.445+0200	INFO	gather	Gathered 1167 resources from cluster "hub" in 1.541 seconds
    2025-01-14T16:33:04.397+0200	INFO	gather	Gathered 1294 resources from cluster "dr2" in 2.493 seconds
    2025-01-14T16:33:04.399+0200	INFO	gather	Gathered 1258 resources from cluster "dr1" in 2.495 seconds
    2025-01-14T16:33:04.399+0200	INFO	gather	Gathered 3719 resources from 3 clusters in 2.495 seconds

Example json logs:

    % ./kubectl-gather --contexts dr1,dr2,hub --log-format json -d gather.json
    {"level":"INFO","ts":"2025-01-14T16:33:11.725+0200","logger":"gather","msg":"Using kubeconfig \"/Users/nir/.kube/config\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from all namespaces"}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Using all addons"}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"dr1\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"dr2\""}
    {"level":"INFO","ts":"2025-01-14T16:33:11.727+0200","logger":"gather","msg":"Gathering from cluster \"hub\""}
    {"level":"INFO","ts":"2025-01-14T16:33:13.134+0200","logger":"gather","msg":"Gathered 1167 resources from cluster \"hub\" in 1.408 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.439+0200","logger":"gather","msg":"Gathered 1298 resources from cluster \"dr2\" in 2.712 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.445+0200","logger":"gather","msg":"Gathered 1262 resources from cluster \"dr1\" in 2.718 seconds"}
    {"level":"INFO","ts":"2025-01-14T16:33:14.445+0200","logger":"gather","msg":"Gathered 3727 resources from 3 clusters in 2.718 seconds"}

Fixes #68
@nirs nirs closed this as completed in #69 Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant