Documentation ¶
Index ¶
- Variables
- type Config
- type Entry
- type FormatError
- type Level
- func (instance Level) CheckedString() (string, error)
- func (instance Level) DisplayForLogging() string
- func (instance Level) IsIndicatingProblem() bool
- func (instance Level) MarshalJSON() ([]byte, error)
- func (instance Level) MarshalYAML() (interface{}, error)
- func (instance *Level) Set(value string) error
- func (instance Level) String() string
- func (instance *Level) UnmarshalJSON(b []byte) error
- func (instance *Level) UnmarshalYAML(unmarshal func(interface{}) error) error
- func (instance Level) Validate() error
- type Logger
- func (i *Logger) Close()
- func (i *Logger) EntryFor(framesToSkip int, problem interface{}, priority Level, time time.Time, ...) Entry
- func (i Logger) IsOpen() bool
- func (i *Logger) Log(level Level, pattern interface{}, args ...interface{})
- func (i *Logger) LogAdvanced(framesToSkip int, problem interface{}, level Level, pattern interface{}, ...)
- func (i *Logger) LogProblem(problem interface{}, level Level, pattern interface{}, args ...interface{})
- func (i *Logger) NewOutputStreamWrapperFor(l Level) io.Writer
- func (i *Logger) Stderr() io.Writer
- func (i *Logger) Stdin() io.Reader
- func (i *Logger) Stdout() io.Writer
- func (i Logger) Uptime() time.Duration
- type Pattern
- func (instance Pattern) CheckedString() (string, error)
- func (instance Pattern) MarshalYAML() (interface{}, error)
- func (instance *Pattern) Set(value string) error
- func (instance Pattern) String() string
- func (instance *Pattern) UnmarshalYAML(unmarshal func(interface{}) error) error
- func (instance Pattern) Validate() error
- type Writer
Constants ¶
This section is empty.
Variables ¶
AllLevels contains all possible variants of Level.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // @default info // // Minimal log level the logger will output its messages. All below will be ignored. Level Level `json:"level" yaml:"level"` // @default info // // If the service prints something to “stdout“ instance will logged with instance level. StdoutLevel Level `json:"stdoutLevel" yaml:"stdoutLevel"` // @default error // // If the service prints something to “stderr“ instance will logged with instance level. StderrLevel Level `json:"stderrLevel" yaml:"stderrLevel"` // @default "console" // // Target file of the logger. The file will be created if not exist - but not the parent directory. // // If instance value is set to “console“ the whole output will go to “stdout“ or to “stderr“ on every log level // above or equal to {@ref .Level#Warning warning}. Filename values.String `json:"filename" yaml:"filename"` // @default 500 // // Maximum size in megabytes of the log file before it gets rotated. // // This is ignored if {@ref #Filename filename} os set to “console“. MaxSizeInMb values.NonNegativeInteger `json:"maxSizeInMb" yaml:"maxSizeInMb"` // @default 500 // // Maximum number of old log files to retain. // // This is ignored if {@ref #Filename filename} os set to “console“. MaxBackups values.NonNegativeInteger `json:"maxBackups" yaml:"maxBackups"` // @default 1 // // Maximum number of days to retain old log files based on the // timestamp encoded in their filename. Note that a day is defined as 24 // hours and may not exactly correspond to calendar days due to daylight // savings, leap seconds, etc. // // This is ignored if {@ref #Filename filename} os set to “console“. MaxAgeInDays values.NonNegativeInteger `json:"maxAgeInDays" yaml:"maxAgeInDays"` // @default "%d{YYYY-MM-DD HH:mm:ss} [%-5.5p] [%c] %m%n%P{%m}" // // Pattern how to format the log messages to output with. Pattern Pattern `json:"pattern" yaml:"pattern"` }
Description ¶
A logger handles every output generated by the daemon itself, the process or other parts controlled by the daemon.
func (*Config) BeforeUnmarshalYAML ¶
BeforeUnmarshalYAML is used until yaml unmarshalling. Do not call directly.
type Entry ¶
type Entry struct { Time time.Time Message string Priority Level Category string Stack stack.Stack Uptime time.Duration Problem interface{} }
Entry represents an entry to be logged.
type FormatError ¶
FormatError represents an error if a given pattern contains wrong arguments.
func NewFormatError ¶
func NewFormatError(position int, message string, a ...interface{}) FormatError
NewFormatError creates a new instance of FormatError.
func (FormatError) Error ¶
func (e FormatError) Error() string
type Level ¶
type Level int
Description ¶
Represents a level for logging with a {@ref .Config Logger}
const ( // @id debug // Used for debugging proposes. This level is only required you something goes wrong and you need more information. Debug Level = 200 // @id info // This is the regular level. Every normal message will be logged with instance level. Info Level = 300 // @id warning // If a problem appears but the program is still able to continue its work, instance level is used. Warning Level = 400 // @id error // If a problem appears and the program is not longer able to continue its work, instance level is used. Error Level = 500 // @id fatal // This level is used on dramatic problems. Fatal Level = 600 )
func (Level) CheckedString ¶
CheckedString is like String but return also an optional error if there are some validation errors.
func (Level) DisplayForLogging ¶
DisplayForLogging returns a string that could be used to display this level in log messages.
func (Level) IsIndicatingProblem ¶
IsIndicatingProblem returns true if this level indicates a problem.
func (Level) MarshalJSON ¶
MarshalJSON is used until json marshalling. Do not call directly.
func (Level) MarshalYAML ¶
MarshalYAML is used until yaml marshalling. Do not call directly.
func (*Level) Set ¶
Set the given string to current object from a string. Return an error object if there are some problems while transforming the string.
func (*Level) UnmarshalJSON ¶
UnmarshalJSON is used until json unmarshalling. Do not call directly.
func (*Level) UnmarshalYAML ¶
UnmarshalYAML is used until yaml unmarshalling. Do not call directly.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger represents a logger to log events to different sources like console or files.
func (*Logger) Close ¶
func (i *Logger) Close()
Close will close this logger and all of its resources.
func (*Logger) EntryFor ¶
func (i *Logger) EntryFor(framesToSkip int, problem interface{}, priority Level, time time.Time, message string) Entry
EntryFor creates a new entry for given parameters using the current Logger instance.
func (*Logger) LogAdvanced ¶ added in v0.1.6
func (i *Logger) LogAdvanced(framesToSkip int, problem interface{}, level Level, pattern interface{}, args ...interface{})
LogAdvanced logs a problem with the given pattern and level.
func (*Logger) LogProblem ¶
func (i *Logger) LogProblem(problem interface{}, level Level, pattern interface{}, args ...interface{})
LogProblem logs a problem with the given pattern and level.
func (*Logger) NewOutputStreamWrapperFor ¶ added in v0.1.6
NewOutputStreamWrapperFor creates a writer to use for redirect every output to a logger.
func (*Logger) Stderr ¶
Stderr creates a writer to use for redirect every Stderr output to a logger.
type Pattern ¶
type Pattern string
Description ¶
A flexible pattern string.
The conversion pattern is closely related to the conversion pattern of the printf function in C. A conversion pattern is composed of literal text and format control expressions called conversion specifiers.
*You are free to insert any literal text within the conversion pattern.*
Each conversion specifier starts with a percent sign (“%“) and is followed by optional format modifiers and a conversion character. The conversion character specifies the type of data, e.g. category, priority, date, thread name. The format modifiers control such things as field width, padding, left and right justification. The following is a simple example.
Let the conversion pattern be "%d{YYYY-MM-DD HH:mm:ss} [%-5p]: %m%n" and assume that the log4j environment was set to use a PatternLayout. Then the statements: ``` LOG debug Message 1 LOG warn Message 2 ```
would yield the output ``` 2016-01-09 14:59:30 [DEBUG] Message 1 2016-01-09 14:59:31 [WARN ] Message 2 ```
Note that there is no explicit separator between text and conversion specifiers. The pattern parser knows when it has reached the end of a conversion specifier when it reads a conversion character. In the example above the conversion specifier %-5p means the priority of the logging event should be left justified to a width of five characters. The recognized conversion characters are
Conversion patterns ¶
* “%d[{<dateFormat>}]“: Prints out the date of when the log event was created. Possible patterns:
- Month
- “M“: 1 2 ... 12
- “MM“: 01 01 ... 12
- “Mo“: 1st 2nd ... 12th
- “MMM“: Jan Feb ... Dec
- “MMMM“: January February ... December
- Day of Month
- “D“: 1 2 ... 31
- “DD“: 01 02 ... 31
- “Do“: 1st 2nd ... 31st
- Day of Week
- “ddd“: Sun Mon ... Sat
- “dddd“: Sunday Monday ... Saturday
- Year
- “YY“: 70 71 ... 12
- “YYYY“: 1970 1971 ... 2012
- Hour
- “H“: 0 1 2 ... 23
- “HH“: 00 01 02 .. 23
- “h“: 1 2 ... 12
- “hh“: 01 02 ... 12
- Minute
- “m“: 0 1 2 ... 59
- “mm“: 00 01 02 ... 59
- Second
- “s“: 0 1 2 ... 59
- “ss“: 00 01 02 ... 59
- AM / PM
- “A“: AM PM
- “a“: am pm
- Timezone
- “Z“: -07:00 -06:00 ... +07:00
- “ZZ“: -0700 -0600 ... +0700
* “%m“: The log message. * “%c[{<maximumNumberOfElements>}]“: Holds the logging category. Normally instance is the name of the logger or the service. If you do not specify “maximumNumberOfElements“ the full name is displayed. If instance is for example “%c{2}“ and the name of the category is “a.b.c“ then the output result is “b.c“. * “%F[{<maximumNumberOfPathElements>}]“: Holds the source file that logs instance event. If you do not specify “maximumNumberOfPathElements“ the full file name is displayed. If instance is for example “%F{2}“ and the file name is “/a/b/c.go“ then the output result is “b/c.go“. * “%l“: Holds the source location of the log event. * “%L“: Holds the line number where the log event was created. * “%C[{<maximumNumberOfElements>}]“: Holds the source code package. If you do not specify “maximumNumberOfElements“ the full name is displayed. If instance is for example “%C{2}“ and the name of the package is “a.b.c“ then the output result is “b.c“. * “%M“: Holds the method name where the log event was created. * “%p“: Holds the priority or better called log level. * “%P[{<subFormatPattern>}]“: Stacktrace of the location where a problem was raised that caused instance log message. * “%r“: Uptime of the logger. * “%n“: Prints out a new line character. * “%%“: Prints out a “%“ character.
func (Pattern) CheckedString ¶
CheckedString is like String but return also an optional error if there are some validation errors.
func (Pattern) MarshalYAML ¶
MarshalYAML is used until yaml marshalling. Do not call directly.
func (*Pattern) Set ¶
Set the given string to current object from a string. Return an error object if there are some problems while transforming the string.
func (*Pattern) UnmarshalYAML ¶
UnmarshalYAML is used until yaml unmarshalling. Do not call directly.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer represents a log writer. A writer of this type is synchronized and could be used from different threads and contexts.