Skip to content

Commit 6513e3c

Browse files
committed
updated documentation and README.md
1 parent 9dcbe83 commit 6513e3c

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,19 @@ type ILogger interface {
8181
## The factory
8282
Simply provides the following functions
8383

84+
* `New(name string, writer ...io.Writer) ILogger`: Creates a new logger instance using the default builder assigned.
85+
* `name`: The name of the logger to create.
86+
* `writer`: (Optional) The io.Writer the logger instance should use. If not provided, it is set to the default writer by the implementation, typically Stdout or Stderr
8487
* `Register(name string, logger ILogger)`: Registers an instance of ILogger to be returned as the singleton instance by the given name.
85-
* `name`: The logger implementation name.
88+
* `name`: The logger name.
8689
* `logger`: The logger instance.
87-
* `RegisterBuilder(name string, ctor func(...interface{}) ILogger)`: Registers an ILogger constructor function which will be used to create a new instance of the logger when requested instance by the given name. The constructor allows a variadic interface{} array that can be used for optional constructor variables, such as the instance name of a logger, the package name where it is used, etc. It is up to the custom implementation of a logger to use these values.
88-
* `name`: The logger implementation name.
89-
* `ctor`: The constructor function used to create the ILogger instance.
90-
* `Get(name string, args ...interface{}) ILogger`: Returns an instance of the requested logger by its name. Returns nil if a logger by that name has not been previously registered.
91-
* `name`: The implementation name of the instance to be retrieved.
92-
* `args`: Variadic interface{} array as optional arguments for a registered logger constructor.
93-
* `List() []string`: Returns the list of loggers that have been registered to the factory.
94-
* `Contains(name string) bool`: Contains indicates if a logger by the given name is contained by the factory.
95-
96-
## Predefined loggers
90+
* `Get(name string) ILogger`: Returns an instance of the requested logger by its name. Creates a new logger with the default logger builder if the logger does not exist.
91+
* `name`: The name of the logger instance to be retrieved.
92+
* `List() []string`: Returns the list of loggers that have been registered.
93+
* `Contains(name string) bool`: Indicates if a logger by the given name exists.
94+
* `SetDefaultBuilder(ctor LoggerBuilder)` Assigns a new constructor function to use as the default logger constructor.
95+
96+
## Predefined logger types
9797

9898
* **Logrus**: Predefined logger implementation powered by `github.com/sirupsen/logrus`. It is assigned as default to be de default logger which responds to the static functions in the `log` package. Can also be obtained by the using the `"logrus"` name (also defined in the `LoggerLogrus` constant). Eg: `log.Get(log.LoggerLogrus)`
9999
* **Nil Logger**: This implementation, as the name suggests, is a logger that does nothing when its functions are called. Can be obtained by the using the `"nil"` name (also defined in the `LoggerNil` constant). Eg: `log.Get(log.LoggerNil)`. To easily set the Nil Logger as the default logger, simply pass `nil` value to the `log.SetDefault` function. Eg `log.SetDefault(nil)`

log/logger_factory.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@ var (
1111
// Register registers an instance of ILogger to be returned as the singleton
1212
// instance by the given name.
1313
//
14-
// {name} - The logger implementation name.
14+
// {name} - The logger name.
1515
// {logger} - The logger instance.
1616
//
17-
func Register(name string, logger ILogger) {
17+
func Register(name string, logger ILogger) ILogger {
1818
loggers[name] = logger
1919
}
2020

2121
// Get returns an instance of the requested logger by its name. Returns the Nil Logger implementation
2222
// if a logger by the given name is not found.
2323
//
24-
// {name} - The implementation name of the instance to be retrieved.
24+
// {name} - The name of the logger instance to be retrieved.
2525
//
2626
func Get(name string) ILogger {
2727
if v, ok := loggers[name]; ok {
2828
return v
2929
}
3030

31-
return NewNil()
31+
return Register(name, defaultBuilder(name))
3232
}
3333

3434
// New creates a new logger instance using the default builder assigned.
3535
//
36-
// {name} - The implementation name of the instance to be retrieved.
36+
// {name} - The name of the logger to create.
3737
// {writer} - (Optional) The io.Writer the logger instance should use. If not provided,
3838
// it is set to the default writer by the implementation, typically Stdout or Stderr
3939
//
4040
func New(name string, writer ...io.Writer) ILogger {
41-
return defaultBuilder(name, writer...)
41+
return Register(name, defaultBuilder(name, writer...))
4242
}
4343

4444
// List returns the list of loggers that have been registered.

0 commit comments

Comments
 (0)