Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/angadthandi/logger
https://github.com/angadthandi/logger
design-patterns object-oriented object-oriented-programming ood
Last synced: about 3 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/angadthandi/logger
- Owner: angadthandi
- Created: 2020-04-30T01:35:02.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-05-04T02:16:48.000Z (over 4 years ago)
- Last Synced: 2024-11-20T21:45:13.767Z (2 months ago)
- Topics: design-patterns, object-oriented, object-oriented-programming, ood
- Language: Java
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Design a Logger
1. Have an enum for LogLevels i.e. FATAL, ERROR, WARN, INFO, DEBUG
2. Have a main Logger class. Provide API in your logger class getMessage(String message, LogLeveLEnum level) which client can use to send log message and associated log level.
3. Have a field to store configured log level in your Logger class. Provide API and maybe have constructor of logger class set a log level and store it in a Enum field, something like setLogLevel(LogLevelEnum level)
4. After receiving a message via getMessage forward it to another function to process it. (filter it if it is less than configured log level, otherwise append timestamp, loglevel)
5. We can use command pattern to tie a sink to a loglevel and a message can be passed on to appropriate command based on the log level. (Logger class can probably keep a Map of logLevel as key, and various classes implementing command interface to map a logLevel to a command. This map should expose setter APIs to change behavior at run-time.) \
OR \
You can implement Sink using the strategic pattern , i.e the code will determine on the runtime whether it has the destination as the text file, database or on console. You can achieve this by Constructor injection. By this you will get the single responsibility of the code as well.