Documentation ¶
Overview ¶
Package log4go provides level-based and highly configurable logging.
Enhanced Logging ¶
This is inspired by the logging functionality in Java. Essentially, you create a Logger object and create output filters for it. You can send whatever you want to the Logger, and it will filter that based on your settings and send it to the outputs. This way, you can put as much debug code in your program as you want, and when you're done you can filter out the mundane messages so only the important ones show up.
Utility functions are provided to make life easier. Here is some example code to get started:
log := log4go.NewLogger() log.AddFilter("stdout", log4go.DEBUG, log4go.NewConsoleLogWriter()) log.AddFilter("log", log4go.FINE, log4go.NewFileLogWriter("example.log", true)) log.Info("The time is now: %s", time.LocalTime().Format("15:04:05 MST 2006/01/02"))
The first two lines can be combined with the utility NewDefaultLogger:
log := log4go.NewDefaultLogger(log4go.DEBUG) log.AddFilter("log", log4go.FINE, log4go.NewFileLogWriter("example.log", true)) log.Info("The time is now: %s", time.LocalTime().Format("15:04:05 MST 2006/01/02"))
Usage notes:
- The ConsoleLogWriter does not display the source of the message to standard output, but the FileLogWriter does.
- The utility functions (Info, Debug, Warn, etc) derive their source from the calling function, and this incurs extra overhead.
Changes from 2.0:
- The external interface has remained mostly stable, but a lot of the internals have been changed, so if you depended on any of this or created your own LogWriter, then you will probably have to update your code. In particular, Logger is now a map and ConsoleLogWriter is now a channel behind-the-scenes, and the LogWrite method no longer has return values.
Future work: (please let me know if you think I should work on any of these particularly)
- Log file rotation
- Logging configuration files ala log4j
- Have the ability to remove filters?
- Have GetInfoChannel, GetDebugChannel, etc return a chan string that allows for another method of logging
- Add an XML filter type
Gypsy is a simplified YAML parser written in Go. It is intended to be used as a simple configuration file, and as such does not support a lot of the more nuanced syntaxes allowed in full-fledged YAML. YAML does not allow indent with tabs, and GYPSY does not ever consider a tab to be a space character. It is recommended that your editor be configured to convert tabs to spaces when editing Gypsy config files.
Gypsy understands the following to be a list:
- one
- two
- three
This is parsed as a `yaml.YamlList`, and can be retrieved from the `yaml.YamlNode.YamlList()` method. In this case, each element of the `yaml.YamlList` would be a `yaml.YamlScalar` whose value can be retrieved with the `yaml.YamlScalar.String()` method.
Gypsy understands the following to be a mapping:
key: value foo: bar running: away
A mapping is an unordered list of `key:value` pairs. All whitespace after the colon is stripped from the value and is used for alignment purposes during export. If the value is not a list or a map, everything after the first non-space character until the end of the line is used as the `yaml.YamlScalar` value.
Gypsy allows arbitrary nesting of maps inside lists, lists inside of maps, and maps and/or lists nested inside of themselves.
A map inside of a list:
- name: John Smith age: 42
- name: Jane Smith age: 45
A list inside of a map:
schools: - Meadow Glen - Forest Creek - Shady Grove libraries: - Joseph Hollingsworth Memorial - Andrew Keriman Memorial
A list of lists:
- - one
- two
- three
- - un
- deux
- trois
- - ichi
- ni
- san
A map of maps:
google: company: Google, Inc. ticker: GOOG url: http://google.com/ yahoo: company: Yahoo, Inc. ticker: YHOO url: http://yahoo.com/
In the case of a map of maps, all sub-keys must be on subsequent lines and indented equally. It is allowable for the first key/value to be on the same line if there is more than one key/value pair, but this is not recommended.
Values can also be expressed in long form (leading whitespace of the first line is removed from it and all subsequent lines). In the normal (baz) case, newlines are treated as spaces, all indentation is removed. In the folded case (bar), newlines are treated as spaces, except pairs of newlines (e.g. a blank line) are treated as a single newline, only the indentation level of the first line is removed, and newlines at the end of indented lines are preserved. In the verbatim (foo) case, only the indent at the level of the first line is stripped. The example:
foo: | lorem ipsum dolor sit amet bar: > lorem ipsum dolor sit amet baz: lorem ipsum dolor sit amet
The YAML subset understood by Gypsy can be expressed (loosely) in the following grammar (not including comments):
OBJECT = MAPPING | SEQUENCE | SCALAR . SHORT-OBJECT = SHORT-MAPPING | SHORT-SEQUENCE | SHORT-SCALAR . EOL = '\n' MAPPING = { LONG-MAPPING | SHORT-MAPPING } . SEQUENCE = { LONG-SEQUENCE | SHORT-SEQUENCE } . SCALAR = { LONG-SCALAR | SHORT-SCALAR } . LONG-MAPPING = { INDENT KEY ':' OBJECT EOL } . SHORT-MAPPING = '{' KEY ':' SHORT-OBJECT { ',' KEY ':' SHORT-OBJECT } '}' EOL . LONG-SEQUENCE = { INDENT '-' OBJECT EOL } EOL . SHORT-SEQUENCE = '[' SHORT-OBJECT { ',' SHORT-OBJECT } ']' EOL . LONG-SCALAR = ( '|' | '>' | ) EOL { INDENT SHORT-SCALAR EOL } SHORT-SCALAR = { alpha | digit | punct | ' ' | '\t' } . KEY = { alpha | digit } INDENT = { ' ' }
Any line where the first non-space character is a sharp sign (#) is a comment. It will be ignored. Only full-line comments are allowed.
Index ¶
- Constants
- Variables
- func ArrayContains(aStr string, arr []string) bool
- func ArrayContainsIgnoreCase(aStr string, arr []string) bool
- func ArrayIndexOf(aStr string, arr []string) int
- func ArrayIndexOfIgnoreCase(aStr string, arr []string) int
- func Bool(node YamlNode, spec string) (bool, error)
- func BoolChild(root YamlNode, spec string) (bool, error)
- func Condition(cond bool, trueVal, falseVal interface{}) interface{}
- func DefaultIfNil(val, def interface{}) interface{}
- func FormatLogRecord(format string, rec *LogRecord) string
- func GqlConnection(name string) *sql.DB
- func If(cond bool, trueFunc func())
- func Int(node YamlNode, spec string) (int64, error)
- func Int64FromStr(str string) (int64, error)
- func IntChild(root YamlNode, spec string) (int64, error)
- func IntFromStr(str string) (int, error)
- func Json(v interface{}) string
- func ListChildCount(root YamlNode, spec string) (int, error)
- func ListCount(node YamlNode, spec string) (int, error)
- func LoadGqlConfigFile(filename string)
- func LoadGqlConfigString(yamlconf string)
- func PathJoin(elem ...string) string
- func ResponseContent(writer http.ResponseWriter, content, contentType, characterEncoding string)
- func ResponseErrorContent(writer http.ResponseWriter, statusCode int, ...)
- func ResponseErrorHtml(writer http.ResponseWriter, statusCode int, html string)
- func ResponseErrorJson(writer http.ResponseWriter, statusCode int, json string)
- func ResponseErrorText(writer http.ResponseWriter, statusCode int, text string)
- func ResponseHtml(writer http.ResponseWriter, html string)
- func ResponseJson(writer http.ResponseWriter, json string)
- func ResponseText(writer http.ResponseWriter, text string)
- func StrFromInt(i int) string
- func StrFromInt64(i int64) string
- func String(node YamlNode, spec string) (string, error)
- func StringChild(root YamlNode, spec string) (string, error)
- func UnJson(str string, v interface{}) interface{}
- func Unless(cond bool, falseFunc func())
- func ValOrFunc(val interface{}) interface{}
- func YamlRender(node YamlNode) string
- type CacheItem
- func (item *CacheItem) AccessCount() int64
- func (item *CacheItem) AccessedOn() time.Time
- func (item *CacheItem) CreatedOn() time.Time
- func (item *CacheItem) Data() interface{}
- func (item *CacheItem) KeepAlive()
- func (item *CacheItem) Key() interface{}
- func (item *CacheItem) LifeSpan() time.Duration
- func (item *CacheItem) SetAboutToExpireCallback(f func(interface{}))
- type CacheItemPair
- type CacheItemPairList
- type CacheTable
- func (table *CacheTable) Add(key interface{}, lifeSpan time.Duration, data interface{}) *CacheItem
- func (table *CacheTable) Count() int
- func (table *CacheTable) Delete(key interface{}) (*CacheItem, error)
- func (table *CacheTable) Exists(key interface{}) bool
- func (table *CacheTable) Flush()
- func (table *CacheTable) Foreach(trans func(key interface{}, item *CacheItem))
- func (table *CacheTable) LoadingAdd(key interface{}, args ...interface{}) (*CacheItem, error)
- func (table *CacheTable) MostAccessed(count int64) []*CacheItem
- func (table *CacheTable) NotFoundAdd(key interface{}, lifeSpan time.Duration, data interface{}) bool
- func (table *CacheTable) SetAboutToDeleteItemCallback(f func(*CacheItem))
- func (table *CacheTable) SetAddedItemCallback(f func(*CacheItem))
- func (table *CacheTable) SetDataLoader(f func(interface{}, ...interface{}) (*CacheItem, error))
- func (table *CacheTable) SetLogger(logger *log.Logger)
- func (table *CacheTable) Value(key interface{}, args ...interface{}) (*CacheItem, error)
- type ConsoleLogWriter
- type ExpireStrategy
- type FileLogWriter
- func (w *FileLogWriter) Close()
- func (w *FileLogWriter) LogWrite(rec *LogRecord)
- func (w *FileLogWriter) Rotate()
- func (w *FileLogWriter) SetFormat(format string) *FileLogWriter
- func (w *FileLogWriter) SetHeadFoot(head, foot string) *FileLogWriter
- func (w *FileLogWriter) SetRotate(rotate bool) *FileLogWriter
- func (w *FileLogWriter) SetRotateDaily(daily bool) *FileLogWriter
- func (w *FileLogWriter) SetRotateLines(maxlines int) *FileLogWriter
- func (w *FileLogWriter) SetRotateSize(maxsize int) *FileLogWriter
- type FormatLogWriter
- type Gql
- type GqlConfig
- type Hashtable
- type HttpReq
- func (httpReq *HttpReq) Cookie(cookie *http.Cookie) *HttpReq
- func (httpReq *HttpReq) Get() (string, error)
- func (httpReq *HttpReq) Params(name string, value string, more ...string) *HttpReq
- func (httpReq *HttpReq) ParamsMapping(params map[string]string) *HttpReq
- func (httpReq *HttpReq) Post() (string, error)
- func (httpReq *HttpReq) Prop(name string, value string) *HttpReq
- func (httpReq *HttpReq) Req(req string) *HttpReq
- func (httpReq *HttpReq) RequestBody(requestBody string) *HttpReq
- type LineReader
- type LineReaderException
- type LogFilter
- type LogRecord
- type LogWriter
- type Logger
- func (log Logger) AddFilter(name string, lvl level, writer LogWriter) Logger
- func (log Logger) Close()
- func (log Logger) Critical(arg0 interface{}, args ...interface{}) error
- func (log Logger) Debug(arg0 interface{}, args ...interface{})
- func (log Logger) Error(arg0 interface{}, args ...interface{}) error
- func (log Logger) Fine(arg0 interface{}, args ...interface{})
- func (log Logger) Finest(arg0 interface{}, args ...interface{})
- func (log Logger) Info(arg0 interface{}, args ...interface{})
- func (log Logger) LoadConfiguration(filename string)
- func (log Logger) Log(lvl level, source, message string)
- func (log Logger) Logc(lvl level, closure func() string)
- func (log Logger) Logf(lvl level, format string, args ...interface{})
- func (log Logger) Trace(arg0 interface{}, args ...interface{})
- func (log Logger) Warn(arg0 interface{}, args ...interface{}) error
- type Properties
- func (properties *Properties) GetProperty(key string) string
- func (properties *Properties) GetPropertyDefault(key, defaultValue string) string
- func (properties *Properties) List(out io.Writer)
- func (properties *Properties) Load(reader io.Reader) error
- func (properties *Properties) PropertyNames() []interface{}
- func (properties *Properties) Save(writer io.Writer, comments string)
- func (properties *Properties) SetProperty(key string, value string)
- func (properties *Properties) Store(writer io.Writer, comments string) error
- func (properties *Properties) StringPropertyNames() []string
- func (properties *Properties) ToMap() map[interface{}]interface{}
- type RecFunc
- type SocketLogWriter
- type UnknownGqlConnectionName
- type YamlFile
- func (f *YamlFile) GetBool(spec string) (bool, error)
- func (f *YamlFile) GetInt(spec string) (int64, error)
- func (f *YamlFile) GetList(spec string) (YamlList, error)
- func (f *YamlFile) GetListCount(spec string) (int, error)
- func (f *YamlFile) GetMap(spec string) (YamlMap, error)
- func (f *YamlFile) GetNode(spec string) (YamlNode, error)
- func (f *YamlFile) GetScalar(spec string) (YamlScalar, error)
- func (f *YamlFile) GetString(spec string) (string, error)
- func (f *YamlFile) RooListCount() (int, error)
- func (f *YamlFile) RootBool() (bool, error)
- func (f *YamlFile) RootInt() (int64, error)
- func (f *YamlFile) RootList() (YamlList, error)
- func (f *YamlFile) RootMap() (YamlMap, error)
- func (f *YamlFile) RootScalar() (YamlScalar, error)
- func (f *YamlFile) RootString() (string, error)
- type YamlList
- type YamlMap
- type YamlNode
- type YamlNodeNotFound
- type YamlNodeTypeMismatch
- type YamlScalar
- Bugs
Constants ¶
const ( ExpireAfterWrite = 0 ExpireAfterAccess = 1 )
const ( L4G_VERSION = "log4go-v4.0.1" L4G_MAJOR = 4 L4G_MINOR = 0 L4G_BUILD = 1 )
Version information noinspection GoSnakeCaseUsage,GoUnusedConst
const ( FINEST level = iota FINE DEBUG TRACE INFO WARNING ERROR CRITICAL )
const ( FORMAT_DEFAULT = "[%D %T] [%L] (%S) %M" FORMAT_SHORT = "[%t %d] [%L] %M" FORMAT_ABBREV = "[%L] %M" )
noinspection GoSnakeCaseUsage
Variables ¶
var ( // ErrCacheKeyNotFound gets returned when a specific key couldn't be found ErrCacheKeyNotFound = errors.New("key not found in cache") // ErrCacheKeyNotFoundOrLoadable gets returned when a specific key couldn't be // found and loading via the data-loader callback also failed ErrCacheKeyNotFoundOrLoadable = errors.New("key not found and could not be loaded into cache") )
var (
LOG logWrapper
)
var ( // LogBufferLength specifies how many log messages a particular log4go // logger can buffer at a time before writing them. LogBufferLength = 32 )
***** Variables *****
Functions ¶
func ArrayContains ¶ added in v0.3.1
func ArrayContainsIgnoreCase ¶ added in v0.3.1
func ArrayIndexOf ¶ added in v0.3.1
func ArrayIndexOfIgnoreCase ¶ added in v0.3.1
func DefaultIfNil ¶
func DefaultIfNil(val, def interface{}) interface{}
func FormatLogRecord ¶
Known format codes: %T - Time (15:04:05 MST) %t - Time (15:04) %D - Date (2006/01/02) %d - Date (01/02/06) %L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT) %S - Source %M - Message Ignores unknown formats Recommended: "[%D %T] [%L] (%S) %M"
func GqlConnection ¶
func Int64FromStr ¶
func IntFromStr ¶
func LoadGqlConfigFile ¶
func LoadGqlConfigFile(filename string)
noinspection GoUnusedExportedFunction
func LoadGqlConfigString ¶
func LoadGqlConfigString(yamlconf string)
noinspection GoUnusedExportedFunction
func ResponseContent ¶ added in v0.3.1
func ResponseContent(writer http.ResponseWriter, content, contentType, characterEncoding string)
func ResponseErrorContent ¶ added in v0.3.1
func ResponseErrorContent(writer http.ResponseWriter, statusCode int, errorContent, contentType, characterEncoding string)
func ResponseErrorHtml ¶ added in v0.3.1
func ResponseErrorHtml(writer http.ResponseWriter, statusCode int, html string)
noinspection GoUnusedExportedFunction
func ResponseErrorJson ¶ added in v0.3.1
func ResponseErrorJson(writer http.ResponseWriter, statusCode int, json string)
noinspection GoUnusedExportedFunction
func ResponseErrorText ¶ added in v0.3.1
func ResponseErrorText(writer http.ResponseWriter, statusCode int, text string)
noinspection GoUnusedExportedFunction
func ResponseHtml ¶ added in v0.3.1
func ResponseHtml(writer http.ResponseWriter, html string)
noinspection GoUnusedExportedFunction
func ResponseJson ¶ added in v0.3.1
func ResponseJson(writer http.ResponseWriter, json string)
noinspection GoUnusedExportedFunction
func ResponseText ¶ added in v0.3.1
func ResponseText(writer http.ResponseWriter, text string)
noinspection GoUnusedExportedFunction
func StrFromInt ¶
func StrFromInt64 ¶
func YamlRender ¶
YamlRender returns a string of the node as a YAML document. Note that Scalars will have a newline appended if they are rendered directly.
Types ¶
type CacheItem ¶
CacheItem is an individual cache item Parameter data contains the user-set value in the cache.
func NewCacheItem ¶
NewCacheItem returns a newly created CacheItem. Parameter key is the item's cache-key. Parameter lifeSpan determines after which time period without an access the item will get removed from the cache. Parameter data is the item's value.
func (*CacheItem) AccessCount ¶
AccessCount returns how often this item has been accessed.
func (*CacheItem) AccessedOn ¶
AccessedOn returns when this item was last accessed.
func (*CacheItem) Data ¶
func (item *CacheItem) Data() interface{}
Data returns the value of this cached item.
func (*CacheItem) KeepAlive ¶
func (item *CacheItem) KeepAlive()
KeepAlive marks an item to be kept for another expireDuration period. Ignored in ExpireAfterWrite cache
func (*CacheItem) Key ¶
func (item *CacheItem) Key() interface{}
Key returns the key of this cached item.
func (*CacheItem) SetAboutToExpireCallback ¶
func (item *CacheItem) SetAboutToExpireCallback(f func(interface{}))
SetAboutToExpireCallback configures a callback, which will be called right before the item is about to be removed from the cache.
type CacheItemPair ¶
type CacheItemPair struct { Key interface{} AccessCount int64 }
CacheItemPair maps key to access counter
type CacheItemPairList ¶
type CacheItemPairList []CacheItemPair
CacheItemPairList is a slice of CacheIemPairs that implements sort. Interface to sort by AccessCount.
func (CacheItemPairList) Len ¶
func (p CacheItemPairList) Len() int
func (CacheItemPairList) Less ¶
func (p CacheItemPairList) Less(i, j int) bool
func (CacheItemPairList) Swap ¶
func (p CacheItemPairList) Swap(i, j int)
type CacheTable ¶
CacheTable is a table within the cache
func CacheExpireAfterAccess ¶
func CacheExpireAfterAccess(table string) *CacheTable
noinspection GoUnusedExportedFunction
func CacheExpireAfterWrite ¶
func CacheExpireAfterWrite(table string) *CacheTable
noinspection GoUnusedExportedFunction
func (*CacheTable) Add ¶
func (table *CacheTable) Add(key interface{}, lifeSpan time.Duration, data interface{}) *CacheItem
Add adds a key/value pair to the cache. Parameter key is the item's cache-key. Parameter lifeSpan determines after which time period without an access the item will get removed from the cache. Parameter data is the item's value.
func (*CacheTable) Count ¶
func (table *CacheTable) Count() int
Count returns how many items are currently stored in the cache.
func (*CacheTable) Delete ¶
func (table *CacheTable) Delete(key interface{}) (*CacheItem, error)
Delete an item from the cache.
func (*CacheTable) Exists ¶
func (table *CacheTable) Exists(key interface{}) bool
Exists returns whether an item exists in the cache. Unlike the Value method Exists neither tries to fetch data via the loadData callback nor does it keep the item alive in the cache.
func (*CacheTable) Flush ¶
func (table *CacheTable) Flush()
Flush deletes all items from this cache table.
func (*CacheTable) Foreach ¶
func (table *CacheTable) Foreach(trans func(key interface{}, item *CacheItem))
Foreach all items
func (*CacheTable) LoadingAdd ¶
func (table *CacheTable) LoadingAdd(key interface{}, args ...interface{}) (*CacheItem, error)
func (*CacheTable) MostAccessed ¶
func (table *CacheTable) MostAccessed(count int64) []*CacheItem
MostAccessed returns the most accessed items in this cache table
func (*CacheTable) NotFoundAdd ¶
func (table *CacheTable) NotFoundAdd(key interface{}, lifeSpan time.Duration, data interface{}) bool
NotFoundAdd tests whether an item not found in the cache. Unlike the Exists method this also adds data if they key could not be found.
func (*CacheTable) SetAboutToDeleteItemCallback ¶
func (table *CacheTable) SetAboutToDeleteItemCallback(f func(*CacheItem))
SetAboutToDeleteItemCallback configures a callback, which will be called every time an item is about to be removed from the cache.
func (*CacheTable) SetAddedItemCallback ¶
func (table *CacheTable) SetAddedItemCallback(f func(*CacheItem))
SetAddedItemCallback configures a callback, which will be called every time a new item is added to the cache.
func (*CacheTable) SetDataLoader ¶
func (table *CacheTable) SetDataLoader(f func(interface{}, ...interface{}) (*CacheItem, error))
SetDataLoader configures a data-loader callback, which will be called when trying to access a non-existing key. The key and 0...n additional arguments are passed to the callback function.
func (*CacheTable) SetLogger ¶
func (table *CacheTable) SetLogger(logger *log.Logger)
SetLogger sets the logger to be used by this cache table.
func (*CacheTable) Value ¶
func (table *CacheTable) Value(key interface{}, args ...interface{}) (*CacheItem, error)
Value returns an item from the cache and marks it to be kept alive. You can pass additional arguments to your DataLoader callback function.
type ConsoleLogWriter ¶
type ConsoleLogWriter chan *LogRecord
This is the standard writer that prints to standard output.
func NewConsoleLogWriter ¶
func NewConsoleLogWriter() ConsoleLogWriter
This creates a new ConsoleLogWriter
func (ConsoleLogWriter) Close ¶
func (w ConsoleLogWriter) Close()
Close stops the logger from sending messages to standard output. Attempts to send log messages to this logger after a Close have undefined behavior.
func (ConsoleLogWriter) LogWrite ¶
func (w ConsoleLogWriter) LogWrite(rec *LogRecord)
This is the ConsoleLogWriter's output method. This will block if the output buffer is full.
type ExpireStrategy ¶
type ExpireStrategy int
type FileLogWriter ¶
type FileLogWriter struct {
// contains filtered or unexported fields
}
This log writer sends output to a file noinspection GoSnakeCaseUsage
func NewFileLogWriter ¶
func NewFileLogWriter(fname string, rotate bool) *FileLogWriter
NewFileLogWriter creates a new LogWriter which writes to the given file and has rotation enabled if rotate is true.
If rotate is true, any time a new log file is opened, the old one is renamed with a .### extension to preserve it. The various Set* methods can be used to configure log rotation based on lines, size, and daily.
The standard log-line format is:
[%D %T] [%L] (%S) %M
func NewXMLLogWriter ¶
func NewXMLLogWriter(fname string, rotate bool) *FileLogWriter
NewXMLLogWriter is a utility method for creating a FileLogWriter set up to output XML record log messages instead of line-based ones.
func (*FileLogWriter) Close ¶
func (w *FileLogWriter) Close()
func (*FileLogWriter) LogWrite ¶
func (w *FileLogWriter) LogWrite(rec *LogRecord)
This is the FileLogWriter's output method
func (*FileLogWriter) SetFormat ¶
func (w *FileLogWriter) SetFormat(format string) *FileLogWriter
Set the logging format (chainable). Must be called before the first log message is written.
func (*FileLogWriter) SetHeadFoot ¶
func (w *FileLogWriter) SetHeadFoot(head, foot string) *FileLogWriter
Set the logfile header and footer (chainable). Must be called before the first log message is written. These are formatted similar to the FormatLogRecord (e.g. you can use %D and %T in your header/footer for date and time).
func (*FileLogWriter) SetRotate ¶
func (w *FileLogWriter) SetRotate(rotate bool) *FileLogWriter
SetRotate changes whether or not the old logs are kept. (chainable) Must be called before the first log message is written. If rotate is false, the files are overwritten; otherwise, they are rotated to another file before the new log is opened.
func (*FileLogWriter) SetRotateDaily ¶
func (w *FileLogWriter) SetRotateDaily(daily bool) *FileLogWriter
Set rotate daily (chainable). Must be called before the first log message is written.
func (*FileLogWriter) SetRotateLines ¶
func (w *FileLogWriter) SetRotateLines(maxlines int) *FileLogWriter
Set rotate at linecount (chainable). Must be called before the first log message is written.
func (*FileLogWriter) SetRotateSize ¶
func (w *FileLogWriter) SetRotateSize(maxsize int) *FileLogWriter
Set rotate at size (chainable). Must be called before the first log message is written.
type FormatLogWriter ¶
type FormatLogWriter chan *LogRecord
This is the standard writer that prints to standard output.
func NewFormatLogWriter ¶
func NewFormatLogWriter(out io.Writer, format string) FormatLogWriter
This creates a new FormatLogWriter noinspection GoUnusedExportedFunction
func (FormatLogWriter) Close ¶
func (w FormatLogWriter) Close()
Close stops the logger from sending messages to standard output. Attempts to send log messages to this logger after a Close have undefined behavior.
func (FormatLogWriter) LogWrite ¶
func (w FormatLogWriter) LogWrite(rec *LogRecord)
This is the FormatLogWriter's output method. This will block if the output buffer is full.
type Hashtable ¶ added in v0.4.0
type Hashtable struct {
// contains filtered or unexported fields
}
func NewHashtable ¶ added in v0.4.0
func NewHashtable() *Hashtable
func (*Hashtable) Get ¶ added in v0.4.0
func (hashtable *Hashtable) Get(key interface{}) interface{}
type HttpReq ¶
type HttpReq struct {
// contains filtered or unexported fields
}
func NewHttpReq ¶
func (*HttpReq) ParamsMapping ¶
func (*HttpReq) RequestBody ¶
type LineReader ¶ added in v0.4.0
type LineReader struct {
// contains filtered or unexported fields
}
func NewLineReader ¶ added in v0.4.0
func NewLineReader(reader io.Reader) *LineReader
func (*LineReader) ReadLine ¶ added in v0.4.0
func (lineReader *LineReader) ReadLine() (int, error)
type LineReaderException ¶ added in v0.4.0
type LineReaderException struct {
Message string
}
func (*LineReaderException) Error ¶ added in v0.4.0
func (e *LineReaderException) Error() string
type LogFilter ¶ added in v0.2.0
type LogFilter struct { Level level LogWriter }
A LogFilter represents the log level below which no log records are written to the associated LogWriter.
type LogRecord ¶
type LogRecord struct { Level level // The log level Created time.Time // The time at which the log message was created (nanoseconds) Source string // The message source Message string // The log message }
A LogRecord contains all of the pertinent information for each message
type LogWriter ¶
type LogWriter interface { // This will be called to log a LogRecord message. LogWrite(rec *LogRecord) // This should clean up anything lingering about the LogWriter, as it is called before // the LogWriter is removed. LogWrite should not be called after Close. Close() }
This is an interface for anything that should be able to write logs
type Logger ¶
A Logger represents a collection of Filters through which log messages are written.
func NewDefaultLogger ¶
func NewDefaultLogger(lvl level) Logger
Create a new logger with a "stdout" filter configured to send log messages at or above lvl to standard output.
func (Logger) AddFilter ¶
Add a new LogWriter to the Logger which will only log messages at lvl or higher. This function should not be called from multiple goroutines. Returns the logger for chaining.
func (Logger) Close ¶
func (log Logger) Close()
Closes all log writers in preparation for exiting the program or a reconfiguration of logging. Calling this is not really imperative, unless you want to guarantee that all log messages are written. Close removes all filters (and thus all LogWriters) from the logger.
func (Logger) Critical ¶
Critical logs a message at the critical log level and returns the formatted error, See Warn for an explanation of the performance and Debug for an explanation of the parameters.
func (Logger) Debug ¶
func (log Logger) Debug(arg0 interface{}, args ...interface{})
Debug is a utility method for debug log messages. The behavior of Debug depends on the first argument:
- arg0 is a string When given a string as the first argument, this behaves like Logf but with the DEBUG log level: the first argument is interpreted as a format for the latter arguments.
- arg0 is a func()string When given a closure of type func()string, this logs the string returned by the closure iff it will be logged. The closure runs at most one time.
- arg0 is interface{} When given anything else, the log message will be each of the arguments formatted with %v and separated by spaces (ala Sprint).
func (Logger) Error ¶
Error logs a message at the error log level and returns the formatted error, See Warn for an explanation of the performance and Debug for an explanation of the parameters.
func (Logger) Fine ¶
func (log Logger) Fine(arg0 interface{}, args ...interface{})
Fine logs a message at the fine log level. See Debug for an explanation of the arguments.
func (Logger) Finest ¶
func (log Logger) Finest(arg0 interface{}, args ...interface{})
Finest logs a message at the finest log level. See Debug for an explanation of the arguments.
func (Logger) Info ¶
func (log Logger) Info(arg0 interface{}, args ...interface{})
Info logs a message at the info log level. See Debug for an explanation of the arguments.
func (Logger) LoadConfiguration ¶
Load XML configuration; see log_manual_test_example.xml for documentation
func (Logger) Logc ¶
Logc logs a string returned by the closure at the given log level, using the caller as its source. If no log message would be written, the closure is never called.
func (Logger) Logf ¶
Logf logs a formatted log message at the given log level, using the caller as its source.
func (Logger) Trace ¶
func (log Logger) Trace(arg0 interface{}, args ...interface{})
Trace logs a message at the trace log level. See Debug for an explanation of the arguments.
func (Logger) Warn ¶
Warn logs a message at the warning log level and returns the formatted error. At the warning level and higher, there is no performance benefit if the message is not actually logged, because all formats are processed and all closures are executed to format the error message. See Debug for further explanation of the arguments.
type Properties ¶ added in v0.4.0
type Properties struct { Hashtable // contains filtered or unexported fields }
func NewProperties ¶ added in v0.4.0
func NewProperties() *Properties
func NewPropertiesDefault ¶ added in v0.4.0
func NewPropertiesDefault(defaults *Properties) *Properties
func (*Properties) GetProperty ¶ added in v0.4.0
func (properties *Properties) GetProperty(key string) string
func (*Properties) GetPropertyDefault ¶ added in v0.4.0
func (properties *Properties) GetPropertyDefault(key, defaultValue string) string
func (*Properties) List ¶ added in v0.4.0
func (properties *Properties) List(out io.Writer)
func (*Properties) Load ¶ added in v0.4.0
func (properties *Properties) Load(reader io.Reader) error
func (*Properties) PropertyNames ¶ added in v0.4.0
func (properties *Properties) PropertyNames() []interface{}
func (*Properties) Save ¶ added in v0.4.0
func (properties *Properties) Save(writer io.Writer, comments string)
func (*Properties) SetProperty ¶ added in v0.4.0
func (properties *Properties) SetProperty(key string, value string)
func (*Properties) Store ¶ added in v0.4.0
func (properties *Properties) Store(writer io.Writer, comments string) error
func (*Properties) StringPropertyNames ¶ added in v0.4.0
func (properties *Properties) StringPropertyNames() []string
func (*Properties) ToMap ¶ added in v0.4.0
func (properties *Properties) ToMap() map[interface{}]interface{}
type SocketLogWriter ¶
type SocketLogWriter chan *LogRecord
This log writer sends output to a socket
func NewSocketLogWriter ¶
func NewSocketLogWriter(proto, hostport string) SocketLogWriter
func (SocketLogWriter) Close ¶
func (w SocketLogWriter) Close()
func (SocketLogWriter) LogWrite ¶
func (w SocketLogWriter) LogWrite(rec *LogRecord)
This is the SocketLogWriter's output method
type UnknownGqlConnectionName ¶ added in v0.2.0
type UnknownGqlConnectionName struct {
Name string
}
func (*UnknownGqlConnectionName) Error ¶ added in v0.2.0
func (e *UnknownGqlConnectionName) Error() string
type YamlFile ¶
type YamlFile struct {
Root YamlNode
}
A YamlFile represents the top-level YAML node found in a file. It is intended for use as a configuration file.
func ConfigYamlFile ¶
ConfigYamlFile reads a YAML configuration file from the given filename and panics if an error is found. This is a utility function and is intended for use in initializers. noinspection GoUnusedExportedFunction
func ConfigYamlString ¶
ConfigYamlString reads a YAML configuration from a static string. If an error is found, it will panic. This is a utility function and is intended for use in initializers. noinspection GoUnusedExportedFunction
func ReadYamlFile ¶
ReadYamlFile reads a YAML configuration file from the given filename.
func ReadYamlString ¶
func (*YamlFile) GetListCount ¶ added in v0.3.0
func (*YamlFile) RooListCount ¶ added in v0.3.0
func (*YamlFile) RootScalar ¶ added in v0.3.0
func (f *YamlFile) RootScalar() (YamlScalar, error)
func (*YamlFile) RootString ¶ added in v0.3.0
type YamlList ¶
type YamlList []YamlNode
A YamlList is a YAML Sequence of Nodes.
type YamlNode ¶
type YamlNode interface {
// contains filtered or unexported methods
}
A YamlNode is a YAML YamlNode which can be a YamlMap, YamlList or YamlScalar.
func YamlChild ¶
YamlChild retrieves a child node from the specified node as follows:
.mapkey - GetString the key 'mapkey' of the YamlNode, which must be a YamlMap [idx] - Choose the index from the current YamlNode, which must be a YamlList
The above selectors may be applied recursively, and each successive selector applies to the result of the previous selector. For convenience, a "." is implied as the first character if the first character is not a "." or "[". The node tree is walked from the given node, considering each token of the above format. If a node along the evaluation path is not found, an error is returned. If a node is not the proper type, an error is returned. If the final node is not a YamlScalar, an error is returned.
type YamlNodeNotFound ¶
func (*YamlNodeNotFound) Error ¶
func (e *YamlNodeNotFound) Error() string
type YamlNodeTypeMismatch ¶
type YamlNodeTypeMismatch struct { Full string Spec string Token string Node YamlNode Expected string }
func (*YamlNodeTypeMismatch) Error ¶
func (e *YamlNodeTypeMismatch) Error() string
type YamlScalar ¶
type YamlScalar string
A YamlScalar is a YAML YamlScalar.
func ScalarChild ¶ added in v0.3.0
func ScalarChild(root YamlNode, spec string) (YamlScalar, error)
func (YamlScalar) Bool ¶
func (node YamlScalar) Bool() (bool, error)
func (YamlScalar) Int ¶
func (node YamlScalar) Int() (int64, error)
func (YamlScalar) String ¶
func (node YamlScalar) String() (string, error)
String returns the string represented by this YamlScalar.
Notes ¶
Bugs ¶
Multi-line strings are currently not supported.
Source Files ¶
- cache.go
- cache_errors.go
- cache_item.go
- cache_table.go
- collections.go
- cond.go
- gql.go
- gql_conn.go
- gql_error.go
- hashtable.go
- http.go
- httpreq.go
- json.go
- line_reader.go
- log4go.go
- log_config.go
- log_file_log.go
- log_pattlog.go
- log_socklog.go
- log_termlog.go
- log_wrapper.go
- path.go
- properties.go
- strconv.go
- yaml_config.go
- yaml_doc.go
- yaml_parser.go
- yaml_types.go
- ycomb.go