-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'go_code/thirdparty/src/github.com/cihub/seelog/' from commit 'f5…
…61c5e57575bb1e0a2167028b7339b3a8d16fb4' git-subtree-dir: go_code/thirdparty/src/github.com/cihub/seelog git-subtree-mainline: 9dae926 git-subtree-split: f561c5e
- Loading branch information
Showing
63 changed files
with
11,233 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
go_code/thirdparty/src/github.com/cihub/seelog/LICENSE.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Copyright (c) 2012, Cloud Instruments Co., Ltd. <[email protected]> | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of the Cloud Instruments Co., Ltd. nor the | ||
names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
116 changes: 116 additions & 0 deletions
116
go_code/thirdparty/src/github.com/cihub/seelog/README.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
Seelog | ||
======= | ||
|
||
Seelog is a powerful and easy-to-learn logging framework that provides functionality for flexible dispatching, filtering, and formatting log messages. | ||
It is natively written in the [Go](http://golang.org/) programming language. | ||
|
||
[](https://drone.io/github.com/cihub/seelog/latest) | ||
|
||
Features | ||
------------------ | ||
|
||
* Xml configuring to be able to change logger parameters without recompilation | ||
* Changing configurations on the fly without app restart | ||
* Possibility to set different log configurations for different project files and functions | ||
* Adjustable message formatting | ||
* Simultaneous log output to multiple streams | ||
* Choosing logger priority strategy to minimize performance hit | ||
* Different output writers | ||
* Console writer | ||
* File writer | ||
* Buffered writer (Chunk writer) | ||
* Rolling log writer (Logging with rotation) | ||
* SMTP writer | ||
* Others... (See [Wiki](https://github.com/cihub/seelog/wiki)) | ||
* Log message wrappers (JSON, XML, etc.) | ||
* Global variables and functions for easy usage in standalone apps | ||
* Functions for flexible usage in libraries | ||
|
||
Quick-start | ||
----------- | ||
|
||
```go | ||
package main | ||
|
||
import log "github.com/cihub/seelog" | ||
|
||
func main() { | ||
defer log.Flush() | ||
log.Info("Hello from Seelog!") | ||
} | ||
``` | ||
|
||
Installation | ||
------------ | ||
|
||
If you don't have the Go development environment installed, visit the | ||
[Getting Started](http://golang.org/doc/install.html) document and follow the instructions. Once you're ready, execute the following command: | ||
|
||
``` | ||
go get -u github.com/cihub/seelog | ||
``` | ||
|
||
*IMPORTANT*: If you are not using the latest release version of Go, check out this [wiki page](https://github.com/cihub/seelog/wiki/Notes-on-'go-get') | ||
|
||
Documentation | ||
--------------- | ||
|
||
Seelog has github wiki pages, which contain detailed how-tos references: https://github.com/cihub/seelog/wiki | ||
|
||
Examples | ||
--------------- | ||
|
||
Seelog examples can be found here: [seelog-examples](https://github.com/cihub/seelog-examples) | ||
|
||
Issues | ||
--------------- | ||
|
||
Feel free to push issues that could make Seelog better: https://github.com/cihub/seelog/issues | ||
|
||
Changelog | ||
--------------- | ||
* **v2.6** : Config using code and custom formatters | ||
* Configuration using code in addition to xml (All internal receiver/dispatcher/logger types are now exported). | ||
* Custom formatters. Check [wiki](https://github.com/cihub/seelog/wiki/Custom-formatters) | ||
* Bugfixes and internal improvements. | ||
* **v2.5** : Interaction with other systems. Part 2: custom receivers | ||
* Finished custom receivers feature. Check [wiki](https://github.com/cihub/seelog/wiki/custom-receivers) | ||
* Added 'LoggerFromCustomReceiver' | ||
* Added 'LoggerFromWriterWithMinLevelAndFormat' | ||
* Added 'LoggerFromCustomReceiver' | ||
* Added 'LoggerFromParamConfigAs...' | ||
* **v2.4** : Interaction with other systems. Part 1: wrapping seelog | ||
* Added configurable caller stack skip logic | ||
* Added 'SetAdditionalStackDepth' to 'LoggerInterface' | ||
* **v2.3** : Rethinking 'rolling' receiver | ||
* Reimplemented 'rolling' receiver | ||
* Added 'Max rolls' feature for 'rolling' receiver with type='date' | ||
* Fixed 'rolling' receiver issue: renaming on Windows | ||
* **v2.2** : go1.0 compatibility point [go1.0 tag] | ||
* Fixed internal bugs | ||
* Added 'ANSI n [;k]' format identifier: %EscN | ||
* Made current release go1 compatible | ||
* **v2.1** : Some new features | ||
* Rolling receiver archiving option. | ||
* Added format identifier: %Line | ||
* Smtp: added paths to PEM files directories | ||
* Added format identifier: %FuncShort | ||
* Warn, Error and Critical methods now return an error | ||
* **v2.0** : Second major release. BREAKING CHANGES. | ||
* Support of binaries with stripped symbols | ||
* Added log strategy: adaptive | ||
* Critical message now forces Flush() | ||
* Added predefined formats: xml-debug, xml-debug-short, xml, xml-short, json-debug, json-debug-short, json, json-short, debug, debug-short, fast | ||
* Added receiver: conn (network connection writer) | ||
* BREAKING CHANGE: added Tracef, Debugf, Infof, etc. to satisfy the print/printf principle | ||
* Bug fixes | ||
* **v1.0** : Initial release. Features: | ||
* Xml config | ||
* Changing configurations on the fly without app restart | ||
* Contraints and exceptions | ||
* Formatting | ||
* Log strategies: sync, async loop, async timer | ||
* Receivers: buffered, console, file, rolling, smtp | ||
|
||
|
||
|
198 changes: 198 additions & 0 deletions
198
go_code/thirdparty/src/github.com/cihub/seelog/archive/archive.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
package archive | ||
|
||
import ( | ||
"archive/tar" | ||
"archive/zip" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"time" | ||
|
||
"github.com/cihub/seelog/archive/gzip" | ||
) | ||
|
||
// Reader is the interface for reading files from an archive. | ||
type Reader interface { | ||
NextFile() (name string, err error) | ||
io.Reader | ||
} | ||
|
||
// ReadCloser is the interface that groups Reader with the Close method. | ||
type ReadCloser interface { | ||
Reader | ||
io.Closer | ||
} | ||
|
||
// Writer is the interface for writing files to an archived format. | ||
type Writer interface { | ||
NextFile(name string, fi os.FileInfo) error | ||
io.Writer | ||
} | ||
|
||
// WriteCloser is the interface that groups Writer with the Close method. | ||
type WriteCloser interface { | ||
Writer | ||
io.Closer | ||
} | ||
|
||
type nopCloser struct{ Reader } | ||
|
||
func (nopCloser) Close() error { return nil } | ||
|
||
// NopCloser returns a ReadCloser with a no-op Close method wrapping the | ||
// provided Reader r. | ||
func NopCloser(r Reader) ReadCloser { | ||
return nopCloser{r} | ||
} | ||
|
||
// Copy copies from src to dest until either EOF is reached on src or an error | ||
// occurs. | ||
// | ||
// When the archive format of src matches that of dst, Copy streams the files | ||
// directly into dst. Otherwise, copy buffers the contents to disk to compute | ||
// headers before writing to dst. | ||
func Copy(dst Writer, src Reader) error { | ||
switch src := src.(type) { | ||
case tarReader: | ||
if dst, ok := dst.(tarWriter); ok { | ||
return copyTar(dst, src) | ||
} | ||
case zipReader: | ||
if dst, ok := dst.(zipWriter); ok { | ||
return copyZip(dst, src) | ||
} | ||
// Switch on concrete type because gzip has no special methods | ||
case *gzip.Reader: | ||
if dst, ok := dst.(*gzip.Writer); ok { | ||
_, err := io.Copy(dst, src) | ||
return err | ||
} | ||
} | ||
|
||
return copyBuffer(dst, src) | ||
} | ||
|
||
func copyBuffer(dst Writer, src Reader) (err error) { | ||
const defaultFileMode = 0666 | ||
|
||
buf, err := ioutil.TempFile("", "archive_copy_buffer") | ||
if err != nil { | ||
return err | ||
} | ||
defer os.Remove(buf.Name()) // Do not care about failure removing temp | ||
defer buf.Close() // Do not care about failure closing temp | ||
for { | ||
// Handle the next file | ||
name, err := src.NextFile() | ||
switch err { | ||
case io.EOF: // Done copying | ||
return nil | ||
default: // Failed to write: bail out | ||
return err | ||
case nil: // Proceed below | ||
} | ||
|
||
// Buffer the file | ||
if _, err := io.Copy(buf, src); err != nil { | ||
return fmt.Errorf("buffer to disk: %v", err) | ||
} | ||
|
||
// Seek to the start of the file for full file copy | ||
if _, err := buf.Seek(0, os.SEEK_SET); err != nil { | ||
return err | ||
} | ||
|
||
// Set desired file permissions | ||
if err := os.Chmod(buf.Name(), defaultFileMode); err != nil { | ||
return err | ||
} | ||
fi, err := buf.Stat() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Write the buffered file | ||
if err := dst.NextFile(name, fi); err != nil { | ||
return err | ||
} | ||
if _, err := io.Copy(dst, buf); err != nil { | ||
return fmt.Errorf("copy to dst: %v", err) | ||
} | ||
if err := buf.Truncate(0); err != nil { | ||
return err | ||
} | ||
if _, err := buf.Seek(0, os.SEEK_SET); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
type tarReader interface { | ||
Next() (*tar.Header, error) | ||
io.Reader | ||
} | ||
|
||
type tarWriter interface { | ||
WriteHeader(hdr *tar.Header) error | ||
io.Writer | ||
} | ||
|
||
type zipReader interface { | ||
Files() []*zip.File | ||
} | ||
|
||
type zipWriter interface { | ||
CreateHeader(fh *zip.FileHeader) (io.Writer, error) | ||
} | ||
|
||
func copyTar(w tarWriter, r tarReader) error { | ||
for { | ||
hdr, err := r.Next() | ||
switch err { | ||
case io.EOF: | ||
return nil | ||
default: // Handle error | ||
return err | ||
case nil: // Proceed below | ||
} | ||
|
||
info := hdr.FileInfo() | ||
// Skip directories | ||
if info.IsDir() { | ||
continue | ||
} | ||
if err := w.WriteHeader(hdr); err != nil { | ||
return err | ||
} | ||
if _, err := io.Copy(w, r); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
func copyZip(zw zipWriter, r zipReader) error { | ||
for _, f := range r.Files() { | ||
if err := copyZipFile(zw, f); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func copyZipFile(zw zipWriter, f *zip.File) error { | ||
rc, err := f.Open() | ||
if err != nil { | ||
return err | ||
} | ||
defer rc.Close() // Read-only | ||
|
||
hdr := f.FileHeader | ||
hdr.SetModTime(time.Now()) | ||
w, err := zw.CreateHeader(&hdr) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = io.Copy(w, rc) | ||
return err | ||
} |
Oops, something went wrong.