Documentation
¶
Index ¶
- func Debug(v ...interface{})
- func Error(err error)
- func Info(v ...interface{})
- func SetFlattenMetadata(b bool)
- func SetFormat(fm formatter)
- func SetMetadata(md map[string]interface{})
- func SetMinLevel(lv level.Level)
- func SetOutput(out io.Writer)
- func SetStdLogger(lg *log.Logger)
- func Warn(v ...interface{})
- type Logger
- func (l *Logger) Debug(v ...interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Error(err error)
- func (l *Logger) Info(v ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) SetMetadata(meta map[string]interface{})
- func (l *Logger) Warn(v ...interface{})
- func (l *Logger) Warnf(format string, v ...interface{})
- type NopLogger
- type Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Debug ¶
func Debug(v ...interface{})
Debug logs a message at level Debug on the default logger.
func SetFlattenMetadata ¶
func SetFlattenMetadata(b bool)
SetFlattenMetadata sets the flag if metadata is going to be flattened. If the flag is put on, metadata is going to be flattened in output
func SetFormat ¶
func SetFormat(fm formatter)
SetFormat sets the format of message output to the default logger.
func SetMetadata ¶
func SetMetadata(md map[string]interface{})
SetMetadata sets metadata to default logger. If you use some querying service for searching specific logs like BigQuery, CloudWatch Logs Insight, Elasticsearch and other more, SetMetadata can be used to set additional information to be able to search for conveniently. For instance, HTTP Request ID, the id of user signed in, EC2 instance-id and other more.
func SetMinLevel ¶
SetMinLevel sets minumum logging level to the default logger.
func SetStdLogger ¶
SetStdLogger sets StdLogger that is used output message to the default logger.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger has fields that Option or setter SetXXXX set.
func (*Logger) Debug ¶
func (l *Logger) Debug(v ...interface{})
Debug logs a message at level Debug.
func (*Logger) SetMetadata ¶
SetMetadata sets a metadata to a logger.
type NopLogger ¶
type NopLogger struct{}
NopLogger just implements the below simple interface. ```
type Logger interface { Debug(v ...interface{}) Info(v ...interface{}) Warn(v ...interface{}) Error(err error) }
```
In writting tests, if you use Logger and you don't want any output, NopLogger can be used as stabs.
type Option ¶
Option is a function for initialization in the constructor of Logger.
func FlattenMetadata ¶
FlattenMetadata returns Option that sets the flag if metadata is going to be flattened. If the flag is put on, metadata is going to be flattened in output.
func Format ¶
func Format(fm formatter) Option
Format returns Option that sets the format of message output to a new logger.
func Metadata ¶
Metadata sets metadata to a new logger. If you use some querying service for searching specific logs like BigQuery, CloudWatch Logs Insight, Elasticsearch and other more, SetMetadata can be used to set additional information to be able to search for conveniently. For instance, HTTP Request ID, the id of user signed in, EC2 instance-id and other more.
func Output ¶
Output returns Option that sets io.Writer as the destination of logging message to a new logger.
Example ¶
SetMinLevel(level.Debug) SetFormat(format.JSONPretty) SetMetadata(map[string]interface{}{ "uesr_id": "86f32b8b-ec0d-479f-aed1-1070aa54cecf", "request_id": "943ad105-7543-11e6-a9ac-65e093327849", }) SetFlattenMetadata(true) SetOutput(os.Stdout) defaultLogger.nowFunc = func() time.Time { return time.Time{} } defaultLogger.withoutTrace = true Debug("debug") Info("info") Warn("warn") Error(errors.New("error"))
Output: { "level": "DEBUG", "message": "debug", "request_id": "943ad105-7543-11e6-a9ac-65e093327849", "time": "0001-01-01T00:00:00Z", "uesr_id": "86f32b8b-ec0d-479f-aed1-1070aa54cecf" } { "level": "INFO", "message": "info", "request_id": "943ad105-7543-11e6-a9ac-65e093327849", "time": "0001-01-01T00:00:00Z", "uesr_id": "86f32b8b-ec0d-479f-aed1-1070aa54cecf" } { "level": "WARN", "message": "warn", "request_id": "943ad105-7543-11e6-a9ac-65e093327849", "time": "0001-01-01T00:00:00Z", "uesr_id": "86f32b8b-ec0d-479f-aed1-1070aa54cecf" } { "error": "*errors.errorString: error", "level": "ERROR", "request_id": "943ad105-7543-11e6-a9ac-65e093327849", "time": "0001-01-01T00:00:00Z", "uesr_id": "86f32b8b-ec0d-479f-aed1-1070aa54cecf" }