Skip to content

feat: remove logger from taskfile package #2082

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

Merged
merged 5 commits into from
Feb 22, 2025

Conversation

pd93
Copy link
Member

@pd93 pd93 commented Feb 20, 2025

Our package API should not rely on our internal logger package. Logging is a CLI-specific responsibility and users that want to use Task as a package may want to implement their own logging. As such, this PR removes the logger from the taskfile package entirely.

Normally this would mean we lose the ability to insert debug logs into our code. However, we can pass a generic function into the Reader which will process logs instead. This allows all of Task's current logging to remain in place while a 3rd party user can either omit the logging function when creating their reader (and discard the logs) or implement their own custom logging.

I have also done the same thing for the prompt function so that package API users can implement their own prompt functionality.

Finally, the reader now uses functional options in its constructor. This allows us to set sensible defaults instead of the caller having to specify everything each time (including the new logging functions).

@pd93 pd93 changed the title remove logger from taskfile package feat: remove logger from taskfile package Feb 20, 2025
@@ -117,7 +115,6 @@ func Exists(l *logger.Logger, path string) (string, error) {
for _, taskfile := range defaultTaskfiles {
alt := filepathext.SmartJoin(path, taskfile)
if _, err := os.Stat(alt); err == nil {
l.VerboseOutf(logger.Magenta, "task: [%s] Not found - Using alternative (%s)\n", path, taskfile)
Copy link
Member

Choose a reason for hiding this comment

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

I’m OK with removing it because, even though we could use it for troubleshooting, I don’t think it’s used at all. I just wanted to make sure it wasn’t an oversight.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, its difficult to log here without passing a function in. If we really want the logs, we could compare the input/output in the caller and log there instead, but I decided it wasn't worth it.

Copy link
Member

Choose a reason for hiding this comment

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

I agree!

@vmaerten vmaerten self-requested a review February 22, 2025 15:48
Copy link
Member

@vmaerten vmaerten left a comment

Choose a reason for hiding this comment

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

❤️

@pd93 pd93 merged commit 4d15a8b into main Feb 22, 2025
14 checks passed
@pd93 pd93 deleted the remove-logger-from-taskfile-package branch February 22, 2025 16:00
pd93 added a commit that referenced this pull request Feb 22, 2025
@pd93 pd93 added the area: package api Changes related to the usage of Task as a Go package. label Feb 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: package api Changes related to the usage of Task as a Go package.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants