Add config file, handle it with Viper, add a command to open it in an editor
This commit is contained in:
parent
b8a8ba2e08
commit
61aa5880d3
234 changed files with 44636 additions and 383 deletions
158
Godeps/_workspace/src/github.com/spf13/jwalterweatherman/README.md
generated
vendored
Normal file
158
Godeps/_workspace/src/github.com/spf13/jwalterweatherman/README.md
generated
vendored
Normal file
|
@ -0,0 +1,158 @@
|
|||
jWalterWeatherman
|
||||
=================
|
||||
|
||||
Seamless printing to the terminal (stdout) and logging to a io.Writer
|
||||
(file) that’s as easy to use as fmt.Println.
|
||||
|
||||

|
||||
Graphic by [JonnyEtc](http://jonnyetc.deviantart.com/art/And-That-s-Why-You-Always-Leave-a-Note-315311422)
|
||||
|
||||
JWW is primarily a wrapper around the excellent standard log library. It
|
||||
provides a few advantages over using the standard log library alone.
|
||||
|
||||
1. Ready to go out of the box.
|
||||
2. One library for both printing to the terminal and logging (to files).
|
||||
3. Really easy to log to either a temp file or a file you specify.
|
||||
|
||||
|
||||
I really wanted a very straightforward library that could seamlessly do
|
||||
the following things.
|
||||
|
||||
1. Replace all the println, printf, etc statements thought my code with
|
||||
something more useful
|
||||
2. Allow the user to easily control what levels are printed to stdout
|
||||
3. Allow the user to easily control what levels are logged
|
||||
4. Provide an easy mechanism (like fmt.Println) to print info to the user
|
||||
which can be easily logged as well
|
||||
5. Due to 2 & 3 provide easy verbose mode for output and logs
|
||||
6. Not have any unnecessary initialization cruft. Just use it.
|
||||
|
||||
# Usage
|
||||
|
||||
## Step 1. Use it
|
||||
Put calls throughout your source based on type of feedback.
|
||||
No initialization or setup needs to happen. Just start calling things.
|
||||
|
||||
Available Loggers are:
|
||||
|
||||
* TRACE
|
||||
* DEBUG
|
||||
* INFO
|
||||
* WARN
|
||||
* ERROR
|
||||
* CRITICAL
|
||||
* FATAL
|
||||
|
||||
These each are loggers based on the log standard library and follow the
|
||||
standard usage. Eg..
|
||||
|
||||
```go
|
||||
import (
|
||||
jww "github.com/spf13/jwalterweatherman"
|
||||
)
|
||||
|
||||
...
|
||||
|
||||
if err != nil {
|
||||
|
||||
// This is a pretty serious error and the user should know about
|
||||
// it. It will be printed to the terminal as well as logged under the
|
||||
// default thresholds.
|
||||
|
||||
jww.ERROR.Println(err)
|
||||
}
|
||||
|
||||
if err2 != nil {
|
||||
// This error isn’t going to materially change the behavior of the
|
||||
// application, but it’s something that may not be what the user
|
||||
// expects. Under the default thresholds, Warn will be logged, but
|
||||
// not printed to the terminal.
|
||||
|
||||
jww.WARN.Println(err2)
|
||||
}
|
||||
|
||||
// Information that’s relevant to what’s happening, but not very
|
||||
// important for the user. Under the default thresholds this will be
|
||||
// discarded.
|
||||
|
||||
jww.INFO.Printf("information %q", response)
|
||||
|
||||
```
|
||||
|
||||
_Why 7 levels?_
|
||||
|
||||
Maybe you think that 7 levels are too much for any application... and you
|
||||
are probably correct. Just because there are seven levels doesn’t mean
|
||||
that you should be using all 7 levels. Pick the right set for your needs.
|
||||
Remember they only have to mean something to your project.
|
||||
|
||||
## Step 2. Optionally configure JWW
|
||||
|
||||
Under the default thresholds :
|
||||
|
||||
* Debug, Trace & Info goto /dev/null
|
||||
* Warn and above is logged (when a log file/io.Writer is provided)
|
||||
* Error and above is printed to the terminal (stdout)
|
||||
|
||||
### Changing the thresholds
|
||||
|
||||
The threshold can be changed at any time, but will only affect calls that
|
||||
execute after the change was made.
|
||||
|
||||
This is very useful if your application has a verbose mode. Of course you
|
||||
can decide what verbose means to you or even have multiple levels of
|
||||
verbosity.
|
||||
|
||||
|
||||
```go
|
||||
import (
|
||||
jww "github.com/spf13/jwalterweatherman"
|
||||
)
|
||||
|
||||
if Verbose {
|
||||
jww.SetLogThreshold(jww.LevelTrace)
|
||||
jww.SetStdoutThreshold(jww.LevelInfo)
|
||||
}
|
||||
```
|
||||
|
||||
### Using a temp log file
|
||||
|
||||
JWW conveniently creates a temporary file and sets the log Handle to
|
||||
a io.Writer created for it. You should call this early in your application
|
||||
initialization routine as it will only log calls made after it is executed.
|
||||
When this option is used, the library will fmt.Println where to find the
|
||||
log file.
|
||||
|
||||
```go
|
||||
import (
|
||||
jww "github.com/spf13/jwalterweatherman"
|
||||
)
|
||||
|
||||
jww.UseTempLogFile("YourAppName")
|
||||
|
||||
```
|
||||
|
||||
### Setting a log file
|
||||
|
||||
JWW can log to any file you provide a path to (provided it’s writable).
|
||||
Will only append to this file.
|
||||
|
||||
|
||||
```go
|
||||
import (
|
||||
jww "github.com/spf13/jwalterweatherman"
|
||||
)
|
||||
|
||||
jww.SetLogFile("/path/to/logfile")
|
||||
|
||||
```
|
||||
|
||||
|
||||
# More information
|
||||
|
||||
This is an early release. I’ve been using it for a while and this is the
|
||||
third interface I’ve tried. I like this one pretty well, but no guarantees
|
||||
that it won’t change a bit.
|
||||
|
||||
I wrote this for use in [hugo](http://hugo.spf13.com). If you are looking
|
||||
for a static website engine that’s super fast please checkout Hugo.
|
Loading…
Add table
Add a link
Reference in a new issue