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 improvements #1

Open
4 tasks done
dmke opened this issue Mar 16, 2022 · 3 comments
Open
4 tasks done

Log improvements #1

dmke opened this issue Mar 16, 2022 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@dmke
Copy link
Member

dmke commented Mar 16, 2022

From my TODO list:

  • switch to a structured logger (like zap)
  • include X-Request-Id generated in service/middleware/requestid.go
  • add a log line when adding files
  • add --log-level CLI flag to set log level
@dmke dmke added the enhancement New feature or request label Mar 16, 2022
@dmke dmke added this to the v1.0 milestone Mar 16, 2022
dmke added a commit that referenced this issue Mar 17, 2022
- introduce go.uber.org/zap
- introduce --log-level CLI flag
- ensure the request ID is logged

Issue: #1
@dmke
Copy link
Member Author

dmke commented Mar 17, 2022

zap is included since 9447a8d, but I don't like the formatting default console encoding:

2022-03-17T13:40:10.806+0100    INFO    exec/docker_client.go:66        image already present   {"image": "texlive/texlive:latest"}
2022-03-17T13:40:10.806+0100    INFO    service/service.go:80   starting server {"addr": ":2201"}
2022-03-17T13:40:16.904+0100    INFO    tex/document.go:107     adding file     {"request-id": "0767bf4c-a8ee-4832-836f-df6a7d096224", "filename": "chapter/input.tex"}
2022-03-17T13:40:16.905+0100    INFO    tex/document.go:107     adding file     {"request-id": "0767bf4c-a8ee-4832-836f-df6a7d096224", "filename": "input.tex"}
2022-03-17T13:40:16.905+0100    INFO    tex/document.go:151     found \documentclass    {"request-id": "0767bf4c-a8ee-4832-836f-df6a7d096224", "filename": "input.tex"}
2022-03-17T13:40:16.905+0100    INFO    tex/document.go:107     adding file     {"request-id": "0767bf4c-a8ee-4832-836f-df6a7d096224", "filename": "doc.tex"}
2022-03-17T13:40:16.905+0100    DEBUG   exec/docker.go:29       running latexmk {"request-id": "0767bf4c-a8ee-4832-836f-df6a7d096224", "args": ["-cd", "-silent", "-pv-", "-pvc-", "-pdfxe", "input.tex"]}
2022-03-17T13:40:16.961+0100    DEBUG   exec/docker_client.go:188       container is ready      {"id": "dcaeabe514afd96bebd6fd8fe0cd83d36fb725bc9bf01f911e6158d926eb141a", "work-dir": "/tmp/texd-483222946"}
2022-03-17T13:40:18.364+0100    DEBUG   tex/document.go:298     fetching result {"request-id": "0767bf4c-a8ee-4832-836f-df6a7d096224"}

My primary issues are:

  • The timestamp should be removed or at least shortened to "seconds since startup" (like logrus).
  • There's no color. I like color in dev mode.
  • Fields are not aligned.

These issues can be easily addressed using either a custom zapcore.EncoderConfig, or by providing a custom encoder (zap.RegisterEncoder). More importantly, this can be addressed later.

dmke added a commit that referenced this issue Mar 17, 2022
Request ID collisions are not a concern.

Issue: #1
dmke added a commit that referenced this issue Mar 17, 2022
Request ID collisions are not a concern.

Issue: #1
dmke added a commit that referenced this issue Mar 17, 2022
Request ID collisions are not a concern.

Issue: #1
@corny
Copy link
Member

corny commented Sep 13, 2023

Let's switch to the log/slog package for structured logging.

@dmke
Copy link
Member Author

dmke commented Sep 13, 2023

I don't object, but need to find time to do the conversion. Fancy a PR?

dmke added a commit that referenced this issue Jan 25, 2024
This replaces the zap logging engine with Go 1.21's new
structured logger, log/slog, or more precisely a thin
wrapper around that ("xlog").

The log/slog package has a few things missing, which are
present in xlog:

1. xlog provides a no-op logger, which simply discards any
   log output. This is extensively used in our tests.
2. xlog has a Fatal() output method, which simply calls
   Error() and then os.Exit(1).
3. xlog treats error values as first-class citizen. Since
   (log/slog).Error() is a convenience function for their
   default logger instance, there is no built-in way to treat
   errors as values. In comparison, (xlog).Error() constructs
   an slog.Attr, since xlog does not provide a default logger.

Point (2) is debatable, since xlog.Fatal is only used in
cmd/texd/main.go, so I'd be willing to forfeit it.

Some TODOs remain:

- xlog, i.e. its extension over log/slog, is not really tested
- documentation is missing
- the current xlog constructor (New) is a bit clunky to use,
  maybe switch to functional options?
- some tests create a local buffer as log output target - this
  could be made easier with a `log, buf := xlog.NewBuffered()`
  constructor (albeit, the overhead is minimal)
- for local development, I still like to have some colorization

Issue: #1
@dmke dmke mentioned this issue Jan 25, 2024
4 tasks
dmke added a commit that referenced this issue Jan 25, 2024
This replaces the zap logging engine with Go 1.21's new
structured logger, log/slog, or more precisely a thin
wrapper around that ("xlog").

The log/slog package has a few things missing, which are
present in xlog:

1. xlog provides a no-op logger, which simply discards any
   log output. This is extensively used in our tests.
2. xlog has a Fatal() output method, which simply calls
   Error() and then os.Exit(1).
3. xlog treats error values as first-class citizen. Since
   (log/slog).Error() is a convenience function for their
   default logger instance, there is no built-in way to treat
   errors as values. In comparison, (xlog).Error() constructs
   an slog.Attr, since xlog does not provide a default logger.

Point (2) is debatable, since xlog.Fatal is only used in
cmd/texd/main.go, so I'd be willing to forfeit it.

Some TODOs remain:

- xlog, i.e. its extension over log/slog, is not really tested
- documentation is missing
- the current xlog constructor (New) is a bit clunky to use,
  maybe switch to functional options?
- some tests create a local buffer as log output target - this
  could be made easier with a `log, buf := xlog.NewBuffered()`
  constructor (albeit, the overhead is minimal)
- for local development, I still like to have some colorization

Issue: #1
dmke added a commit that referenced this issue Jan 28, 2024
This replaces the zap logging engine with Go 1.21's new
structured logger, log/slog, or more precisely a thin
wrapper around that ("xlog").

The log/slog package has a few things missing, which are
present in xlog:

1. xlog provides a no-op logger, which simply discards any
   log output. This is extensively used in our tests.
2. xlog has a Fatal() output method, which simply calls
   Error() and then os.Exit(1).
3. xlog treats error values as first-class citizen. Since
   (log/slog).Error() is a convenience function for their
   default logger instance, there is no built-in way to treat
   errors as values. In comparison, (xlog).Error() constructs
   an slog.Attr, since xlog does not provide a default logger.

Point (2) is debatable, since xlog.Fatal is only used in
cmd/texd/main.go, so I'd be willing to forfeit it.

Some TODOs remain:

- xlog, i.e. its extension over log/slog, is not really tested
- documentation is missing
- the current xlog constructor (New) is a bit clunky to use,
  maybe switch to functional options?
- some tests create a local buffer as log output target - this
  could be made easier with a `log, buf := xlog.NewBuffered()`
  constructor (albeit, the overhead is minimal)
- for local development, I still like to have some colorization

Issue: #1
dmke added a commit that referenced this issue Jan 28, 2024
This replaces the zap logging engine with Go 1.21's new
structured logger, log/slog, or more precisely a thin
wrapper around that ("xlog").

The log/slog package has a few things missing, which are
present in xlog:

1. xlog provides a no-op logger, which simply discards any
   log output. This is extensively used in our tests.
2. xlog has a Fatal() output method, which simply calls
   Error() and then os.Exit(1).
3. xlog treats error values as first-class citizen. Since
   (log/slog).Error() is a convenience function for their
   default logger instance, there is no built-in way to treat
   errors as values. In comparison, (xlog).Error() constructs
   an slog.Attr, since xlog does not provide a default logger.

Point (2) is debatable, since xlog.Fatal is only used in
cmd/texd/main.go, so I'd be willing to forfeit it.

Some TODOs remain:

- xlog, i.e. its extension over log/slog, is not really tested
- documentation is missing
- the current xlog constructor (New) is a bit clunky to use,
  maybe switch to functional options?
- some tests create a local buffer as log output target - this
  could be made easier with a `log, buf := xlog.NewBuffered()`
  constructor (albeit, the overhead is minimal)
- for local development, I still like to have some colorization

Issue: #1
dmke added a commit that referenced this issue Oct 28, 2024
This replaces the zap logging engine with Go 1.21's structured
logger, log/slog, or more precisely a thin wrapper around that
("xlog").

The log/slog package has a few things missing, which are
present in xlog:

1. xlog provides a no-op logger, which simply discards any log output.
   This is extensively used in our tests.
2. xlog has a Fatal() output method, which simply calls Error() and then
   os.Exit(1).
3. xlog treats error values as first-class citizen. Since (log/slog).Error()
   is a convenience function for their default logger instance, there is
   no built-in way to treat errors as values. In comparison, (xlog).Error()
   constructs an slog.Attr, since xlog does not provide a default logger.

Point (2) is debatable, since xlog.Fatal is only used in cmd/texd/main.go,
so I'd be willing to forfeit it.

Some TODOs remain:

- xlog, i.e. its extension over log/slog, is not really tested
- documentation is missing
- the current xlog constructor (New) is a bit clunky to use,
  maybe switch to functional options?
- some tests create a local buffer as log output target - this
  could be made easier with a `log, buf := xlog.NewBuffered()`
  constructor (albeit, the overhead is minimal)
- for local development, I still like to have some colorization

Issue: #1
dmke added a commit that referenced this issue Oct 30, 2024
This replaces the zap logging engine with Go 1.21's structured
logger, log/slog, or more precisely a thin wrapper around that
("xlog").

The log/slog package has a few things missing, which are
present in xlog:

1. xlog provides a no-op logger, which simply discards any log output.
   This is extensively used in our tests.
2. xlog has a Fatal() output method, which simply calls Error() and then
   os.Exit(1).
3. xlog treats error values as first-class citizen. Since (log/slog).Error()
   is a convenience function for their default logger instance, there is
   no built-in way to treat errors as values. In comparison, (xlog).Error()
   constructs an slog.Attr, since xlog does not provide a default logger.

Point (2) is debatable, since xlog.Fatal is only used in cmd/texd/main.go,
so I'd be willing to forfeit it.

Some TODOs remain:

- xlog, i.e. its extension over log/slog, is not really tested
- documentation is missing
- the current xlog constructor (New) is a bit clunky to use,
  maybe switch to functional options?
- some tests create a local buffer as log output target - this
  could be made easier with a `log, buf := xlog.NewBuffered()`
  constructor (albeit, the overhead is minimal)
- for local development, I still like to have some colorization

Issue: #1
dmke added a commit that referenced this issue Oct 30, 2024
This replaces the zap logging engine with Go 1.21's structured
logger, log/slog, or more precisely a thin wrapper around that
("xlog").

The log/slog package has a few things missing, which are
present in xlog:

1. xlog provides a no-op logger, which simply discards any log output.
   This is extensively used in our tests.
2. xlog has a Fatal() output method, which simply calls Error() and then
   os.Exit(1).
3. xlog treats error values as first-class citizen. Since (log/slog).Error()
   is a convenience function for their default logger instance, there is
   no built-in way to treat errors as values. In comparison, (xlog).Error()
   constructs an slog.Attr, since xlog does not provide a default logger.

Point (2) is debatable, since xlog.Fatal is only used in cmd/texd/main.go,
so I'd be willing to forfeit it.

Some TODOs remain:

- xlog, i.e. its extension over log/slog, is not really tested
- documentation is missing
- the current xlog constructor (New) is a bit clunky to use,
  maybe switch to functional options?
- some tests create a local buffer as log output target - this
  could be made easier with a `log, buf := xlog.NewBuffered()`
  constructor (albeit, the overhead is minimal)
- for local development, I still like to have some colorization

Issue: #1
dmke added a commit that referenced this issue Oct 30, 2024
This replaces the zap logging engine with Go 1.21's structured
logger, log/slog, or more precisely a thin wrapper around that
("xlog").

The log/slog package has a few things missing, which are
present in xlog:

1. xlog provides a no-op logger, which simply discards any log output.
   This is extensively used in our tests.
2. xlog has a Fatal() output method, which simply calls Error() and then
   os.Exit(1).
3. xlog treats error values as first-class citizen. Since (log/slog).Error()
   is a convenience function for their default logger instance, there is
   no built-in way to treat errors as values. In comparison, (xlog).Error()
   constructs an slog.Attr, since xlog does not provide a default logger.

Point (2) is debatable, since xlog.Fatal is only used in cmd/texd/main.go,
so I'd be willing to forfeit it.

Some TODOs remain:

- xlog, i.e. its extension over log/slog, is not really tested
- documentation is missing
- the current xlog constructor (New) is a bit clunky to use,
  maybe switch to functional options?
- some tests create a local buffer as log output target - this
  could be made easier with a `log, buf := xlog.NewBuffered()`
  constructor (albeit, the overhead is minimal)
- for local development, I still like to have some colorization

Issue: #1
dmke added a commit that referenced this issue Oct 30, 2024
This replaces the zap logging engine with Go 1.21's structured
logger, log/slog, or more precisely a thin wrapper around that
("xlog").

The log/slog package has a few things missing, which are
present in xlog:

1. xlog provides a no-op logger, which simply discards any log output.
   This is extensively used in our tests.
2. xlog has a Fatal() output method, which simply calls Error() and then
   os.Exit(1).
3. xlog treats error values as first-class citizen. Since (log/slog).Error()
   is a convenience function for their default logger instance, there is
   no built-in way to treat errors as values. In comparison, (xlog).Error()
   constructs an slog.Attr, since xlog does not provide a default logger.

Point (2) is debatable, since xlog.Fatal is only used in cmd/texd/main.go,
so I'd be willing to forfeit it.

Some TODOs remain:

- xlog, i.e. its extension over log/slog, is not really tested
- documentation is missing
- the current xlog constructor (New) is a bit clunky to use,
  maybe switch to functional options?
- some tests create a local buffer as log output target - this
  could be made easier with a `log, buf := xlog.NewBuffered()`
  constructor (albeit, the overhead is minimal)
- for local development, I still like to have some colorization

Issue: #1
dmke added a commit that referenced this issue Oct 31, 2024
This replaces the zap logging engine with Go 1.21's structured
logger, log/slog, or more precisely a thin wrapper around that
("xlog").

The log/slog package has a few things missing, which are
present in xlog:

1. xlog provides a no-op logger, which simply discards any log output.
   This is extensively used in our tests.
2. xlog has a Fatal() output method, which simply calls Error() and then
   os.Exit(1).
3. xlog treats error values as first-class citizen. Since (log/slog).Error()
   is a convenience function for their default logger instance, there is
   no built-in way to treat errors as values. In comparison, (xlog).Error()
   constructs an slog.Attr, since xlog does not provide a default logger.

Point (2) is debatable, since xlog.Fatal is only used in cmd/texd/main.go,
so I'd be willing to forfeit it.

Some TODOs remain:

- xlog, i.e. its extension over log/slog, is not really tested
- documentation is missing
- the current xlog constructor (New) is a bit clunky to use,
  maybe switch to functional options?
- some tests create a local buffer as log output target - this
  could be made easier with a `log, buf := xlog.NewBuffered()`
  constructor (albeit, the overhead is minimal)
- for local development, I still like to have some colorization

Issue: #1
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

No branches or pull requests

2 participants