Documentation ¶
Overview ¶
Package Oris_Log allows users to write application logs to file, console or DB (NoSql/Sql)
The logger allows users to add context (context are more information that can be shared across the logger instance) to logs if needed.
Features ¶
1. Write log to SQL/NoSQL DB.
2. Write log to file.
3. Write log to console.
4. Logs are written in json/plain text format.
5. Logs can be written to multiple output source i.e. to both file and console.
6. Context can be added to a log i.e. User ID, can be added to a log to track user footprint.
Oris logger requires a configuration file `logger.json`:
{ "name": "awesomeProject", "filename": "sample", "MaxFileSize": "2K", "folder": "logs", "output": "console", "buffer": 10000, "disable_logType": ["fatal","debug"] }
1. name: The project name
2. filename: The name that would be assigned to log file. This config is only needed when using file as output.
3. MaxFileSize: Set the max file size for each log, ones the file exceeds the max size, it is renamed and subsequent logs are written to a new file. Note: A new log file is created every day. The size is a string with suffix 'K' kilobyte and 'M' Megabyte.
4. folder: the name of the folder where logs file would be kept, the default location is ./logs.
5. output: This determines where logs would be written to i.e file, console, or MongoDB
6. buffer: This value is used when output is set to `file`, it buffers file during write to memory to avoid blocking.
7. disable_logType: This can be used to disable so log type in production i.e. debug log. The allowable values are 'info','debug','error','fatal'
Index ¶
- Constants
- func ConvertSize(size string) int64
- type Configuration
- type ConsoleWriter
- func (l *ConsoleWriter) AddContext(key string, value interface{})
- func (l *ConsoleWriter) Debug(arg0 interface{}, arg1 ...interface{})
- func (l *ConsoleWriter) Error(arg0 interface{}, arg1 ...interface{})
- func (l *ConsoleWriter) Fatal(arg0 interface{}, arg1 ...interface{})
- func (l *ConsoleWriter) GetContext(key string) interface{}
- func (l *ConsoleWriter) Info(arg0 interface{}, arg1 ...interface{})
- func (l *ConsoleWriter) NewContext() Logger
- func (l *ConsoleWriter) SetLogID(id string)
- type FileWriter
- func (l *FileWriter) AddContext(key string, value interface{})
- func (f *FileWriter) Debug(arg0 interface{}, arg1 ...interface{})
- func (f *FileWriter) Error(arg0 interface{}, arg1 ...interface{})
- func (f *FileWriter) Fatal(arg0 interface{}, arg1 ...interface{})
- func (l *FileWriter) GetContext(key string) interface{}
- func (f *FileWriter) Info(arg0 interface{}, arg1 ...interface{})
- func (f *FileWriter) NewContext() Logger
- func (f *FileWriter) SetLogID(id string)
- type Label
- type Logger
- type MongoWriter
- func (l *MongoWriter) AddContext(key string, value interface{})
- func (m *MongoWriter) Debug(arg0 interface{}, arg1 ...interface{})
- func (m *MongoWriter) Error(arg0 interface{}, arg1 ...interface{})
- func (m *MongoWriter) Fatal(arg0 interface{}, arg1 ...interface{})
- func (l *MongoWriter) GetContext(key string) interface{}
- func (m *MongoWriter) Info(arg0 interface{}, arg1 ...interface{})
- func (m *MongoWriter) NewContext() Logger
- func (m *MongoWriter) SetLogID(id string)
- type SqlWriter
- func (l *SqlWriter) AddContext(key string, value interface{})
- func (s *SqlWriter) Debug(arg0 interface{}, arg1 ...interface{})
- func (s *SqlWriter) Error(arg0 interface{}, arg1 ...interface{})
- func (s *SqlWriter) Fatal(arg0 interface{}, arg1 ...interface{})
- func (l *SqlWriter) GetContext(key string) interface{}
- func (s *SqlWriter) Info(arg0 interface{}, arg1 ...interface{})
- func (s *SqlWriter) NewContext() Logger
- func (s *SqlWriter) SetLogID(id string)
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func ConvertSize ¶
ConvertSize converts MaxFileSize value in the config file to bytes.
Types ¶
type Configuration ¶
type ConsoleWriter ¶
type ConsoleWriter struct { ID string // contains filtered or unexported fields }
ConsoleWriter writes log to console
func (*ConsoleWriter) AddContext ¶
func (l *ConsoleWriter) AddContext(key string, value interface{})
AddContext Add a new context value to log writer
func (*ConsoleWriter) Debug ¶
func (l *ConsoleWriter) Debug(arg0 interface{}, arg1 ...interface{})
Debug log debug
func (*ConsoleWriter) Error ¶
func (l *ConsoleWriter) Error(arg0 interface{}, arg1 ...interface{})
Error log error
func (*ConsoleWriter) Fatal ¶
func (l *ConsoleWriter) Fatal(arg0 interface{}, arg1 ...interface{})
Fatal log fatal
func (*ConsoleWriter) GetContext ¶
func (l *ConsoleWriter) GetContext(key string) interface{}
GetContext returns context value based on its key
func (*ConsoleWriter) Info ¶
func (l *ConsoleWriter) Info(arg0 interface{}, arg1 ...interface{})
Info log info
func (*ConsoleWriter) NewContext ¶
func (l *ConsoleWriter) NewContext() Logger
NewContext This function is used to add context to the logger instance
func (*ConsoleWriter) SetLogID ¶
func (l *ConsoleWriter) SetLogID(id string)
SetLogID set the current logger instance's ID
type FileWriter ¶
FileWriter writes log to file
func (*FileWriter) AddContext ¶
func (l *FileWriter) AddContext(key string, value interface{})
AddContext Add a new context value to log writer
func (*FileWriter) Debug ¶
func (f *FileWriter) Debug(arg0 interface{}, arg1 ...interface{})
Debug log debug
func (*FileWriter) Error ¶
func (f *FileWriter) Error(arg0 interface{}, arg1 ...interface{})
Error log error
func (*FileWriter) Fatal ¶
func (f *FileWriter) Fatal(arg0 interface{}, arg1 ...interface{})
Fatal log fatal
func (*FileWriter) GetContext ¶
func (l *FileWriter) GetContext(key string) interface{}
GetContext returns context value based on its key
func (*FileWriter) Info ¶
func (f *FileWriter) Info(arg0 interface{}, arg1 ...interface{})
Info log info
func (*FileWriter) NewContext ¶
func (f *FileWriter) NewContext() Logger
NewContext This function is used to add context to a log record.
func (*FileWriter) SetLogID ¶
func (f *FileWriter) SetLogID(id string)
type Logger ¶
type Logger interface { // Info Logs are written to an output with an info label Info(interface{}, ...interface{}) // Error Logs are written to an output with an error label Error(interface{}, ...interface{}) // Debug Logs are written to an output with a debug label Debug(interface{}, ...interface{}) // Fatal : Logs is been written to output and program terminates immediately Fatal(interface{}, ...interface{}) // NewContext This function is used to add context to a log record, a new instance of the log writer is returned. NewContext() Logger // AddContext Add a new context value to a log writer AddContext(key string, value interface{}) // GetContext returns context value based on its key GetContext(key string) interface{} // SetLogID set ID for the current log context SetLogID(id string) }
Logger An interface that states the requirements for a writer to be an instance of Logger. Every log writer must implement the Logger interface.
type MongoWriter ¶
type MongoWriter struct { ID string // contains filtered or unexported fields }
MongoWriter
func (*MongoWriter) AddContext ¶
func (l *MongoWriter) AddContext(key string, value interface{})
AddContext Add a new context value to log writer
func (*MongoWriter) Debug ¶
func (m *MongoWriter) Debug(arg0 interface{}, arg1 ...interface{})
Debug log debug
func (*MongoWriter) Error ¶
func (m *MongoWriter) Error(arg0 interface{}, arg1 ...interface{})
Error log error
func (*MongoWriter) Fatal ¶
func (m *MongoWriter) Fatal(arg0 interface{}, arg1 ...interface{})
Fatal log fatal
func (*MongoWriter) GetContext ¶
func (l *MongoWriter) GetContext(key string) interface{}
GetContext returns context value based on its key
func (*MongoWriter) Info ¶
func (m *MongoWriter) Info(arg0 interface{}, arg1 ...interface{})
Info log info
func (*MongoWriter) NewContext ¶
func (m *MongoWriter) NewContext() Logger
NewContext This function is used to add context to a log record.
func (*MongoWriter) SetLogID ¶
func (m *MongoWriter) SetLogID(id string)
SetLogID set the current logger instance's ID
type SqlWriter ¶
type SqlWriter struct { ID string // contains filtered or unexported fields }
SqlWriter
func (*SqlWriter) AddContext ¶
AddContext Add a new context value to log writer
func (*SqlWriter) Debug ¶
func (s *SqlWriter) Debug(arg0 interface{}, arg1 ...interface{})
Debug log debug
func (*SqlWriter) Error ¶
func (s *SqlWriter) Error(arg0 interface{}, arg1 ...interface{})
Error log error
func (*SqlWriter) Fatal ¶
func (s *SqlWriter) Fatal(arg0 interface{}, arg1 ...interface{})
Fatal log fatal
func (*SqlWriter) GetContext ¶
GetContext returns context value based on its key
func (*SqlWriter) Info ¶
func (s *SqlWriter) Info(arg0 interface{}, arg1 ...interface{})
Info log info
func (*SqlWriter) NewContext ¶
NewContext This function is used to add context to a log record.