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

Create a logger package with slog #14

Closed
AmirAtashghah opened this issue Nov 22, 2023 · 2 comments · Fixed by #18
Closed

Create a logger package with slog #14

AmirAtashghah opened this issue Nov 22, 2023 · 2 comments · Fixed by #18

Comments

@AmirAtashghah
Copy link
Contributor

Description:

The project requires a logging system with structured and leveled output. The slog crate provides a powerful and flexible logging framework that meets these requirements. However, the project does not have a dedicated logger package that uses slog and configures the output format, destination, and filters. This issue suggests the creation of a logger package with slog that can be easily integrated with the project.

Features:

Logger Initialization: Implement a function that initializes the logger with a given configuration file or default settings.
Output Format: Define the log structure and levels, and choose a suitable output format (e.g., JSON, plain text) for the logger.
Output Destination: Choose a suitable output destination (e.g., console, file, network) for the logger, and implement a drain that writes the log messages to the destination.
Output Filters: Implement a mechanism that allows the user to filter the log messages based on the log level, module, or other criteria.

Implementation Guidelines:

Performance: Benchmark and optimize the performance of the logger package, as logging can have a significant impact on the application’s speed and resource consumption. You can use the [testing] and [pprof] packages to measure and improve the performance of your code.

Error Handling: Decide how to handle errors that may occur during logging, such as writing to a closed or unavailable output destination, or formatting an invalid log message. You can use the [errors] package to create and handle errors in a consistent and informative way.

Compatibility: Ensure that your logger package is compatible with the existing log and slog packages, as well as other popular logging packages in the Go ecosystem. You can use the [slog.Handler] interface to adapt different output formats and destinations, and the [slog.Logger] interface to wrap other loggers and add structured fields to them.


Testing: Provide a robust suite of tests to validate the correctness and reliability of the logger package.

Modularity: Design the logger package to be modular and easily extensible, allowing for the addition of new output formats, destinations, or filters in future updates.

Documentation: Provide clear and comprehensive documentation for the logger package, explaining its usage, features, and limitations.
@DOO-DEV
Copy link
Contributor

DOO-DEV commented Nov 23, 2023

Why we are not using open-source package like Zap?
Writing the features and more important achieve same performance and allocation rate is hard.

Also what should implement?? the slog package has already JsonHandler for showing result in json format. My question is what is the feature that we looking for?

logger := slog.New(slog.NewJsonHandler(os.Stdout, nil);
logger.Warn("This is warning", "key", "value")

By the way I create a pull request that use slog package and make it little nicer but slower i think (with color) and this the resutl:
image

@gohossein
Copy link
Contributor

Performance isn't a concern at the moment. I prefer to stick with std packages as far as I can.

@DOO-DEV DOO-DEV linked a pull request Dec 9, 2023 that will close this issue
@DOO-DEV DOO-DEV closed this as completed Dec 9, 2023
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 a pull request may close this issue.

3 participants