gorealis-v2/logger.go

80 lines
1.8 KiB
Go
Raw Normal View History

2017-11-30 12:11:54 -08:00
/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package realis
type Logger interface {
Println(v ...interface{})
Printf(format string, v ...interface{})
Print(v ...interface{})
}
type NoopLogger struct{}
func (NoopLogger) Printf(format string, a ...interface{}) {}
func (NoopLogger) Print(a ...interface{}) {}
func (NoopLogger) Println(a ...interface{}) {}
type LevelLogger struct {
Logger
debug bool
2019-09-10 15:19:45 -07:00
trace bool
}
Merge develop branch into master (#68) * Fixing possible race condition when passing backoff around as a pointer. * Adding a debug logger that is turned off by default. Info logger is enabled by default but prints out less information. * Removing OK Aurora acknowledgment. * Making Mutex a pointer so that there's no chance it can accidentally be copied. * Changing %v to %+v for composite structs. Removing a repetitive statement for the Aurora return code. * Removing another superflous debug statement. * Removing a leftover helper function from before we changed how we configured the client. * Changing the logging paradigm to only require a single logger. All logging will be disabled by default. If debug is enabled, and a logger has not been set, the library will default to printing all logging (INFO and DEBUG) to the stdout. * Minor changes to demonstrate how a logger can be used in conjunction to debug mode. * Removing port override as it is not needed * Changing code comments to reflect getting rid of port override. * Adding port override back in. * Bug fix: Logger was being set to NOOP despite no logger being provided when debug mode is turned on. * Turn on logging by default. * Removing option to override schema and ports for information found on Zookeeper. * Turning off debug mode for tests because it's too verbose. Making sure LevelLogger is initialized correctly under all scenarios. * Removing override fields for zk config. * Remove space. * Removing info that is now incorrect about zk options.
2018-06-22 12:57:21 -07:00
func (l *LevelLogger) EnableDebug(enable bool) {
l.debug = enable
}
2019-09-10 15:19:45 -07:00
func (l *LevelLogger) EnableTrace(enable bool) {
l.trace = enable
}
func (l LevelLogger) DebugPrintf(format string, a ...interface{}) {
if l.debug {
2019-09-10 15:19:45 -07:00
l.Printf("[DEBUG] "+format, a...)
}
}
func (l LevelLogger) DebugPrint(a ...interface{}) {
if l.debug {
2019-09-10 15:19:45 -07:00
l.Print(append([]interface{}{"[DEBUG] "}, a...)...)
}
}
func (l LevelLogger) DebugPrintln(a ...interface{}) {
if l.debug {
2019-09-10 15:19:45 -07:00
l.Println(append([]interface{}{"[DEBUG] "}, a...)...)
}
}
func (l LevelLogger) TracePrintf(format string, a ...interface{}) {
if l.trace {
l.Printf("[TRACE] "+format, a...)
}
}
func (l LevelLogger) TracePrint(a ...interface{}) {
if l.trace {
l.Print(append([]interface{}{"[TRACE] "}, a...)...)
}
}
func (l LevelLogger) TracePrintln(a ...interface{}) {
if l.trace {
l.Println(append([]interface{}{"[TRACE] "}, a...)...)
}
}