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

feat: Add logger #179

Merged
merged 7 commits into from
Oct 14, 2024
Merged

feat: Add logger #179

merged 7 commits into from
Oct 14, 2024

Conversation

alcb1310
Copy link
Contributor

@alcb1310 alcb1310 commented Sep 22, 2024

This PR will close issue #140

Adds structured logger to the application

Usage

Define your logs by priority: Debug, Info, Warn and Error by adding the following to the code

import log/slog

slog.Debug("Debug message")
slog.Info("Information message")
slog.Warn("Warning message")
slog.Error("Error message")

To set the debug level when running:

ENV=debug sesh

Just need to change the debug text for info or error. The default log level is warn.

By default all logs will go to a file, which will be in the `<user home
directory>/.config/sesh` and the file will be named
`<year-month-day>.log`

If running in other than the default mode, logs will be also be
displayed in screen
@alcb1310 alcb1310 mentioned this pull request Sep 22, 2024
@alcb1310
Copy link
Contributor Author

Made some decisions to implement this, it will be good to have your input about those:

  • Log file location: I decided to use the following ~/.config/sesh/<date>.log
  • Log file name: I decided to use the date in the format YYYY-mm-dd as the log file name
  • Default log level: If no log level is defined, I set being the warn level as the default one
  • When using the default log level, I decided not to show the user the log information and only save the log to the specified file

@alcb1310 alcb1310 changed the title Logger feat: Add logger Sep 22, 2024
@joshmedeski
Copy link
Owner

I'll review this and plan on merging it later this week, thanks!

Copy link
Owner

@joshmedeski joshmedeski left a comment

Choose a reason for hiding this comment

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

Could you please add one or two examples (maybe a debug and an error) somewhere in the codebase that shows how this gets used?

I just want to make sure I understand how this gets used and how it impacts testing, thanks.

main.go Outdated Show resolved Hide resolved
main.go Show resolved Hide resolved
@alcb1310
Copy link
Contributor Author

alcb1310 commented Oct 8, 2024

Could you please add one or two examples (maybe a debug and an error) somewhere in the codebase that shows how this gets used?

I just want to make sure I understand how this gets used and how it impacts testing, thanks.

I've added a couple of examples on how I would log the the error and debug inside the App() function

@joshmedeski
Copy link
Owner

I'm on macOS and I was unable to generate a log file in the tmp directory. I could only see the logs in the terminal.

I tried all the logs levels, am I missing something?

@alcb1310
Copy link
Contributor Author

alcb1310 commented Oct 8, 2024

The os.TempDir() function that is used to get the temp directory returns whatever is in your $TMPDIR environment variable and if empty it defaults to /tmp try :

cd $TMPDIR/sesh
tail <date>.log

You will find the log file there

main.go Show resolved Hide resolved
@joshmedeski joshmedeski merged commit 39e5fab into joshmedeski:main Oct 14, 2024
4 checks passed
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