mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-27 06:29:42 -08:00
vendor: remove unused dependencies
This commit is contained in:
parent
f52248269e
commit
748d392a7a
202
vendor/github.com/coreos/etcd/LICENSE
generated
vendored
202
vendor/github.com/coreos/etcd/LICENSE
generated
vendored
|
@ -1,202 +0,0 @@
|
||||||
|
|
||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright [yyyy] [name of copyright owner]
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
5
vendor/github.com/coreos/etcd/NOTICE
generated
vendored
5
vendor/github.com/coreos/etcd/NOTICE
generated
vendored
|
@ -1,5 +0,0 @@
|
||||||
CoreOS Project
|
|
||||||
Copyright 2014 CoreOS, Inc
|
|
||||||
|
|
||||||
This product includes software developed at CoreOS, Inc.
|
|
||||||
(http://www.coreos.com/).
|
|
22
vendor/github.com/coreos/etcd/pkg/fileutil/dir_unix.go
generated
vendored
22
vendor/github.com/coreos/etcd/pkg/fileutil/dir_unix.go
generated
vendored
|
@ -1,22 +0,0 @@
|
||||||
// Copyright 2016 The etcd Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build !windows
|
|
||||||
|
|
||||||
package fileutil
|
|
||||||
|
|
||||||
import "os"
|
|
||||||
|
|
||||||
// OpenDir opens a directory for syncing.
|
|
||||||
func OpenDir(path string) (*os.File, error) { return os.Open(path) }
|
|
46
vendor/github.com/coreos/etcd/pkg/fileutil/dir_windows.go
generated
vendored
46
vendor/github.com/coreos/etcd/pkg/fileutil/dir_windows.go
generated
vendored
|
@ -1,46 +0,0 @@
|
||||||
// Copyright 2016 The etcd Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package fileutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// OpenDir opens a directory in windows with write access for syncing.
|
|
||||||
func OpenDir(path string) (*os.File, error) {
|
|
||||||
fd, err := openDir(path)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return os.NewFile(uintptr(fd), path), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func openDir(path string) (fd syscall.Handle, err error) {
|
|
||||||
if len(path) == 0 {
|
|
||||||
return syscall.InvalidHandle, syscall.ERROR_FILE_NOT_FOUND
|
|
||||||
}
|
|
||||||
pathp, err := syscall.UTF16PtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return syscall.InvalidHandle, err
|
|
||||||
}
|
|
||||||
access := uint32(syscall.GENERIC_READ | syscall.GENERIC_WRITE)
|
|
||||||
sharemode := uint32(syscall.FILE_SHARE_READ | syscall.FILE_SHARE_WRITE)
|
|
||||||
createmode := uint32(syscall.OPEN_EXISTING)
|
|
||||||
fl := uint32(syscall.FILE_FLAG_BACKUP_SEMANTICS)
|
|
||||||
return syscall.CreateFile(pathp, access, sharemode, nil, createmode, fl, 0)
|
|
||||||
}
|
|
121
vendor/github.com/coreos/etcd/pkg/fileutil/fileutil.go
generated
vendored
121
vendor/github.com/coreos/etcd/pkg/fileutil/fileutil.go
generated
vendored
|
@ -1,121 +0,0 @@
|
||||||
// Copyright 2015 The etcd Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// Package fileutil implements utility functions related to files and paths.
|
|
||||||
package fileutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"sort"
|
|
||||||
|
|
||||||
"github.com/coreos/pkg/capnslog"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// PrivateFileMode grants owner to read/write a file.
|
|
||||||
PrivateFileMode = 0600
|
|
||||||
// PrivateDirMode grants owner to make/remove files inside the directory.
|
|
||||||
PrivateDirMode = 0700
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "pkg/fileutil")
|
|
||||||
)
|
|
||||||
|
|
||||||
// IsDirWriteable checks if dir is writable by writing and removing a file
|
|
||||||
// to dir. It returns nil if dir is writable.
|
|
||||||
func IsDirWriteable(dir string) error {
|
|
||||||
f := path.Join(dir, ".touch")
|
|
||||||
if err := ioutil.WriteFile(f, []byte(""), PrivateFileMode); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return os.Remove(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReadDir returns the filenames in the given directory in sorted order.
|
|
||||||
func ReadDir(dirpath string) ([]string, error) {
|
|
||||||
dir, err := os.Open(dirpath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer dir.Close()
|
|
||||||
names, err := dir.Readdirnames(-1)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
sort.Strings(names)
|
|
||||||
return names, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// TouchDirAll is similar to os.MkdirAll. It creates directories with 0700 permission if any directory
|
|
||||||
// does not exists. TouchDirAll also ensures the given directory is writable.
|
|
||||||
func TouchDirAll(dir string) error {
|
|
||||||
// If path is already a directory, MkdirAll does nothing
|
|
||||||
// and returns nil.
|
|
||||||
err := os.MkdirAll(dir, PrivateDirMode)
|
|
||||||
if err != nil {
|
|
||||||
// if mkdirAll("a/text") and "text" is not
|
|
||||||
// a directory, this will return syscall.ENOTDIR
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return IsDirWriteable(dir)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateDirAll is similar to TouchDirAll but returns error
|
|
||||||
// if the deepest directory was not empty.
|
|
||||||
func CreateDirAll(dir string) error {
|
|
||||||
err := TouchDirAll(dir)
|
|
||||||
if err == nil {
|
|
||||||
var ns []string
|
|
||||||
ns, err = ReadDir(dir)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if len(ns) != 0 {
|
|
||||||
err = fmt.Errorf("expected %q to be empty, got %q", dir, ns)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func Exist(name string) bool {
|
|
||||||
_, err := os.Stat(name)
|
|
||||||
return err == nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ZeroToEnd zeros a file starting from SEEK_CUR to its SEEK_END. May temporarily
|
|
||||||
// shorten the length of the file.
|
|
||||||
func ZeroToEnd(f *os.File) error {
|
|
||||||
// TODO: support FALLOC_FL_ZERO_RANGE
|
|
||||||
off, err := f.Seek(0, os.SEEK_CUR)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
lenf, lerr := f.Seek(0, os.SEEK_END)
|
|
||||||
if lerr != nil {
|
|
||||||
return lerr
|
|
||||||
}
|
|
||||||
if err = f.Truncate(off); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// make sure blocks remain allocated
|
|
||||||
if err = Preallocate(f, lenf, true); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = f.Seek(off, os.SEEK_SET)
|
|
||||||
return err
|
|
||||||
}
|
|
26
vendor/github.com/coreos/etcd/pkg/fileutil/lock.go
generated
vendored
26
vendor/github.com/coreos/etcd/pkg/fileutil/lock.go
generated
vendored
|
@ -1,26 +0,0 @@
|
||||||
// Copyright 2016 The etcd Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package fileutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
ErrLocked = errors.New("fileutil: file already locked")
|
|
||||||
)
|
|
||||||
|
|
||||||
type LockedFile struct{ *os.File }
|
|
49
vendor/github.com/coreos/etcd/pkg/fileutil/lock_flock.go
generated
vendored
49
vendor/github.com/coreos/etcd/pkg/fileutil/lock_flock.go
generated
vendored
|
@ -1,49 +0,0 @@
|
||||||
// Copyright 2016 The etcd Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build !windows,!plan9,!solaris
|
|
||||||
|
|
||||||
package fileutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
func flockTryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) {
|
|
||||||
f, err := os.OpenFile(path, flag, perm)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err = syscall.Flock(int(f.Fd()), syscall.LOCK_EX|syscall.LOCK_NB); err != nil {
|
|
||||||
f.Close()
|
|
||||||
if err == syscall.EWOULDBLOCK {
|
|
||||||
err = ErrLocked
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &LockedFile{f}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func flockLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) {
|
|
||||||
f, err := os.OpenFile(path, flag, perm)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err = syscall.Flock(int(f.Fd()), syscall.LOCK_EX); err != nil {
|
|
||||||
f.Close()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &LockedFile{f}, err
|
|
||||||
}
|
|
96
vendor/github.com/coreos/etcd/pkg/fileutil/lock_linux.go
generated
vendored
96
vendor/github.com/coreos/etcd/pkg/fileutil/lock_linux.go
generated
vendored
|
@ -1,96 +0,0 @@
|
||||||
// Copyright 2016 The etcd Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build linux
|
|
||||||
|
|
||||||
package fileutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// This used to call syscall.Flock() but that call fails with EBADF on NFS.
|
|
||||||
// An alternative is lockf() which works on NFS but that call lets a process lock
|
|
||||||
// the same file twice. Instead, use Linux's non-standard open file descriptor
|
|
||||||
// locks which will block if the process already holds the file lock.
|
|
||||||
//
|
|
||||||
// constants from /usr/include/bits/fcntl-linux.h
|
|
||||||
const (
|
|
||||||
F_OFD_GETLK = 37
|
|
||||||
F_OFD_SETLK = 37
|
|
||||||
F_OFD_SETLKW = 38
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
wrlck = syscall.Flock_t{
|
|
||||||
Type: syscall.F_WRLCK,
|
|
||||||
Whence: int16(os.SEEK_SET),
|
|
||||||
Start: 0,
|
|
||||||
Len: 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
linuxTryLockFile = flockTryLockFile
|
|
||||||
linuxLockFile = flockLockFile
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
// use open file descriptor locks if the system supports it
|
|
||||||
getlk := syscall.Flock_t{Type: syscall.F_RDLCK}
|
|
||||||
if err := syscall.FcntlFlock(0, F_OFD_GETLK, &getlk); err == nil {
|
|
||||||
linuxTryLockFile = ofdTryLockFile
|
|
||||||
linuxLockFile = ofdLockFile
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) {
|
|
||||||
return linuxTryLockFile(path, flag, perm)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ofdTryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) {
|
|
||||||
f, err := os.OpenFile(path, flag, perm)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
flock := wrlck
|
|
||||||
if err = syscall.FcntlFlock(f.Fd(), F_OFD_SETLK, &flock); err != nil {
|
|
||||||
f.Close()
|
|
||||||
if err == syscall.EWOULDBLOCK {
|
|
||||||
err = ErrLocked
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &LockedFile{f}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) {
|
|
||||||
return linuxLockFile(path, flag, perm)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ofdLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) {
|
|
||||||
f, err := os.OpenFile(path, flag, perm)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
flock := wrlck
|
|
||||||
err = syscall.FcntlFlock(f.Fd(), F_OFD_SETLKW, &flock)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
f.Close()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &LockedFile{f}, err
|
|
||||||
}
|
|
45
vendor/github.com/coreos/etcd/pkg/fileutil/lock_plan9.go
generated
vendored
45
vendor/github.com/coreos/etcd/pkg/fileutil/lock_plan9.go
generated
vendored
|
@ -1,45 +0,0 @@
|
||||||
// Copyright 2015 The etcd Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package fileutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) {
|
|
||||||
if err := os.Chmod(path, syscall.DMEXCL|PrivateFileMode); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
f, err := os.Open(path, flag, perm)
|
|
||||||
if err != nil {
|
|
||||||
return nil, ErrLocked
|
|
||||||
}
|
|
||||||
return &LockedFile{f}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) {
|
|
||||||
if err := os.Chmod(path, syscall.DMEXCL|PrivateFileMode); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
for {
|
|
||||||
f, err := os.OpenFile(path, flag, perm)
|
|
||||||
if err == nil {
|
|
||||||
return &LockedFile{f}, nil
|
|
||||||
}
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
62
vendor/github.com/coreos/etcd/pkg/fileutil/lock_solaris.go
generated
vendored
62
vendor/github.com/coreos/etcd/pkg/fileutil/lock_solaris.go
generated
vendored
|
@ -1,62 +0,0 @@
|
||||||
// Copyright 2015 The etcd Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build solaris
|
|
||||||
|
|
||||||
package fileutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) {
|
|
||||||
var lock syscall.Flock_t
|
|
||||||
lock.Start = 0
|
|
||||||
lock.Len = 0
|
|
||||||
lock.Pid = 0
|
|
||||||
lock.Type = syscall.F_WRLCK
|
|
||||||
lock.Whence = 0
|
|
||||||
lock.Pid = 0
|
|
||||||
f, err := os.OpenFile(path, flag, perm)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := syscall.FcntlFlock(f.Fd(), syscall.F_SETLK, &lock); err != nil {
|
|
||||||
f.Close()
|
|
||||||
if err == syscall.EAGAIN {
|
|
||||||
err = ErrLocked
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &LockedFile{f}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) {
|
|
||||||
var lock syscall.Flock_t
|
|
||||||
lock.Start = 0
|
|
||||||
lock.Len = 0
|
|
||||||
lock.Pid = 0
|
|
||||||
lock.Type = syscall.F_WRLCK
|
|
||||||
lock.Whence = 0
|
|
||||||
f, err := os.OpenFile(path, flag, perm)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err = syscall.FcntlFlock(f.Fd(), syscall.F_SETLKW, &lock); err != nil {
|
|
||||||
f.Close()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &LockedFile{f}, nil
|
|
||||||
}
|
|
29
vendor/github.com/coreos/etcd/pkg/fileutil/lock_unix.go
generated
vendored
29
vendor/github.com/coreos/etcd/pkg/fileutil/lock_unix.go
generated
vendored
|
@ -1,29 +0,0 @@
|
||||||
// Copyright 2015 The etcd Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build !windows,!plan9,!solaris,!linux
|
|
||||||
|
|
||||||
package fileutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) {
|
|
||||||
return flockTryLockFile(path, flag, perm)
|
|
||||||
}
|
|
||||||
|
|
||||||
func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) {
|
|
||||||
return flockLockFile(path, flag, perm)
|
|
||||||
}
|
|
125
vendor/github.com/coreos/etcd/pkg/fileutil/lock_windows.go
generated
vendored
125
vendor/github.com/coreos/etcd/pkg/fileutil/lock_windows.go
generated
vendored
|
@ -1,125 +0,0 @@
|
||||||
// Copyright 2015 The etcd Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package fileutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
|
|
||||||
procLockFileEx = modkernel32.NewProc("LockFileEx")
|
|
||||||
|
|
||||||
errLocked = errors.New("The process cannot access the file because another process has locked a portion of the file.")
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa365203(v=vs.85).aspx
|
|
||||||
LOCKFILE_EXCLUSIVE_LOCK = 2
|
|
||||||
LOCKFILE_FAIL_IMMEDIATELY = 1
|
|
||||||
|
|
||||||
// see https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx
|
|
||||||
errLockViolation syscall.Errno = 0x21
|
|
||||||
)
|
|
||||||
|
|
||||||
func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) {
|
|
||||||
f, err := open(path, flag, perm)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := lockFile(syscall.Handle(f.Fd()), LOCKFILE_FAIL_IMMEDIATELY); err != nil {
|
|
||||||
f.Close()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &LockedFile{f}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) {
|
|
||||||
f, err := open(path, flag, perm)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := lockFile(syscall.Handle(f.Fd()), 0); err != nil {
|
|
||||||
f.Close()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &LockedFile{f}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func open(path string, flag int, perm os.FileMode) (*os.File, error) {
|
|
||||||
if path == "" {
|
|
||||||
return nil, fmt.Errorf("cannot open empty filename")
|
|
||||||
}
|
|
||||||
var access uint32
|
|
||||||
switch flag {
|
|
||||||
case syscall.O_RDONLY:
|
|
||||||
access = syscall.GENERIC_READ
|
|
||||||
case syscall.O_WRONLY:
|
|
||||||
access = syscall.GENERIC_WRITE
|
|
||||||
case syscall.O_RDWR:
|
|
||||||
access = syscall.GENERIC_READ | syscall.GENERIC_WRITE
|
|
||||||
case syscall.O_WRONLY | syscall.O_CREAT:
|
|
||||||
access = syscall.GENERIC_ALL
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("flag %v is not supported", flag))
|
|
||||||
}
|
|
||||||
fd, err := syscall.CreateFile(&(syscall.StringToUTF16(path)[0]),
|
|
||||||
access,
|
|
||||||
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
|
|
||||||
nil,
|
|
||||||
syscall.OPEN_ALWAYS,
|
|
||||||
syscall.FILE_ATTRIBUTE_NORMAL,
|
|
||||||
0)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return os.NewFile(uintptr(fd), path), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func lockFile(fd syscall.Handle, flags uint32) error {
|
|
||||||
var flag uint32 = LOCKFILE_EXCLUSIVE_LOCK
|
|
||||||
flag |= flags
|
|
||||||
if fd == syscall.InvalidHandle {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
err := lockFileEx(fd, flag, 1, 0, &syscall.Overlapped{})
|
|
||||||
if err == nil {
|
|
||||||
return nil
|
|
||||||
} else if err.Error() == errLocked.Error() {
|
|
||||||
return ErrLocked
|
|
||||||
} else if err != errLockViolation {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func lockFileEx(h syscall.Handle, flags, locklow, lockhigh uint32, ol *syscall.Overlapped) (err error) {
|
|
||||||
var reserved uint32 = 0
|
|
||||||
r1, _, e1 := syscall.Syscall6(procLockFileEx.Addr(), 6, uintptr(h), uintptr(flags), uintptr(reserved), uintptr(locklow), uintptr(lockhigh), uintptr(unsafe.Pointer(ol)))
|
|
||||||
if r1 == 0 {
|
|
||||||
if e1 != 0 {
|
|
||||||
err = error(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
47
vendor/github.com/coreos/etcd/pkg/fileutil/preallocate.go
generated
vendored
47
vendor/github.com/coreos/etcd/pkg/fileutil/preallocate.go
generated
vendored
|
@ -1,47 +0,0 @@
|
||||||
// Copyright 2015 The etcd Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package fileutil
|
|
||||||
|
|
||||||
import "os"
|
|
||||||
|
|
||||||
// Preallocate tries to allocate the space for given
|
|
||||||
// file. This operation is only supported on linux by a
|
|
||||||
// few filesystems (btrfs, ext4, etc.).
|
|
||||||
// If the operation is unsupported, no error will be returned.
|
|
||||||
// Otherwise, the error encountered will be returned.
|
|
||||||
func Preallocate(f *os.File, sizeInBytes int64, extendFile bool) error {
|
|
||||||
if extendFile {
|
|
||||||
return preallocExtend(f, sizeInBytes)
|
|
||||||
}
|
|
||||||
return preallocFixed(f, sizeInBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
func preallocExtendTrunc(f *os.File, sizeInBytes int64) error {
|
|
||||||
curOff, err := f.Seek(0, os.SEEK_CUR)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
size, err := f.Seek(sizeInBytes, os.SEEK_END)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err = f.Seek(curOff, os.SEEK_SET); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if sizeInBytes > size {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return f.Truncate(sizeInBytes)
|
|
||||||
}
|
|
43
vendor/github.com/coreos/etcd/pkg/fileutil/preallocate_darwin.go
generated
vendored
43
vendor/github.com/coreos/etcd/pkg/fileutil/preallocate_darwin.go
generated
vendored
|
@ -1,43 +0,0 @@
|
||||||
// Copyright 2016 The etcd Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build darwin
|
|
||||||
|
|
||||||
package fileutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
func preallocExtend(f *os.File, sizeInBytes int64) error {
|
|
||||||
if err := preallocFixed(f, sizeInBytes); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return preallocExtendTrunc(f, sizeInBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
func preallocFixed(f *os.File, sizeInBytes int64) error {
|
|
||||||
fstore := &syscall.Fstore_t{
|
|
||||||
Flags: syscall.F_ALLOCATEALL,
|
|
||||||
Posmode: syscall.F_PEOFPOSMODE,
|
|
||||||
Length: sizeInBytes}
|
|
||||||
p := unsafe.Pointer(fstore)
|
|
||||||
_, _, errno := syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), uintptr(syscall.F_PREALLOCATE), uintptr(p))
|
|
||||||
if errno == 0 || errno == syscall.ENOTSUP {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return errno
|
|
||||||
}
|
|
49
vendor/github.com/coreos/etcd/pkg/fileutil/preallocate_unix.go
generated
vendored
49
vendor/github.com/coreos/etcd/pkg/fileutil/preallocate_unix.go
generated
vendored
|
@ -1,49 +0,0 @@
|
||||||
// Copyright 2016 The etcd Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build linux
|
|
||||||
|
|
||||||
package fileutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
func preallocExtend(f *os.File, sizeInBytes int64) error {
|
|
||||||
// use mode = 0 to change size
|
|
||||||
err := syscall.Fallocate(int(f.Fd()), 0, 0, sizeInBytes)
|
|
||||||
if err != nil {
|
|
||||||
errno, ok := err.(syscall.Errno)
|
|
||||||
// not supported; fallback
|
|
||||||
// fallocate EINTRs frequently in some environments; fallback
|
|
||||||
if ok && (errno == syscall.ENOTSUP || errno == syscall.EINTR) {
|
|
||||||
return preallocExtendTrunc(f, sizeInBytes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func preallocFixed(f *os.File, sizeInBytes int64) error {
|
|
||||||
// use mode = 1 to keep size; see FALLOC_FL_KEEP_SIZE
|
|
||||||
err := syscall.Fallocate(int(f.Fd()), 1, 0, sizeInBytes)
|
|
||||||
if err != nil {
|
|
||||||
errno, ok := err.(syscall.Errno)
|
|
||||||
// treat not supported as nil error
|
|
||||||
if ok && errno == syscall.ENOTSUP {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
25
vendor/github.com/coreos/etcd/pkg/fileutil/preallocate_unsupported.go
generated
vendored
25
vendor/github.com/coreos/etcd/pkg/fileutil/preallocate_unsupported.go
generated
vendored
|
@ -1,25 +0,0 @@
|
||||||
// Copyright 2015 The etcd Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build !linux,!darwin
|
|
||||||
|
|
||||||
package fileutil
|
|
||||||
|
|
||||||
import "os"
|
|
||||||
|
|
||||||
func preallocExtend(f *os.File, sizeInBytes int64) error {
|
|
||||||
return preallocExtendTrunc(f, sizeInBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
func preallocFixed(f *os.File, sizeInBytes int64) error { return nil }
|
|
78
vendor/github.com/coreos/etcd/pkg/fileutil/purge.go
generated
vendored
78
vendor/github.com/coreos/etcd/pkg/fileutil/purge.go
generated
vendored
|
@ -1,78 +0,0 @@
|
||||||
// Copyright 2015 The etcd Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package fileutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"sort"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func PurgeFile(dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) <-chan error {
|
|
||||||
return purgeFile(dirname, suffix, max, interval, stop, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// purgeFile is the internal implementation for PurgeFile which can post purged files to purgec if non-nil.
|
|
||||||
func purgeFile(dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}, purgec chan<- string) <-chan error {
|
|
||||||
errC := make(chan error, 1)
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
fnames, err := ReadDir(dirname)
|
|
||||||
if err != nil {
|
|
||||||
errC <- err
|
|
||||||
return
|
|
||||||
}
|
|
||||||
newfnames := make([]string, 0)
|
|
||||||
for _, fname := range fnames {
|
|
||||||
if strings.HasSuffix(fname, suffix) {
|
|
||||||
newfnames = append(newfnames, fname)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sort.Strings(newfnames)
|
|
||||||
fnames = newfnames
|
|
||||||
for len(newfnames) > int(max) {
|
|
||||||
f := path.Join(dirname, newfnames[0])
|
|
||||||
l, err := TryLockFile(f, os.O_WRONLY, PrivateFileMode)
|
|
||||||
if err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err = os.Remove(f); err != nil {
|
|
||||||
errC <- err
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err = l.Close(); err != nil {
|
|
||||||
plog.Errorf("error unlocking %s when purging file (%v)", l.Name(), err)
|
|
||||||
errC <- err
|
|
||||||
return
|
|
||||||
}
|
|
||||||
plog.Infof("purged file %s successfully", f)
|
|
||||||
newfnames = newfnames[1:]
|
|
||||||
}
|
|
||||||
if purgec != nil {
|
|
||||||
for i := 0; i < len(fnames)-len(newfnames); i++ {
|
|
||||||
purgec <- fnames[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
select {
|
|
||||||
case <-time.After(interval):
|
|
||||||
case <-stop:
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
return errC
|
|
||||||
}
|
|
29
vendor/github.com/coreos/etcd/pkg/fileutil/sync.go
generated
vendored
29
vendor/github.com/coreos/etcd/pkg/fileutil/sync.go
generated
vendored
|
@ -1,29 +0,0 @@
|
||||||
// Copyright 2016 The etcd Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build !linux,!darwin
|
|
||||||
|
|
||||||
package fileutil
|
|
||||||
|
|
||||||
import "os"
|
|
||||||
|
|
||||||
// Fsync is a wrapper around file.Sync(). Special handling is needed on darwin platform.
|
|
||||||
func Fsync(f *os.File) error {
|
|
||||||
return f.Sync()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fdatasync is a wrapper around file.Sync(). Special handling is needed on linux platform.
|
|
||||||
func Fdatasync(f *os.File) error {
|
|
||||||
return f.Sync()
|
|
||||||
}
|
|
40
vendor/github.com/coreos/etcd/pkg/fileutil/sync_darwin.go
generated
vendored
40
vendor/github.com/coreos/etcd/pkg/fileutil/sync_darwin.go
generated
vendored
|
@ -1,40 +0,0 @@
|
||||||
// Copyright 2016 The etcd Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build darwin
|
|
||||||
|
|
||||||
package fileutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Fsync on HFS/OSX flushes the data on to the physical drive but the drive
|
|
||||||
// may not write it to the persistent media for quite sometime and it may be
|
|
||||||
// written in out-of-order sequence. Using F_FULLFSYNC ensures that the
|
|
||||||
// physical drive's buffer will also get flushed to the media.
|
|
||||||
func Fsync(f *os.File) error {
|
|
||||||
_, _, errno := syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), uintptr(syscall.F_FULLFSYNC), uintptr(0))
|
|
||||||
if errno == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return errno
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fdatasync on darwin platform invokes fcntl(F_FULLFSYNC) for actual persistence
|
|
||||||
// on physical drive media.
|
|
||||||
func Fdatasync(f *os.File) error {
|
|
||||||
return Fsync(f)
|
|
||||||
}
|
|
34
vendor/github.com/coreos/etcd/pkg/fileutil/sync_linux.go
generated
vendored
34
vendor/github.com/coreos/etcd/pkg/fileutil/sync_linux.go
generated
vendored
|
@ -1,34 +0,0 @@
|
||||||
// Copyright 2016 The etcd Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build linux
|
|
||||||
|
|
||||||
package fileutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Fsync is a wrapper around file.Sync(). Special handling is needed on darwin platform.
|
|
||||||
func Fsync(f *os.File) error {
|
|
||||||
return f.Sync()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fdatasync is similar to fsync(), but does not flush modified metadata
|
|
||||||
// unless that metadata is needed in order to allow a subsequent data retrieval
|
|
||||||
// to be correctly handled.
|
|
||||||
func Fdatasync(f *os.File) error {
|
|
||||||
return syscall.Fdatasync(int(f.Fd()))
|
|
||||||
}
|
|
191
vendor/github.com/coreos/go-systemd/LICENSE
generated
vendored
191
vendor/github.com/coreos/go-systemd/LICENSE
generated
vendored
|
@ -1,191 +0,0 @@
|
||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction, and
|
|
||||||
distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
|
||||||
owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all other entities
|
|
||||||
that control, are controlled by, or are under common control with that entity.
|
|
||||||
For the purposes of this definition, "control" means (i) the power, direct or
|
|
||||||
indirect, to cause the direction or management of such entity, whether by
|
|
||||||
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
||||||
permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications, including
|
|
||||||
but not limited to software source code, documentation source, and configuration
|
|
||||||
files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical transformation or
|
|
||||||
translation of a Source form, including but not limited to compiled object code,
|
|
||||||
generated documentation, and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or Object form, made
|
|
||||||
available under the License, as indicated by a copyright notice that is included
|
|
||||||
in or attached to the work (an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
|
||||||
is based on (or derived from) the Work and for which the editorial revisions,
|
|
||||||
annotations, elaborations, or other modifications represent, as a whole, an
|
|
||||||
original work of authorship. For the purposes of this License, Derivative Works
|
|
||||||
shall not include works that remain separable from, or merely link (or bind by
|
|
||||||
name) to the interfaces of, the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including the original version
|
|
||||||
of the Work and any modifications or additions to that Work or Derivative Works
|
|
||||||
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
|
||||||
by the copyright owner or by an individual or Legal Entity authorized to submit
|
|
||||||
on behalf of the copyright owner. For the purposes of this definition,
|
|
||||||
"submitted" means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems, and
|
|
||||||
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
|
||||||
the purpose of discussing and improving the Work, but excluding communication
|
|
||||||
that is conspicuously marked or otherwise designated in writing by the copyright
|
|
||||||
owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
|
||||||
of whom a Contribution has been received by Licensor and subsequently
|
|
||||||
incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License.
|
|
||||||
|
|
||||||
Subject to the terms and conditions of this License, each Contributor hereby
|
|
||||||
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
|
||||||
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the Work and such
|
|
||||||
Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License.
|
|
||||||
|
|
||||||
Subject to the terms and conditions of this License, each Contributor hereby
|
|
||||||
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
|
||||||
irrevocable (except as stated in this section) patent license to make, have
|
|
||||||
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
|
||||||
such license applies only to those patent claims licensable by such Contributor
|
|
||||||
that are necessarily infringed by their Contribution(s) alone or by combination
|
|
||||||
of their Contribution(s) with the Work to which such Contribution(s) was
|
|
||||||
submitted. If You institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
|
||||||
Contribution incorporated within the Work constitutes direct or contributory
|
|
||||||
patent infringement, then any patent licenses granted to You under this License
|
|
||||||
for that Work shall terminate as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution.
|
|
||||||
|
|
||||||
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
|
||||||
in any medium, with or without modifications, and in Source or Object form,
|
|
||||||
provided that You meet the following conditions:
|
|
||||||
|
|
||||||
You must give any other recipients of the Work or Derivative Works a copy of
|
|
||||||
this License; and
|
|
||||||
You must cause any modified files to carry prominent notices stating that You
|
|
||||||
changed the files; and
|
|
||||||
You must retain, in the Source form of any Derivative Works that You distribute,
|
|
||||||
all copyright, patent, trademark, and attribution notices from the Source form
|
|
||||||
of the Work, excluding those notices that do not pertain to any part of the
|
|
||||||
Derivative Works; and
|
|
||||||
If the Work includes a "NOTICE" text file as part of its distribution, then any
|
|
||||||
Derivative Works that You distribute must include a readable copy of the
|
|
||||||
attribution notices contained within such NOTICE file, excluding those notices
|
|
||||||
that do not pertain to any part of the Derivative Works, in at least one of the
|
|
||||||
following places: within a NOTICE text file distributed as part of the
|
|
||||||
Derivative Works; within the Source form or documentation, if provided along
|
|
||||||
with the Derivative Works; or, within a display generated by the Derivative
|
|
||||||
Works, if and wherever such third-party notices normally appear. The contents of
|
|
||||||
the NOTICE file are for informational purposes only and do not modify the
|
|
||||||
License. You may add Your own attribution notices within Derivative Works that
|
|
||||||
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
|
||||||
provided that such additional attribution notices cannot be construed as
|
|
||||||
modifying the License.
|
|
||||||
You may add Your own copyright statement to Your modifications and may provide
|
|
||||||
additional or different license terms and conditions for use, reproduction, or
|
|
||||||
distribution of Your modifications, or for any such Derivative Works as a whole,
|
|
||||||
provided Your use, reproduction, and distribution of the Work otherwise complies
|
|
||||||
with the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions.
|
|
||||||
|
|
||||||
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
|
||||||
for inclusion in the Work by You to the Licensor shall be under the terms and
|
|
||||||
conditions of this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
|
||||||
any separate license agreement you may have executed with Licensor regarding
|
|
||||||
such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks.
|
|
||||||
|
|
||||||
This License does not grant permission to use the trade names, trademarks,
|
|
||||||
service marks, or product names of the Licensor, except as required for
|
|
||||||
reasonable and customary use in describing the origin of the Work and
|
|
||||||
reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, Licensor provides the
|
|
||||||
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
|
||||||
including, without limitation, any warranties or conditions of TITLE,
|
|
||||||
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
|
||||||
solely responsible for determining the appropriateness of using or
|
|
||||||
redistributing the Work and assume any risks associated with Your exercise of
|
|
||||||
permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability.
|
|
||||||
|
|
||||||
In no event and under no legal theory, whether in tort (including negligence),
|
|
||||||
contract, or otherwise, unless required by applicable law (such as deliberate
|
|
||||||
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special, incidental,
|
|
||||||
or consequential damages of any character arising as a result of this License or
|
|
||||||
out of the use or inability to use the Work (including but not limited to
|
|
||||||
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
|
||||||
any and all other commercial damages or losses), even if such Contributor has
|
|
||||||
been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability.
|
|
||||||
|
|
||||||
While redistributing the Work or Derivative Works thereof, You may choose to
|
|
||||||
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
|
||||||
other liability obligations and/or rights consistent with this License. However,
|
|
||||||
in accepting such obligations, You may act only on Your own behalf and on Your
|
|
||||||
sole responsibility, not on behalf of any other Contributor, and only if You
|
|
||||||
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason of your
|
|
||||||
accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following boilerplate
|
|
||||||
notice, with the fields enclosed by brackets "[]" replaced with your own
|
|
||||||
identifying information. (Don't include the brackets!) The text should be
|
|
||||||
enclosed in the appropriate comment syntax for the file format. We also
|
|
||||||
recommend that a file or class name and description of purpose be included on
|
|
||||||
the same "printed page" as the copyright notice for easier identification within
|
|
||||||
third-party archives.
|
|
||||||
|
|
||||||
Copyright [yyyy] [name of copyright owner]
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
179
vendor/github.com/coreos/go-systemd/journal/journal.go
generated
vendored
179
vendor/github.com/coreos/go-systemd/journal/journal.go
generated
vendored
|
@ -1,179 +0,0 @@
|
||||||
// Copyright 2015 CoreOS, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// Package journal provides write bindings to the local systemd journal.
|
|
||||||
// It is implemented in pure Go and connects to the journal directly over its
|
|
||||||
// unix socket.
|
|
||||||
//
|
|
||||||
// To read from the journal, see the "sdjournal" package, which wraps the
|
|
||||||
// sd-journal a C API.
|
|
||||||
//
|
|
||||||
// http://www.freedesktop.org/software/systemd/man/systemd-journald.service.html
|
|
||||||
package journal
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/binary"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Priority of a journal message
|
|
||||||
type Priority int
|
|
||||||
|
|
||||||
const (
|
|
||||||
PriEmerg Priority = iota
|
|
||||||
PriAlert
|
|
||||||
PriCrit
|
|
||||||
PriErr
|
|
||||||
PriWarning
|
|
||||||
PriNotice
|
|
||||||
PriInfo
|
|
||||||
PriDebug
|
|
||||||
)
|
|
||||||
|
|
||||||
var conn net.Conn
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
var err error
|
|
||||||
conn, err = net.Dial("unixgram", "/run/systemd/journal/socket")
|
|
||||||
if err != nil {
|
|
||||||
conn = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enabled returns true if the local systemd journal is available for logging
|
|
||||||
func Enabled() bool {
|
|
||||||
return conn != nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send a message to the local systemd journal. vars is a map of journald
|
|
||||||
// fields to values. Fields must be composed of uppercase letters, numbers,
|
|
||||||
// and underscores, but must not start with an underscore. Within these
|
|
||||||
// restrictions, any arbitrary field name may be used. Some names have special
|
|
||||||
// significance: see the journalctl documentation
|
|
||||||
// (http://www.freedesktop.org/software/systemd/man/systemd.journal-fields.html)
|
|
||||||
// for more details. vars may be nil.
|
|
||||||
func Send(message string, priority Priority, vars map[string]string) error {
|
|
||||||
if conn == nil {
|
|
||||||
return journalError("could not connect to journald socket")
|
|
||||||
}
|
|
||||||
|
|
||||||
data := new(bytes.Buffer)
|
|
||||||
appendVariable(data, "PRIORITY", strconv.Itoa(int(priority)))
|
|
||||||
appendVariable(data, "MESSAGE", message)
|
|
||||||
for k, v := range vars {
|
|
||||||
appendVariable(data, k, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := io.Copy(conn, data)
|
|
||||||
if err != nil && isSocketSpaceError(err) {
|
|
||||||
file, err := tempFd()
|
|
||||||
if err != nil {
|
|
||||||
return journalError(err.Error())
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
_, err = io.Copy(file, data)
|
|
||||||
if err != nil {
|
|
||||||
return journalError(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
rights := syscall.UnixRights(int(file.Fd()))
|
|
||||||
|
|
||||||
/* this connection should always be a UnixConn, but better safe than sorry */
|
|
||||||
unixConn, ok := conn.(*net.UnixConn)
|
|
||||||
if !ok {
|
|
||||||
return journalError("can't send file through non-Unix connection")
|
|
||||||
}
|
|
||||||
unixConn.WriteMsgUnix([]byte{}, rights, nil)
|
|
||||||
} else if err != nil {
|
|
||||||
return journalError(err.Error())
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print prints a message to the local systemd journal using Send().
|
|
||||||
func Print(priority Priority, format string, a ...interface{}) error {
|
|
||||||
return Send(fmt.Sprintf(format, a...), priority, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func appendVariable(w io.Writer, name, value string) {
|
|
||||||
if !validVarName(name) {
|
|
||||||
journalError("variable name contains invalid character, ignoring")
|
|
||||||
}
|
|
||||||
if strings.ContainsRune(value, '\n') {
|
|
||||||
/* When the value contains a newline, we write:
|
|
||||||
* - the variable name, followed by a newline
|
|
||||||
* - the size (in 64bit little endian format)
|
|
||||||
* - the data, followed by a newline
|
|
||||||
*/
|
|
||||||
fmt.Fprintln(w, name)
|
|
||||||
binary.Write(w, binary.LittleEndian, uint64(len(value)))
|
|
||||||
fmt.Fprintln(w, value)
|
|
||||||
} else {
|
|
||||||
/* just write the variable and value all on one line */
|
|
||||||
fmt.Fprintf(w, "%s=%s\n", name, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func validVarName(name string) bool {
|
|
||||||
/* The variable name must be in uppercase and consist only of characters,
|
|
||||||
* numbers and underscores, and may not begin with an underscore. (from the docs)
|
|
||||||
*/
|
|
||||||
|
|
||||||
valid := name[0] != '_'
|
|
||||||
for _, c := range name {
|
|
||||||
valid = valid && ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || c == '_'
|
|
||||||
}
|
|
||||||
return valid
|
|
||||||
}
|
|
||||||
|
|
||||||
func isSocketSpaceError(err error) bool {
|
|
||||||
opErr, ok := err.(*net.OpError)
|
|
||||||
if !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
sysErr, ok := opErr.Err.(syscall.Errno)
|
|
||||||
if !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return sysErr == syscall.EMSGSIZE || sysErr == syscall.ENOBUFS
|
|
||||||
}
|
|
||||||
|
|
||||||
func tempFd() (*os.File, error) {
|
|
||||||
file, err := ioutil.TempFile("/dev/shm/", "journal.XXXXX")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
syscall.Unlink(file.Name())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return file, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func journalError(s string) error {
|
|
||||||
s = "journal error: " + s
|
|
||||||
fmt.Fprintln(os.Stderr, s)
|
|
||||||
return errors.New(s)
|
|
||||||
}
|
|
39
vendor/github.com/coreos/pkg/capnslog/README.md
generated
vendored
39
vendor/github.com/coreos/pkg/capnslog/README.md
generated
vendored
|
@ -1,39 +0,0 @@
|
||||||
# capnslog, the CoreOS logging package
|
|
||||||
|
|
||||||
There are far too many logging packages out there, with varying degrees of licenses, far too many features (colorization, all sorts of log frameworks) or are just a pain to use (lack of `Fatalln()`?).
|
|
||||||
capnslog provides a simple but consistent logging interface suitable for all kinds of projects.
|
|
||||||
|
|
||||||
### Design Principles
|
|
||||||
|
|
||||||
##### `package main` is the place where logging gets turned on and routed
|
|
||||||
|
|
||||||
A library should not touch log options, only generate log entries. Libraries are silent until main lets them speak.
|
|
||||||
|
|
||||||
##### All log options are runtime-configurable.
|
|
||||||
|
|
||||||
Still the job of `main` to expose these configurations. `main` may delegate this to, say, a configuration webhook, but does so explicitly.
|
|
||||||
|
|
||||||
##### There is one log object per package. It is registered under its repository and package name.
|
|
||||||
|
|
||||||
`main` activates logging for its repository and any dependency repositories it would also like to have output in its logstream. `main` also dictates at which level each subpackage logs.
|
|
||||||
|
|
||||||
##### There is *one* output stream, and it is an `io.Writer` composed with a formatter.
|
|
||||||
|
|
||||||
Splitting streams is probably not the job of your program, but rather, your log aggregation framework. If you must split output streams, again, `main` configures this and you can write a very simple two-output struct that satisfies io.Writer.
|
|
||||||
|
|
||||||
Fancy colorful formatting and JSON output are beyond the scope of a basic logging framework -- they're application/log-collector dependant. These are, at best, provided as options, but more likely, provided by your application.
|
|
||||||
|
|
||||||
##### Log objects are an interface
|
|
||||||
|
|
||||||
An object knows best how to print itself. Log objects can collect more interesting metadata if they wish, however, because text isn't going away anytime soon, they must all be marshalable to text. The simplest log object is a string, which returns itself. If you wish to do more fancy tricks for printing your log objects, see also JSON output -- introspect and write a formatter which can handle your advanced log interface. Making strings is the only thing guaranteed.
|
|
||||||
|
|
||||||
##### Log levels have specific meanings:
|
|
||||||
|
|
||||||
* Critical: Unrecoverable. Must fail.
|
|
||||||
* Error: Data has been lost, a request has failed for a bad reason, or a required resource has been lost
|
|
||||||
* Warning: (Hopefully) Temporary conditions that may cause errors, but may work fine. A replica disappearing (that may reconnect) is a warning.
|
|
||||||
* Notice: Normal, but important (uncommon) log information.
|
|
||||||
* Info: Normal, working log information, everything is fine, but helpful notices for auditing or common operations.
|
|
||||||
* Debug: Everything is still fine, but even common operations may be logged, and less helpful but more quantity of notices.
|
|
||||||
* Trace: Anything goes, from logging every function call as part of a common operation, to tracing execution of a query.
|
|
||||||
|
|
157
vendor/github.com/coreos/pkg/capnslog/formatters.go
generated
vendored
157
vendor/github.com/coreos/pkg/capnslog/formatters.go
generated
vendored
|
@ -1,157 +0,0 @@
|
||||||
// Copyright 2015 CoreOS, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package capnslog
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"log"
|
|
||||||
"runtime"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Formatter interface {
|
|
||||||
Format(pkg string, level LogLevel, depth int, entries ...interface{})
|
|
||||||
Flush()
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewStringFormatter(w io.Writer) Formatter {
|
|
||||||
return &StringFormatter{
|
|
||||||
w: bufio.NewWriter(w),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type StringFormatter struct {
|
|
||||||
w *bufio.Writer
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *StringFormatter) Format(pkg string, l LogLevel, i int, entries ...interface{}) {
|
|
||||||
now := time.Now().UTC()
|
|
||||||
s.w.WriteString(now.Format(time.RFC3339))
|
|
||||||
s.w.WriteByte(' ')
|
|
||||||
writeEntries(s.w, pkg, l, i, entries...)
|
|
||||||
s.Flush()
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeEntries(w *bufio.Writer, pkg string, _ LogLevel, _ int, entries ...interface{}) {
|
|
||||||
if pkg != "" {
|
|
||||||
w.WriteString(pkg + ": ")
|
|
||||||
}
|
|
||||||
str := fmt.Sprint(entries...)
|
|
||||||
endsInNL := strings.HasSuffix(str, "\n")
|
|
||||||
w.WriteString(str)
|
|
||||||
if !endsInNL {
|
|
||||||
w.WriteString("\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *StringFormatter) Flush() {
|
|
||||||
s.w.Flush()
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewPrettyFormatter(w io.Writer, debug bool) Formatter {
|
|
||||||
return &PrettyFormatter{
|
|
||||||
w: bufio.NewWriter(w),
|
|
||||||
debug: debug,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type PrettyFormatter struct {
|
|
||||||
w *bufio.Writer
|
|
||||||
debug bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *PrettyFormatter) Format(pkg string, l LogLevel, depth int, entries ...interface{}) {
|
|
||||||
now := time.Now()
|
|
||||||
ts := now.Format("2006-01-02 15:04:05")
|
|
||||||
c.w.WriteString(ts)
|
|
||||||
ms := now.Nanosecond() / 1000
|
|
||||||
c.w.WriteString(fmt.Sprintf(".%06d", ms))
|
|
||||||
if c.debug {
|
|
||||||
_, file, line, ok := runtime.Caller(depth) // It's always the same number of frames to the user's call.
|
|
||||||
if !ok {
|
|
||||||
file = "???"
|
|
||||||
line = 1
|
|
||||||
} else {
|
|
||||||
slash := strings.LastIndex(file, "/")
|
|
||||||
if slash >= 0 {
|
|
||||||
file = file[slash+1:]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if line < 0 {
|
|
||||||
line = 0 // not a real line number
|
|
||||||
}
|
|
||||||
c.w.WriteString(fmt.Sprintf(" [%s:%d]", file, line))
|
|
||||||
}
|
|
||||||
c.w.WriteString(fmt.Sprint(" ", l.Char(), " | "))
|
|
||||||
writeEntries(c.w, pkg, l, depth, entries...)
|
|
||||||
c.Flush()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *PrettyFormatter) Flush() {
|
|
||||||
c.w.Flush()
|
|
||||||
}
|
|
||||||
|
|
||||||
// LogFormatter emulates the form of the traditional built-in logger.
|
|
||||||
type LogFormatter struct {
|
|
||||||
logger *log.Logger
|
|
||||||
prefix string
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewLogFormatter is a helper to produce a new LogFormatter struct. It uses the
|
|
||||||
// golang log package to actually do the logging work so that logs look similar.
|
|
||||||
func NewLogFormatter(w io.Writer, prefix string, flag int) Formatter {
|
|
||||||
return &LogFormatter{
|
|
||||||
logger: log.New(w, "", flag), // don't use prefix here
|
|
||||||
prefix: prefix, // save it instead
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Format builds a log message for the LogFormatter. The LogLevel is ignored.
|
|
||||||
func (lf *LogFormatter) Format(pkg string, _ LogLevel, _ int, entries ...interface{}) {
|
|
||||||
str := fmt.Sprint(entries...)
|
|
||||||
prefix := lf.prefix
|
|
||||||
if pkg != "" {
|
|
||||||
prefix = fmt.Sprintf("%s%s: ", prefix, pkg)
|
|
||||||
}
|
|
||||||
lf.logger.Output(5, fmt.Sprintf("%s%v", prefix, str)) // call depth is 5
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flush is included so that the interface is complete, but is a no-op.
|
|
||||||
func (lf *LogFormatter) Flush() {
|
|
||||||
// noop
|
|
||||||
}
|
|
||||||
|
|
||||||
// NilFormatter is a no-op log formatter that does nothing.
|
|
||||||
type NilFormatter struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewNilFormatter is a helper to produce a new LogFormatter struct. It logs no
|
|
||||||
// messages so that you can cause part of your logging to be silent.
|
|
||||||
func NewNilFormatter() Formatter {
|
|
||||||
return &NilFormatter{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Format does nothing.
|
|
||||||
func (_ *NilFormatter) Format(_ string, _ LogLevel, _ int, _ ...interface{}) {
|
|
||||||
// noop
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flush is included so that the interface is complete, but is a no-op.
|
|
||||||
func (_ *NilFormatter) Flush() {
|
|
||||||
// noop
|
|
||||||
}
|
|
96
vendor/github.com/coreos/pkg/capnslog/glog_formatter.go
generated
vendored
96
vendor/github.com/coreos/pkg/capnslog/glog_formatter.go
generated
vendored
|
@ -1,96 +0,0 @@
|
||||||
// Copyright 2015 CoreOS, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package capnslog
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"bytes"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"runtime"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var pid = os.Getpid()
|
|
||||||
|
|
||||||
type GlogFormatter struct {
|
|
||||||
StringFormatter
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewGlogFormatter(w io.Writer) *GlogFormatter {
|
|
||||||
g := &GlogFormatter{}
|
|
||||||
g.w = bufio.NewWriter(w)
|
|
||||||
return g
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g GlogFormatter) Format(pkg string, level LogLevel, depth int, entries ...interface{}) {
|
|
||||||
g.w.Write(GlogHeader(level, depth+1))
|
|
||||||
g.StringFormatter.Format(pkg, level, depth+1, entries...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func GlogHeader(level LogLevel, depth int) []byte {
|
|
||||||
// Lmmdd hh:mm:ss.uuuuuu threadid file:line]
|
|
||||||
now := time.Now().UTC()
|
|
||||||
_, file, line, ok := runtime.Caller(depth) // It's always the same number of frames to the user's call.
|
|
||||||
if !ok {
|
|
||||||
file = "???"
|
|
||||||
line = 1
|
|
||||||
} else {
|
|
||||||
slash := strings.LastIndex(file, "/")
|
|
||||||
if slash >= 0 {
|
|
||||||
file = file[slash+1:]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if line < 0 {
|
|
||||||
line = 0 // not a real line number
|
|
||||||
}
|
|
||||||
buf := &bytes.Buffer{}
|
|
||||||
buf.Grow(30)
|
|
||||||
_, month, day := now.Date()
|
|
||||||
hour, minute, second := now.Clock()
|
|
||||||
buf.WriteString(level.Char())
|
|
||||||
twoDigits(buf, int(month))
|
|
||||||
twoDigits(buf, day)
|
|
||||||
buf.WriteByte(' ')
|
|
||||||
twoDigits(buf, hour)
|
|
||||||
buf.WriteByte(':')
|
|
||||||
twoDigits(buf, minute)
|
|
||||||
buf.WriteByte(':')
|
|
||||||
twoDigits(buf, second)
|
|
||||||
buf.WriteByte('.')
|
|
||||||
buf.WriteString(strconv.Itoa(now.Nanosecond() / 1000))
|
|
||||||
buf.WriteByte('Z')
|
|
||||||
buf.WriteByte(' ')
|
|
||||||
buf.WriteString(strconv.Itoa(pid))
|
|
||||||
buf.WriteByte(' ')
|
|
||||||
buf.WriteString(file)
|
|
||||||
buf.WriteByte(':')
|
|
||||||
buf.WriteString(strconv.Itoa(line))
|
|
||||||
buf.WriteByte(']')
|
|
||||||
buf.WriteByte(' ')
|
|
||||||
return buf.Bytes()
|
|
||||||
}
|
|
||||||
|
|
||||||
const digits = "0123456789"
|
|
||||||
|
|
||||||
func twoDigits(b *bytes.Buffer, d int) {
|
|
||||||
c2 := digits[d%10]
|
|
||||||
d /= 10
|
|
||||||
c1 := digits[d%10]
|
|
||||||
b.WriteByte(c1)
|
|
||||||
b.WriteByte(c2)
|
|
||||||
}
|
|
49
vendor/github.com/coreos/pkg/capnslog/init.go
generated
vendored
49
vendor/github.com/coreos/pkg/capnslog/init.go
generated
vendored
|
@ -1,49 +0,0 @@
|
||||||
// Copyright 2015 CoreOS, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
//
|
|
||||||
// +build !windows
|
|
||||||
|
|
||||||
package capnslog
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Here's where the opinionation comes in. We need some sensible defaults,
|
|
||||||
// especially after taking over the log package. Your project (whatever it may
|
|
||||||
// be) may see things differently. That's okay; there should be no defaults in
|
|
||||||
// the main package that cannot be controlled or overridden programatically,
|
|
||||||
// otherwise it's a bug. Doing so is creating your own init_log.go file much
|
|
||||||
// like this one.
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
initHijack()
|
|
||||||
|
|
||||||
// Go `log` pacakge uses os.Stderr.
|
|
||||||
SetFormatter(NewDefaultFormatter(os.Stderr))
|
|
||||||
SetGlobalLogLevel(INFO)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewDefaultFormatter(out io.Writer) Formatter {
|
|
||||||
if syscall.Getppid() == 1 {
|
|
||||||
// We're running under init, which may be systemd.
|
|
||||||
f, err := NewJournaldFormatter()
|
|
||||||
if err == nil {
|
|
||||||
return f
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NewPrettyFormatter(out, false)
|
|
||||||
}
|
|
25
vendor/github.com/coreos/pkg/capnslog/init_windows.go
generated
vendored
25
vendor/github.com/coreos/pkg/capnslog/init_windows.go
generated
vendored
|
@ -1,25 +0,0 @@
|
||||||
// Copyright 2015 CoreOS, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package capnslog
|
|
||||||
|
|
||||||
import "os"
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
initHijack()
|
|
||||||
|
|
||||||
// Go `log` package uses os.Stderr.
|
|
||||||
SetFormatter(NewPrettyFormatter(os.Stderr, false))
|
|
||||||
SetGlobalLogLevel(INFO)
|
|
||||||
}
|
|
68
vendor/github.com/coreos/pkg/capnslog/journald_formatter.go
generated
vendored
68
vendor/github.com/coreos/pkg/capnslog/journald_formatter.go
generated
vendored
|
@ -1,68 +0,0 @@
|
||||||
// Copyright 2015 CoreOS, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
//
|
|
||||||
// +build !windows
|
|
||||||
|
|
||||||
package capnslog
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/coreos/go-systemd/journal"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewJournaldFormatter() (Formatter, error) {
|
|
||||||
if !journal.Enabled() {
|
|
||||||
return nil, errors.New("No systemd detected")
|
|
||||||
}
|
|
||||||
return &journaldFormatter{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type journaldFormatter struct{}
|
|
||||||
|
|
||||||
func (j *journaldFormatter) Format(pkg string, l LogLevel, _ int, entries ...interface{}) {
|
|
||||||
var pri journal.Priority
|
|
||||||
switch l {
|
|
||||||
case CRITICAL:
|
|
||||||
pri = journal.PriCrit
|
|
||||||
case ERROR:
|
|
||||||
pri = journal.PriErr
|
|
||||||
case WARNING:
|
|
||||||
pri = journal.PriWarning
|
|
||||||
case NOTICE:
|
|
||||||
pri = journal.PriNotice
|
|
||||||
case INFO:
|
|
||||||
pri = journal.PriInfo
|
|
||||||
case DEBUG:
|
|
||||||
pri = journal.PriDebug
|
|
||||||
case TRACE:
|
|
||||||
pri = journal.PriDebug
|
|
||||||
default:
|
|
||||||
panic("Unhandled loglevel")
|
|
||||||
}
|
|
||||||
msg := fmt.Sprint(entries...)
|
|
||||||
tags := map[string]string{
|
|
||||||
"PACKAGE": pkg,
|
|
||||||
"SYSLOG_IDENTIFIER": filepath.Base(os.Args[0]),
|
|
||||||
}
|
|
||||||
err := journal.Send(msg, pri, tags)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *journaldFormatter) Flush() {}
|
|
39
vendor/github.com/coreos/pkg/capnslog/log_hijack.go
generated
vendored
39
vendor/github.com/coreos/pkg/capnslog/log_hijack.go
generated
vendored
|
@ -1,39 +0,0 @@
|
||||||
// Copyright 2015 CoreOS, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package capnslog
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
)
|
|
||||||
|
|
||||||
func initHijack() {
|
|
||||||
pkg := NewPackageLogger("log", "")
|
|
||||||
w := packageWriter{pkg}
|
|
||||||
log.SetFlags(0)
|
|
||||||
log.SetPrefix("")
|
|
||||||
log.SetOutput(w)
|
|
||||||
}
|
|
||||||
|
|
||||||
type packageWriter struct {
|
|
||||||
pl *PackageLogger
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p packageWriter) Write(b []byte) (int, error) {
|
|
||||||
if p.pl.level < INFO {
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
p.pl.internalLog(calldepth+2, INFO, string(b))
|
|
||||||
return len(b), nil
|
|
||||||
}
|
|
245
vendor/github.com/coreos/pkg/capnslog/logmap.go
generated
vendored
245
vendor/github.com/coreos/pkg/capnslog/logmap.go
generated
vendored
|
@ -1,245 +0,0 @@
|
||||||
// Copyright 2015 CoreOS, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package capnslog
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
// LogLevel is the set of all log levels.
|
|
||||||
type LogLevel int8
|
|
||||||
|
|
||||||
const (
|
|
||||||
// CRITICAL is the lowest log level; only errors which will end the program will be propagated.
|
|
||||||
CRITICAL LogLevel = iota - 1
|
|
||||||
// ERROR is for errors that are not fatal but lead to troubling behavior.
|
|
||||||
ERROR
|
|
||||||
// WARNING is for errors which are not fatal and not errors, but are unusual. Often sourced from misconfigurations.
|
|
||||||
WARNING
|
|
||||||
// NOTICE is for normal but significant conditions.
|
|
||||||
NOTICE
|
|
||||||
// INFO is a log level for common, everyday log updates.
|
|
||||||
INFO
|
|
||||||
// DEBUG is the default hidden level for more verbose updates about internal processes.
|
|
||||||
DEBUG
|
|
||||||
// TRACE is for (potentially) call by call tracing of programs.
|
|
||||||
TRACE
|
|
||||||
)
|
|
||||||
|
|
||||||
// Char returns a single-character representation of the log level.
|
|
||||||
func (l LogLevel) Char() string {
|
|
||||||
switch l {
|
|
||||||
case CRITICAL:
|
|
||||||
return "C"
|
|
||||||
case ERROR:
|
|
||||||
return "E"
|
|
||||||
case WARNING:
|
|
||||||
return "W"
|
|
||||||
case NOTICE:
|
|
||||||
return "N"
|
|
||||||
case INFO:
|
|
||||||
return "I"
|
|
||||||
case DEBUG:
|
|
||||||
return "D"
|
|
||||||
case TRACE:
|
|
||||||
return "T"
|
|
||||||
default:
|
|
||||||
panic("Unhandled loglevel")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// String returns a multi-character representation of the log level.
|
|
||||||
func (l LogLevel) String() string {
|
|
||||||
switch l {
|
|
||||||
case CRITICAL:
|
|
||||||
return "CRITICAL"
|
|
||||||
case ERROR:
|
|
||||||
return "ERROR"
|
|
||||||
case WARNING:
|
|
||||||
return "WARNING"
|
|
||||||
case NOTICE:
|
|
||||||
return "NOTICE"
|
|
||||||
case INFO:
|
|
||||||
return "INFO"
|
|
||||||
case DEBUG:
|
|
||||||
return "DEBUG"
|
|
||||||
case TRACE:
|
|
||||||
return "TRACE"
|
|
||||||
default:
|
|
||||||
panic("Unhandled loglevel")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update using the given string value. Fulfills the flag.Value interface.
|
|
||||||
func (l *LogLevel) Set(s string) error {
|
|
||||||
value, err := ParseLevel(s)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
*l = value
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns an empty string, only here to fulfill the pflag.Value interface.
|
|
||||||
func (l *LogLevel) Type() string {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseLevel translates some potential loglevel strings into their corresponding levels.
|
|
||||||
func ParseLevel(s string) (LogLevel, error) {
|
|
||||||
switch s {
|
|
||||||
case "CRITICAL", "C":
|
|
||||||
return CRITICAL, nil
|
|
||||||
case "ERROR", "0", "E":
|
|
||||||
return ERROR, nil
|
|
||||||
case "WARNING", "1", "W":
|
|
||||||
return WARNING, nil
|
|
||||||
case "NOTICE", "2", "N":
|
|
||||||
return NOTICE, nil
|
|
||||||
case "INFO", "3", "I":
|
|
||||||
return INFO, nil
|
|
||||||
case "DEBUG", "4", "D":
|
|
||||||
return DEBUG, nil
|
|
||||||
case "TRACE", "5", "T":
|
|
||||||
return TRACE, nil
|
|
||||||
}
|
|
||||||
return CRITICAL, errors.New("couldn't parse log level " + s)
|
|
||||||
}
|
|
||||||
|
|
||||||
type RepoLogger map[string]*PackageLogger
|
|
||||||
|
|
||||||
type loggerStruct struct {
|
|
||||||
sync.Mutex
|
|
||||||
repoMap map[string]RepoLogger
|
|
||||||
formatter Formatter
|
|
||||||
}
|
|
||||||
|
|
||||||
// logger is the global logger
|
|
||||||
var logger = new(loggerStruct)
|
|
||||||
|
|
||||||
// SetGlobalLogLevel sets the log level for all packages in all repositories
|
|
||||||
// registered with capnslog.
|
|
||||||
func SetGlobalLogLevel(l LogLevel) {
|
|
||||||
logger.Lock()
|
|
||||||
defer logger.Unlock()
|
|
||||||
for _, r := range logger.repoMap {
|
|
||||||
r.setRepoLogLevelInternal(l)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRepoLogger may return the handle to the repository's set of packages' loggers.
|
|
||||||
func GetRepoLogger(repo string) (RepoLogger, error) {
|
|
||||||
logger.Lock()
|
|
||||||
defer logger.Unlock()
|
|
||||||
r, ok := logger.repoMap[repo]
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("no packages registered for repo " + repo)
|
|
||||||
}
|
|
||||||
return r, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MustRepoLogger returns the handle to the repository's packages' loggers.
|
|
||||||
func MustRepoLogger(repo string) RepoLogger {
|
|
||||||
r, err := GetRepoLogger(repo)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetRepoLogLevel sets the log level for all packages in the repository.
|
|
||||||
func (r RepoLogger) SetRepoLogLevel(l LogLevel) {
|
|
||||||
logger.Lock()
|
|
||||||
defer logger.Unlock()
|
|
||||||
r.setRepoLogLevelInternal(l)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r RepoLogger) setRepoLogLevelInternal(l LogLevel) {
|
|
||||||
for _, v := range r {
|
|
||||||
v.level = l
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseLogLevelConfig parses a comma-separated string of "package=loglevel", in
|
|
||||||
// order, and returns a map of the results, for use in SetLogLevel.
|
|
||||||
func (r RepoLogger) ParseLogLevelConfig(conf string) (map[string]LogLevel, error) {
|
|
||||||
setlist := strings.Split(conf, ",")
|
|
||||||
out := make(map[string]LogLevel)
|
|
||||||
for _, setstring := range setlist {
|
|
||||||
setting := strings.Split(setstring, "=")
|
|
||||||
if len(setting) != 2 {
|
|
||||||
return nil, errors.New("oddly structured `pkg=level` option: " + setstring)
|
|
||||||
}
|
|
||||||
l, err := ParseLevel(setting[1])
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
out[setting[0]] = l
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetLogLevel takes a map of package names within a repository to their desired
|
|
||||||
// loglevel, and sets the levels appropriately. Unknown packages are ignored.
|
|
||||||
// "*" is a special package name that corresponds to all packages, and will be
|
|
||||||
// processed first.
|
|
||||||
func (r RepoLogger) SetLogLevel(m map[string]LogLevel) {
|
|
||||||
logger.Lock()
|
|
||||||
defer logger.Unlock()
|
|
||||||
if l, ok := m["*"]; ok {
|
|
||||||
r.setRepoLogLevelInternal(l)
|
|
||||||
}
|
|
||||||
for k, v := range m {
|
|
||||||
l, ok := r[k]
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
l.level = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetFormatter sets the formatting function for all logs.
|
|
||||||
func SetFormatter(f Formatter) {
|
|
||||||
logger.Lock()
|
|
||||||
defer logger.Unlock()
|
|
||||||
logger.formatter = f
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewPackageLogger creates a package logger object.
|
|
||||||
// This should be defined as a global var in your package, referencing your repo.
|
|
||||||
func NewPackageLogger(repo string, pkg string) (p *PackageLogger) {
|
|
||||||
logger.Lock()
|
|
||||||
defer logger.Unlock()
|
|
||||||
if logger.repoMap == nil {
|
|
||||||
logger.repoMap = make(map[string]RepoLogger)
|
|
||||||
}
|
|
||||||
r, rok := logger.repoMap[repo]
|
|
||||||
if !rok {
|
|
||||||
logger.repoMap[repo] = make(RepoLogger)
|
|
||||||
r = logger.repoMap[repo]
|
|
||||||
}
|
|
||||||
p, pok := r[pkg]
|
|
||||||
if !pok {
|
|
||||||
r[pkg] = &PackageLogger{
|
|
||||||
pkg: pkg,
|
|
||||||
level: INFO,
|
|
||||||
}
|
|
||||||
p = r[pkg]
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
177
vendor/github.com/coreos/pkg/capnslog/pkg_logger.go
generated
vendored
177
vendor/github.com/coreos/pkg/capnslog/pkg_logger.go
generated
vendored
|
@ -1,177 +0,0 @@
|
||||||
// Copyright 2015 CoreOS, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package capnslog
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PackageLogger struct {
|
|
||||||
pkg string
|
|
||||||
level LogLevel
|
|
||||||
}
|
|
||||||
|
|
||||||
const calldepth = 2
|
|
||||||
|
|
||||||
func (p *PackageLogger) internalLog(depth int, inLevel LogLevel, entries ...interface{}) {
|
|
||||||
logger.Lock()
|
|
||||||
defer logger.Unlock()
|
|
||||||
if inLevel != CRITICAL && p.level < inLevel {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if logger.formatter != nil {
|
|
||||||
logger.formatter.Format(p.pkg, inLevel, depth+1, entries...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PackageLogger) LevelAt(l LogLevel) bool {
|
|
||||||
logger.Lock()
|
|
||||||
defer logger.Unlock()
|
|
||||||
return p.level >= l
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log a formatted string at any level between ERROR and TRACE
|
|
||||||
func (p *PackageLogger) Logf(l LogLevel, format string, args ...interface{}) {
|
|
||||||
p.internalLog(calldepth, l, fmt.Sprintf(format, args...))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log a message at any level between ERROR and TRACE
|
|
||||||
func (p *PackageLogger) Log(l LogLevel, args ...interface{}) {
|
|
||||||
p.internalLog(calldepth, l, fmt.Sprint(args...))
|
|
||||||
}
|
|
||||||
|
|
||||||
// log stdlib compatibility
|
|
||||||
|
|
||||||
func (p *PackageLogger) Println(args ...interface{}) {
|
|
||||||
p.internalLog(calldepth, INFO, fmt.Sprintln(args...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PackageLogger) Printf(format string, args ...interface{}) {
|
|
||||||
p.Logf(INFO, format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PackageLogger) Print(args ...interface{}) {
|
|
||||||
p.internalLog(calldepth, INFO, fmt.Sprint(args...))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Panic and fatal
|
|
||||||
|
|
||||||
func (p *PackageLogger) Panicf(format string, args ...interface{}) {
|
|
||||||
s := fmt.Sprintf(format, args...)
|
|
||||||
p.internalLog(calldepth, CRITICAL, s)
|
|
||||||
panic(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PackageLogger) Panic(args ...interface{}) {
|
|
||||||
s := fmt.Sprint(args...)
|
|
||||||
p.internalLog(calldepth, CRITICAL, s)
|
|
||||||
panic(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PackageLogger) Fatalf(format string, args ...interface{}) {
|
|
||||||
p.Logf(CRITICAL, format, args...)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PackageLogger) Fatal(args ...interface{}) {
|
|
||||||
s := fmt.Sprint(args...)
|
|
||||||
p.internalLog(calldepth, CRITICAL, s)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PackageLogger) Fatalln(args ...interface{}) {
|
|
||||||
s := fmt.Sprintln(args...)
|
|
||||||
p.internalLog(calldepth, CRITICAL, s)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error Functions
|
|
||||||
|
|
||||||
func (p *PackageLogger) Errorf(format string, args ...interface{}) {
|
|
||||||
p.Logf(ERROR, format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PackageLogger) Error(entries ...interface{}) {
|
|
||||||
p.internalLog(calldepth, ERROR, entries...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warning Functions
|
|
||||||
|
|
||||||
func (p *PackageLogger) Warningf(format string, args ...interface{}) {
|
|
||||||
p.Logf(WARNING, format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PackageLogger) Warning(entries ...interface{}) {
|
|
||||||
p.internalLog(calldepth, WARNING, entries...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Notice Functions
|
|
||||||
|
|
||||||
func (p *PackageLogger) Noticef(format string, args ...interface{}) {
|
|
||||||
p.Logf(NOTICE, format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PackageLogger) Notice(entries ...interface{}) {
|
|
||||||
p.internalLog(calldepth, NOTICE, entries...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info Functions
|
|
||||||
|
|
||||||
func (p *PackageLogger) Infof(format string, args ...interface{}) {
|
|
||||||
p.Logf(INFO, format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PackageLogger) Info(entries ...interface{}) {
|
|
||||||
p.internalLog(calldepth, INFO, entries...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debug Functions
|
|
||||||
|
|
||||||
func (p *PackageLogger) Debugf(format string, args ...interface{}) {
|
|
||||||
if p.level < DEBUG {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
p.Logf(DEBUG, format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PackageLogger) Debug(entries ...interface{}) {
|
|
||||||
if p.level < DEBUG {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
p.internalLog(calldepth, DEBUG, entries...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trace Functions
|
|
||||||
|
|
||||||
func (p *PackageLogger) Tracef(format string, args ...interface{}) {
|
|
||||||
if p.level < TRACE {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
p.Logf(TRACE, format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PackageLogger) Trace(entries ...interface{}) {
|
|
||||||
if p.level < TRACE {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
p.internalLog(calldepth, TRACE, entries...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PackageLogger) Flush() {
|
|
||||||
logger.Lock()
|
|
||||||
defer logger.Unlock()
|
|
||||||
logger.formatter.Flush()
|
|
||||||
}
|
|
65
vendor/github.com/coreos/pkg/capnslog/syslog_formatter.go
generated
vendored
65
vendor/github.com/coreos/pkg/capnslog/syslog_formatter.go
generated
vendored
|
@ -1,65 +0,0 @@
|
||||||
// Copyright 2015 CoreOS, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
//
|
|
||||||
// +build !windows
|
|
||||||
|
|
||||||
package capnslog
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log/syslog"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewSyslogFormatter(w *syslog.Writer) Formatter {
|
|
||||||
return &syslogFormatter{w}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewDefaultSyslogFormatter(tag string) (Formatter, error) {
|
|
||||||
w, err := syslog.New(syslog.LOG_DEBUG, tag)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return NewSyslogFormatter(w), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type syslogFormatter struct {
|
|
||||||
w *syslog.Writer
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *syslogFormatter) Format(pkg string, l LogLevel, _ int, entries ...interface{}) {
|
|
||||||
for _, entry := range entries {
|
|
||||||
str := fmt.Sprint(entry)
|
|
||||||
switch l {
|
|
||||||
case CRITICAL:
|
|
||||||
s.w.Crit(str)
|
|
||||||
case ERROR:
|
|
||||||
s.w.Err(str)
|
|
||||||
case WARNING:
|
|
||||||
s.w.Warning(str)
|
|
||||||
case NOTICE:
|
|
||||||
s.w.Notice(str)
|
|
||||||
case INFO:
|
|
||||||
s.w.Info(str)
|
|
||||||
case DEBUG:
|
|
||||||
s.w.Debug(str)
|
|
||||||
case TRACE:
|
|
||||||
s.w.Debug(str)
|
|
||||||
default:
|
|
||||||
panic("Unhandled loglevel")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *syslogFormatter) Flush() {
|
|
||||||
}
|
|
21
vendor/github.com/go-kit/kit/log/term/LICENSE
generated
vendored
21
vendor/github.com/go-kit/kit/log/term/LICENSE
generated
vendored
|
@ -1,21 +0,0 @@
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2014 Simon Eskildsen
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
144
vendor/github.com/go-kit/kit/log/term/colorlogger.go
generated
vendored
144
vendor/github.com/go-kit/kit/log/term/colorlogger.go
generated
vendored
|
@ -1,144 +0,0 @@
|
||||||
package term
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/go-kit/kit/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Color represents an ANSI color. The zero value is Default.
|
|
||||||
type Color uint8
|
|
||||||
|
|
||||||
// ANSI colors.
|
|
||||||
const (
|
|
||||||
Default = Color(iota)
|
|
||||||
|
|
||||||
Black
|
|
||||||
DarkRed
|
|
||||||
DarkGreen
|
|
||||||
Brown
|
|
||||||
DarkBlue
|
|
||||||
DarkMagenta
|
|
||||||
DarkCyan
|
|
||||||
Gray
|
|
||||||
|
|
||||||
DarkGray
|
|
||||||
Red
|
|
||||||
Green
|
|
||||||
Yellow
|
|
||||||
Blue
|
|
||||||
Magenta
|
|
||||||
Cyan
|
|
||||||
White
|
|
||||||
|
|
||||||
numColors
|
|
||||||
)
|
|
||||||
|
|
||||||
// For more on ANSI escape codes see
|
|
||||||
// https://en.wikipedia.org/wiki/ANSI_escape_code. See in particular
|
|
||||||
// https://en.wikipedia.org/wiki/ANSI_escape_code#Colors.
|
|
||||||
|
|
||||||
var (
|
|
||||||
resetColorBytes = []byte("\x1b[39;49;22m")
|
|
||||||
fgColorBytes [][]byte
|
|
||||||
bgColorBytes [][]byte
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
// Default
|
|
||||||
fgColorBytes = append(fgColorBytes, []byte("\x1b[39m"))
|
|
||||||
bgColorBytes = append(bgColorBytes, []byte("\x1b[49m"))
|
|
||||||
|
|
||||||
// dark colors
|
|
||||||
for color := Black; color < DarkGray; color++ {
|
|
||||||
fgColorBytes = append(fgColorBytes, []byte(fmt.Sprintf("\x1b[%dm", 30+color-Black)))
|
|
||||||
bgColorBytes = append(bgColorBytes, []byte(fmt.Sprintf("\x1b[%dm", 40+color-Black)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// bright colors
|
|
||||||
for color := DarkGray; color < numColors; color++ {
|
|
||||||
fgColorBytes = append(fgColorBytes, []byte(fmt.Sprintf("\x1b[%d;1m", 30+color-DarkGray)))
|
|
||||||
bgColorBytes = append(bgColorBytes, []byte(fmt.Sprintf("\x1b[%d;1m", 40+color-DarkGray)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FgBgColor represents a foreground and background color.
|
|
||||||
type FgBgColor struct {
|
|
||||||
Fg, Bg Color
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c FgBgColor) isZero() bool {
|
|
||||||
return c.Fg == Default && c.Bg == Default
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewColorLogger returns a Logger which writes colored logs to w. ANSI color
|
|
||||||
// codes for the colors returned by color are added to the formatted output
|
|
||||||
// from the Logger returned by newLogger and the combined result written to w.
|
|
||||||
func NewColorLogger(w io.Writer, newLogger func(io.Writer) log.Logger, color func(keyvals ...interface{}) FgBgColor) log.Logger {
|
|
||||||
if color == nil {
|
|
||||||
panic("color func nil")
|
|
||||||
}
|
|
||||||
return &colorLogger{
|
|
||||||
w: w,
|
|
||||||
newLogger: newLogger,
|
|
||||||
color: color,
|
|
||||||
bufPool: sync.Pool{New: func() interface{} { return &loggerBuf{} }},
|
|
||||||
noColorLogger: newLogger(w),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type colorLogger struct {
|
|
||||||
w io.Writer
|
|
||||||
newLogger func(io.Writer) log.Logger
|
|
||||||
color func(keyvals ...interface{}) FgBgColor
|
|
||||||
bufPool sync.Pool
|
|
||||||
noColorLogger log.Logger
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *colorLogger) Log(keyvals ...interface{}) error {
|
|
||||||
color := l.color(keyvals...)
|
|
||||||
if color.isZero() {
|
|
||||||
return l.noColorLogger.Log(keyvals...)
|
|
||||||
}
|
|
||||||
|
|
||||||
lb := l.getLoggerBuf()
|
|
||||||
defer l.putLoggerBuf(lb)
|
|
||||||
if color.Fg != Default {
|
|
||||||
lb.buf.Write(fgColorBytes[color.Fg])
|
|
||||||
}
|
|
||||||
if color.Bg != Default {
|
|
||||||
lb.buf.Write(bgColorBytes[color.Bg])
|
|
||||||
}
|
|
||||||
err := lb.logger.Log(keyvals...)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if color.Fg != Default || color.Bg != Default {
|
|
||||||
lb.buf.Write(resetColorBytes)
|
|
||||||
}
|
|
||||||
_, err = io.Copy(l.w, lb.buf)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
type loggerBuf struct {
|
|
||||||
buf *bytes.Buffer
|
|
||||||
logger log.Logger
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *colorLogger) getLoggerBuf() *loggerBuf {
|
|
||||||
lb := l.bufPool.Get().(*loggerBuf)
|
|
||||||
if lb.buf == nil {
|
|
||||||
lb.buf = &bytes.Buffer{}
|
|
||||||
lb.logger = l.newLogger(lb.buf)
|
|
||||||
} else {
|
|
||||||
lb.buf.Reset()
|
|
||||||
}
|
|
||||||
return lb
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *colorLogger) putLoggerBuf(cb *loggerBuf) {
|
|
||||||
l.bufPool.Put(cb)
|
|
||||||
}
|
|
12
vendor/github.com/go-kit/kit/log/term/colorwriter_others.go
generated
vendored
12
vendor/github.com/go-kit/kit/log/term/colorwriter_others.go
generated
vendored
|
@ -1,12 +0,0 @@
|
||||||
// +build !windows
|
|
||||||
|
|
||||||
package term
|
|
||||||
|
|
||||||
import "io"
|
|
||||||
|
|
||||||
// NewColorWriter returns an io.Writer that writes to w and provides cross
|
|
||||||
// platform support for ANSI color codes. If w is not a terminal it is
|
|
||||||
// returned unmodified.
|
|
||||||
func NewColorWriter(w io.Writer) io.Writer {
|
|
||||||
return w
|
|
||||||
}
|
|
190
vendor/github.com/go-kit/kit/log/term/colorwriter_windows.go
generated
vendored
190
vendor/github.com/go-kit/kit/log/term/colorwriter_windows.go
generated
vendored
|
@ -1,190 +0,0 @@
|
||||||
// The code in this file is adapted from github.com/mattn/go-colorable.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package term
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
type colorWriter struct {
|
|
||||||
out io.Writer
|
|
||||||
handle syscall.Handle
|
|
||||||
lastbuf bytes.Buffer
|
|
||||||
oldattr word
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewColorWriter returns an io.Writer that writes to w and provides cross
|
|
||||||
// platform support for ANSI color codes. If w is not a terminal it is
|
|
||||||
// returned unmodified.
|
|
||||||
func NewColorWriter(w io.Writer) io.Writer {
|
|
||||||
if !IsConsole(w) {
|
|
||||||
return w
|
|
||||||
}
|
|
||||||
|
|
||||||
var csbi consoleScreenBufferInfo
|
|
||||||
handle := syscall.Handle(w.(fder).Fd())
|
|
||||||
procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
|
|
||||||
|
|
||||||
return &colorWriter{
|
|
||||||
out: w,
|
|
||||||
handle: handle,
|
|
||||||
oldattr: csbi.attributes,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *colorWriter) Write(data []byte) (n int, err error) {
|
|
||||||
var csbi consoleScreenBufferInfo
|
|
||||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
|
||||||
|
|
||||||
er := bytes.NewBuffer(data)
|
|
||||||
loop:
|
|
||||||
for {
|
|
||||||
r1, _, err := procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
|
||||||
if r1 == 0 {
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
|
|
||||||
c1, _, err := er.ReadRune()
|
|
||||||
if err != nil {
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
if c1 != 0x1b {
|
|
||||||
fmt.Fprint(w.out, string(c1))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
c2, _, err := er.ReadRune()
|
|
||||||
if err != nil {
|
|
||||||
w.lastbuf.WriteRune(c1)
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
if c2 != 0x5b {
|
|
||||||
w.lastbuf.WriteRune(c1)
|
|
||||||
w.lastbuf.WriteRune(c2)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
var buf bytes.Buffer
|
|
||||||
var m rune
|
|
||||||
for {
|
|
||||||
c, _, err := er.ReadRune()
|
|
||||||
if err != nil {
|
|
||||||
w.lastbuf.WriteRune(c1)
|
|
||||||
w.lastbuf.WriteRune(c2)
|
|
||||||
w.lastbuf.Write(buf.Bytes())
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
if ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '@' {
|
|
||||||
m = c
|
|
||||||
break
|
|
||||||
}
|
|
||||||
buf.Write([]byte(string(c)))
|
|
||||||
}
|
|
||||||
|
|
||||||
switch m {
|
|
||||||
case 'm':
|
|
||||||
attr := csbi.attributes
|
|
||||||
cs := buf.String()
|
|
||||||
if cs == "" {
|
|
||||||
procSetConsoleTextAttribute.Call(uintptr(w.handle), uintptr(w.oldattr))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
token := strings.Split(cs, ";")
|
|
||||||
intensityMode := word(0)
|
|
||||||
for _, ns := range token {
|
|
||||||
if n, err = strconv.Atoi(ns); err == nil {
|
|
||||||
switch {
|
|
||||||
case n == 0:
|
|
||||||
attr = w.oldattr
|
|
||||||
case n == 1:
|
|
||||||
attr |= intensityMode
|
|
||||||
case 30 <= n && n <= 37:
|
|
||||||
attr = (attr & backgroundMask)
|
|
||||||
if (n-30)&1 != 0 {
|
|
||||||
attr |= foregroundRed
|
|
||||||
}
|
|
||||||
if (n-30)&2 != 0 {
|
|
||||||
attr |= foregroundGreen
|
|
||||||
}
|
|
||||||
if (n-30)&4 != 0 {
|
|
||||||
attr |= foregroundBlue
|
|
||||||
}
|
|
||||||
intensityMode = foregroundIntensity
|
|
||||||
case n == 39: // reset foreground color
|
|
||||||
attr &= backgroundMask
|
|
||||||
attr |= w.oldattr & foregroundMask
|
|
||||||
case 40 <= n && n <= 47:
|
|
||||||
attr = (attr & foregroundMask)
|
|
||||||
if (n-40)&1 != 0 {
|
|
||||||
attr |= backgroundRed
|
|
||||||
}
|
|
||||||
if (n-40)&2 != 0 {
|
|
||||||
attr |= backgroundGreen
|
|
||||||
}
|
|
||||||
if (n-40)&4 != 0 {
|
|
||||||
attr |= backgroundBlue
|
|
||||||
}
|
|
||||||
intensityMode = backgroundIntensity
|
|
||||||
case n == 49: // reset background color
|
|
||||||
attr &= foregroundMask
|
|
||||||
attr |= w.oldattr & backgroundMask
|
|
||||||
}
|
|
||||||
procSetConsoleTextAttribute.Call(uintptr(w.handle), uintptr(attr))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return len(data) - w.lastbuf.Len(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
procGetConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo")
|
|
||||||
procSetConsoleTextAttribute = kernel32.NewProc("SetConsoleTextAttribute")
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
foregroundBlue = 0x1
|
|
||||||
foregroundGreen = 0x2
|
|
||||||
foregroundRed = 0x4
|
|
||||||
foregroundIntensity = 0x8
|
|
||||||
foregroundMask = (foregroundRed | foregroundBlue | foregroundGreen | foregroundIntensity)
|
|
||||||
backgroundBlue = 0x10
|
|
||||||
backgroundGreen = 0x20
|
|
||||||
backgroundRed = 0x40
|
|
||||||
backgroundIntensity = 0x80
|
|
||||||
backgroundMask = (backgroundRed | backgroundBlue | backgroundGreen | backgroundIntensity)
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
wchar uint16
|
|
||||||
short int16
|
|
||||||
dword uint32
|
|
||||||
word uint16
|
|
||||||
)
|
|
||||||
|
|
||||||
type coord struct {
|
|
||||||
x short
|
|
||||||
y short
|
|
||||||
}
|
|
||||||
|
|
||||||
type smallRect struct {
|
|
||||||
left short
|
|
||||||
top short
|
|
||||||
right short
|
|
||||||
bottom short
|
|
||||||
}
|
|
||||||
|
|
||||||
type consoleScreenBufferInfo struct {
|
|
||||||
size coord
|
|
||||||
cursorPosition coord
|
|
||||||
attributes word
|
|
||||||
window smallRect
|
|
||||||
maximumWindowSize coord
|
|
||||||
}
|
|
22
vendor/github.com/go-kit/kit/log/term/term.go
generated
vendored
22
vendor/github.com/go-kit/kit/log/term/term.go
generated
vendored
|
@ -1,22 +0,0 @@
|
||||||
// Package term provides tools for logging to a terminal.
|
|
||||||
package term
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/go-kit/kit/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewLogger returns a Logger that takes advantage of terminal features if
|
|
||||||
// possible. Log events are formatted by the Logger returned by newLogger. If
|
|
||||||
// w is a terminal each log event is colored according to the color function.
|
|
||||||
func NewLogger(w io.Writer, newLogger func(io.Writer) log.Logger, color func(keyvals ...interface{}) FgBgColor) log.Logger {
|
|
||||||
if !IsTerminal(w) {
|
|
||||||
return newLogger(w)
|
|
||||||
}
|
|
||||||
return NewColorLogger(NewColorWriter(w), newLogger, color)
|
|
||||||
}
|
|
||||||
|
|
||||||
type fder interface {
|
|
||||||
Fd() uintptr
|
|
||||||
}
|
|
15
vendor/github.com/go-kit/kit/log/term/terminal_appengine.go
generated
vendored
15
vendor/github.com/go-kit/kit/log/term/terminal_appengine.go
generated
vendored
|
@ -1,15 +0,0 @@
|
||||||
// Based on ssh/terminal:
|
|
||||||
// Copyright 2013 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build appengine
|
|
||||||
|
|
||||||
package term
|
|
||||||
|
|
||||||
import "io"
|
|
||||||
|
|
||||||
// IsTerminal always returns false on AppEngine.
|
|
||||||
func IsTerminal(w io.Writer) bool {
|
|
||||||
return false
|
|
||||||
}
|
|
10
vendor/github.com/go-kit/kit/log/term/terminal_darwin.go
generated
vendored
10
vendor/github.com/go-kit/kit/log/term/terminal_darwin.go
generated
vendored
|
@ -1,10 +0,0 @@
|
||||||
// Based on ssh/terminal:
|
|
||||||
// Copyright 2013 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package term
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
const ioctlReadTermios = syscall.TIOCGETA
|
|
7
vendor/github.com/go-kit/kit/log/term/terminal_freebsd.go
generated
vendored
7
vendor/github.com/go-kit/kit/log/term/terminal_freebsd.go
generated
vendored
|
@ -1,7 +0,0 @@
|
||||||
package term
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
const ioctlReadTermios = syscall.TIOCGETA
|
|
12
vendor/github.com/go-kit/kit/log/term/terminal_linux.go
generated
vendored
12
vendor/github.com/go-kit/kit/log/term/terminal_linux.go
generated
vendored
|
@ -1,12 +0,0 @@
|
||||||
// Based on ssh/terminal:
|
|
||||||
// Copyright 2013 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build !appengine
|
|
||||||
|
|
||||||
package term
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
const ioctlReadTermios = syscall.TCGETS
|
|
25
vendor/github.com/go-kit/kit/log/term/terminal_notwindows.go
generated
vendored
25
vendor/github.com/go-kit/kit/log/term/terminal_notwindows.go
generated
vendored
|
@ -1,25 +0,0 @@
|
||||||
// Based on ssh/terminal:
|
|
||||||
// Copyright 2011 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build linux,!appengine darwin freebsd openbsd
|
|
||||||
|
|
||||||
package term
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// IsTerminal returns true if w writes to a terminal.
|
|
||||||
func IsTerminal(w io.Writer) bool {
|
|
||||||
fw, ok := w.(fder)
|
|
||||||
if !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
var termios syscall.Termios
|
|
||||||
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fw.Fd(), ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
|
|
||||||
return err == 0
|
|
||||||
}
|
|
5
vendor/github.com/go-kit/kit/log/term/terminal_openbsd.go
generated
vendored
5
vendor/github.com/go-kit/kit/log/term/terminal_openbsd.go
generated
vendored
|
@ -1,5 +0,0 @@
|
||||||
package term
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
const ioctlReadTermios = syscall.TIOCGETA
|
|
102
vendor/github.com/go-kit/kit/log/term/terminal_windows.go
generated
vendored
102
vendor/github.com/go-kit/kit/log/term/terminal_windows.go
generated
vendored
|
@ -1,102 +0,0 @@
|
||||||
// Based on ssh/terminal:
|
|
||||||
// Copyright 2011 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package term
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/binary"
|
|
||||||
"io"
|
|
||||||
"regexp"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
var kernel32 = syscall.NewLazyDLL("kernel32.dll")
|
|
||||||
|
|
||||||
var (
|
|
||||||
procGetFileInformationByHandleEx = kernel32.NewProc("GetFileInformationByHandleEx")
|
|
||||||
msysPipeNameRegex = regexp.MustCompile(`\\(cygwin|msys)-\w+-pty\d?-(to|from)-master`)
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
fileNameInfo = 0x02
|
|
||||||
)
|
|
||||||
|
|
||||||
// IsTerminal returns true if w writes to a terminal.
|
|
||||||
func IsTerminal(w io.Writer) bool {
|
|
||||||
return IsConsole(w) || IsMSYSTerminal(w)
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsConsole returns true if w writes to a Windows console.
|
|
||||||
func IsConsole(w io.Writer) bool {
|
|
||||||
var handle syscall.Handle
|
|
||||||
|
|
||||||
if fw, ok := w.(fder); ok {
|
|
||||||
handle = syscall.Handle(fw.Fd())
|
|
||||||
} else {
|
|
||||||
// The writer has no file-descriptor and so can't be a terminal.
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
var st uint32
|
|
||||||
err := syscall.GetConsoleMode(handle, &st)
|
|
||||||
|
|
||||||
// If the handle is attached to a terminal, GetConsoleMode returns a
|
|
||||||
// non-zero value containing the console mode flags. We don't care about
|
|
||||||
// the specifics of flags, just that it is not zero.
|
|
||||||
return (err == nil && st != 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsMSYSTerminal returns true if w writes to a MSYS/MSYS2 terminal.
|
|
||||||
func IsMSYSTerminal(w io.Writer) bool {
|
|
||||||
var handle syscall.Handle
|
|
||||||
|
|
||||||
if fw, ok := w.(fder); ok {
|
|
||||||
handle = syscall.Handle(fw.Fd())
|
|
||||||
} else {
|
|
||||||
// The writer has no file-descriptor and so can't be a terminal.
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// MSYS(2) terminal reports as a pipe for STDIN/STDOUT/STDERR. If it isn't
|
|
||||||
// a pipe, it can't be a MSYS(2) terminal.
|
|
||||||
filetype, err := syscall.GetFileType(handle)
|
|
||||||
|
|
||||||
if filetype != syscall.FILE_TYPE_PIPE || err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// MSYS2/Cygwin terminal's name looks like: \msys-dd50a72ab4668b33-pty2-to-master
|
|
||||||
data := make([]byte, 256, 256)
|
|
||||||
|
|
||||||
r, _, e := syscall.Syscall6(
|
|
||||||
procGetFileInformationByHandleEx.Addr(),
|
|
||||||
4,
|
|
||||||
uintptr(handle),
|
|
||||||
uintptr(fileNameInfo),
|
|
||||||
uintptr(unsafe.Pointer(&data[0])),
|
|
||||||
uintptr(len(data)),
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
)
|
|
||||||
|
|
||||||
if r != 0 && e == 0 {
|
|
||||||
// The first 4 bytes of the buffer are the size of the UTF16 name, in bytes.
|
|
||||||
unameLen := binary.LittleEndian.Uint32(data[:4]) / 2
|
|
||||||
uname := make([]uint16, unameLen, unameLen)
|
|
||||||
|
|
||||||
for i := uint32(0); i < unameLen; i++ {
|
|
||||||
uname[i] = binary.LittleEndian.Uint16(data[i*2+4 : i*2+2+4])
|
|
||||||
}
|
|
||||||
|
|
||||||
name := syscall.UTF16ToString(uname)
|
|
||||||
|
|
||||||
return msysPipeNameRegex.MatchString(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
382
vendor/github.com/golang/protobuf/ptypes/struct/struct.pb.go
generated
vendored
382
vendor/github.com/golang/protobuf/ptypes/struct/struct.pb.go
generated
vendored
|
@ -1,382 +0,0 @@
|
||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
|
||||||
// source: github.com/golang/protobuf/ptypes/struct/struct.proto
|
|
||||||
|
|
||||||
/*
|
|
||||||
Package structpb is a generated protocol buffer package.
|
|
||||||
|
|
||||||
It is generated from these files:
|
|
||||||
github.com/golang/protobuf/ptypes/struct/struct.proto
|
|
||||||
|
|
||||||
It has these top-level messages:
|
|
||||||
Struct
|
|
||||||
Value
|
|
||||||
ListValue
|
|
||||||
*/
|
|
||||||
package structpb
|
|
||||||
|
|
||||||
import proto "github.com/golang/protobuf/proto"
|
|
||||||
import fmt "fmt"
|
|
||||||
import math "math"
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
|
||||||
var _ = proto.Marshal
|
|
||||||
var _ = fmt.Errorf
|
|
||||||
var _ = math.Inf
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the proto package it is being compiled against.
|
|
||||||
// A compilation error at this line likely means your copy of the
|
|
||||||
// proto package needs to be updated.
|
|
||||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
|
||||||
|
|
||||||
// `NullValue` is a singleton enumeration to represent the null value for the
|
|
||||||
// `Value` type union.
|
|
||||||
//
|
|
||||||
// The JSON representation for `NullValue` is JSON `null`.
|
|
||||||
type NullValue int32
|
|
||||||
|
|
||||||
const (
|
|
||||||
// Null value.
|
|
||||||
NullValue_NULL_VALUE NullValue = 0
|
|
||||||
)
|
|
||||||
|
|
||||||
var NullValue_name = map[int32]string{
|
|
||||||
0: "NULL_VALUE",
|
|
||||||
}
|
|
||||||
var NullValue_value = map[string]int32{
|
|
||||||
"NULL_VALUE": 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x NullValue) String() string {
|
|
||||||
return proto.EnumName(NullValue_name, int32(x))
|
|
||||||
}
|
|
||||||
func (NullValue) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
|
||||||
func (NullValue) XXX_WellKnownType() string { return "NullValue" }
|
|
||||||
|
|
||||||
// `Struct` represents a structured data value, consisting of fields
|
|
||||||
// which map to dynamically typed values. In some languages, `Struct`
|
|
||||||
// might be supported by a native representation. For example, in
|
|
||||||
// scripting languages like JS a struct is represented as an
|
|
||||||
// object. The details of that representation are described together
|
|
||||||
// with the proto support for the language.
|
|
||||||
//
|
|
||||||
// The JSON representation for `Struct` is JSON object.
|
|
||||||
type Struct struct {
|
|
||||||
// Unordered map of dynamically typed values.
|
|
||||||
Fields map[string]*Value `protobuf:"bytes,1,rep,name=fields" json:"fields,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Struct) Reset() { *m = Struct{} }
|
|
||||||
func (m *Struct) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*Struct) ProtoMessage() {}
|
|
||||||
func (*Struct) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
|
||||||
func (*Struct) XXX_WellKnownType() string { return "Struct" }
|
|
||||||
|
|
||||||
func (m *Struct) GetFields() map[string]*Value {
|
|
||||||
if m != nil {
|
|
||||||
return m.Fields
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// `Value` represents a dynamically typed value which can be either
|
|
||||||
// null, a number, a string, a boolean, a recursive struct value, or a
|
|
||||||
// list of values. A producer of value is expected to set one of that
|
|
||||||
// variants, absence of any variant indicates an error.
|
|
||||||
//
|
|
||||||
// The JSON representation for `Value` is JSON value.
|
|
||||||
type Value struct {
|
|
||||||
// The kind of value.
|
|
||||||
//
|
|
||||||
// Types that are valid to be assigned to Kind:
|
|
||||||
// *Value_NullValue
|
|
||||||
// *Value_NumberValue
|
|
||||||
// *Value_StringValue
|
|
||||||
// *Value_BoolValue
|
|
||||||
// *Value_StructValue
|
|
||||||
// *Value_ListValue
|
|
||||||
Kind isValue_Kind `protobuf_oneof:"kind"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Value) Reset() { *m = Value{} }
|
|
||||||
func (m *Value) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*Value) ProtoMessage() {}
|
|
||||||
func (*Value) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
|
||||||
func (*Value) XXX_WellKnownType() string { return "Value" }
|
|
||||||
|
|
||||||
type isValue_Kind interface {
|
|
||||||
isValue_Kind()
|
|
||||||
}
|
|
||||||
|
|
||||||
type Value_NullValue struct {
|
|
||||||
NullValue NullValue `protobuf:"varint,1,opt,name=null_value,json=nullValue,enum=google.protobuf.NullValue,oneof"`
|
|
||||||
}
|
|
||||||
type Value_NumberValue struct {
|
|
||||||
NumberValue float64 `protobuf:"fixed64,2,opt,name=number_value,json=numberValue,oneof"`
|
|
||||||
}
|
|
||||||
type Value_StringValue struct {
|
|
||||||
StringValue string `protobuf:"bytes,3,opt,name=string_value,json=stringValue,oneof"`
|
|
||||||
}
|
|
||||||
type Value_BoolValue struct {
|
|
||||||
BoolValue bool `protobuf:"varint,4,opt,name=bool_value,json=boolValue,oneof"`
|
|
||||||
}
|
|
||||||
type Value_StructValue struct {
|
|
||||||
StructValue *Struct `protobuf:"bytes,5,opt,name=struct_value,json=structValue,oneof"`
|
|
||||||
}
|
|
||||||
type Value_ListValue struct {
|
|
||||||
ListValue *ListValue `protobuf:"bytes,6,opt,name=list_value,json=listValue,oneof"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*Value_NullValue) isValue_Kind() {}
|
|
||||||
func (*Value_NumberValue) isValue_Kind() {}
|
|
||||||
func (*Value_StringValue) isValue_Kind() {}
|
|
||||||
func (*Value_BoolValue) isValue_Kind() {}
|
|
||||||
func (*Value_StructValue) isValue_Kind() {}
|
|
||||||
func (*Value_ListValue) isValue_Kind() {}
|
|
||||||
|
|
||||||
func (m *Value) GetKind() isValue_Kind {
|
|
||||||
if m != nil {
|
|
||||||
return m.Kind
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Value) GetNullValue() NullValue {
|
|
||||||
if x, ok := m.GetKind().(*Value_NullValue); ok {
|
|
||||||
return x.NullValue
|
|
||||||
}
|
|
||||||
return NullValue_NULL_VALUE
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Value) GetNumberValue() float64 {
|
|
||||||
if x, ok := m.GetKind().(*Value_NumberValue); ok {
|
|
||||||
return x.NumberValue
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Value) GetStringValue() string {
|
|
||||||
if x, ok := m.GetKind().(*Value_StringValue); ok {
|
|
||||||
return x.StringValue
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Value) GetBoolValue() bool {
|
|
||||||
if x, ok := m.GetKind().(*Value_BoolValue); ok {
|
|
||||||
return x.BoolValue
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Value) GetStructValue() *Struct {
|
|
||||||
if x, ok := m.GetKind().(*Value_StructValue); ok {
|
|
||||||
return x.StructValue
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Value) GetListValue() *ListValue {
|
|
||||||
if x, ok := m.GetKind().(*Value_ListValue); ok {
|
|
||||||
return x.ListValue
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX_OneofFuncs is for the internal use of the proto package.
|
|
||||||
func (*Value) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {
|
|
||||||
return _Value_OneofMarshaler, _Value_OneofUnmarshaler, _Value_OneofSizer, []interface{}{
|
|
||||||
(*Value_NullValue)(nil),
|
|
||||||
(*Value_NumberValue)(nil),
|
|
||||||
(*Value_StringValue)(nil),
|
|
||||||
(*Value_BoolValue)(nil),
|
|
||||||
(*Value_StructValue)(nil),
|
|
||||||
(*Value_ListValue)(nil),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func _Value_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
|
|
||||||
m := msg.(*Value)
|
|
||||||
// kind
|
|
||||||
switch x := m.Kind.(type) {
|
|
||||||
case *Value_NullValue:
|
|
||||||
b.EncodeVarint(1<<3 | proto.WireVarint)
|
|
||||||
b.EncodeVarint(uint64(x.NullValue))
|
|
||||||
case *Value_NumberValue:
|
|
||||||
b.EncodeVarint(2<<3 | proto.WireFixed64)
|
|
||||||
b.EncodeFixed64(math.Float64bits(x.NumberValue))
|
|
||||||
case *Value_StringValue:
|
|
||||||
b.EncodeVarint(3<<3 | proto.WireBytes)
|
|
||||||
b.EncodeStringBytes(x.StringValue)
|
|
||||||
case *Value_BoolValue:
|
|
||||||
t := uint64(0)
|
|
||||||
if x.BoolValue {
|
|
||||||
t = 1
|
|
||||||
}
|
|
||||||
b.EncodeVarint(4<<3 | proto.WireVarint)
|
|
||||||
b.EncodeVarint(t)
|
|
||||||
case *Value_StructValue:
|
|
||||||
b.EncodeVarint(5<<3 | proto.WireBytes)
|
|
||||||
if err := b.EncodeMessage(x.StructValue); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case *Value_ListValue:
|
|
||||||
b.EncodeVarint(6<<3 | proto.WireBytes)
|
|
||||||
if err := b.EncodeMessage(x.ListValue); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case nil:
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("Value.Kind has unexpected type %T", x)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func _Value_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
|
|
||||||
m := msg.(*Value)
|
|
||||||
switch tag {
|
|
||||||
case 1: // kind.null_value
|
|
||||||
if wire != proto.WireVarint {
|
|
||||||
return true, proto.ErrInternalBadWireType
|
|
||||||
}
|
|
||||||
x, err := b.DecodeVarint()
|
|
||||||
m.Kind = &Value_NullValue{NullValue(x)}
|
|
||||||
return true, err
|
|
||||||
case 2: // kind.number_value
|
|
||||||
if wire != proto.WireFixed64 {
|
|
||||||
return true, proto.ErrInternalBadWireType
|
|
||||||
}
|
|
||||||
x, err := b.DecodeFixed64()
|
|
||||||
m.Kind = &Value_NumberValue{math.Float64frombits(x)}
|
|
||||||
return true, err
|
|
||||||
case 3: // kind.string_value
|
|
||||||
if wire != proto.WireBytes {
|
|
||||||
return true, proto.ErrInternalBadWireType
|
|
||||||
}
|
|
||||||
x, err := b.DecodeStringBytes()
|
|
||||||
m.Kind = &Value_StringValue{x}
|
|
||||||
return true, err
|
|
||||||
case 4: // kind.bool_value
|
|
||||||
if wire != proto.WireVarint {
|
|
||||||
return true, proto.ErrInternalBadWireType
|
|
||||||
}
|
|
||||||
x, err := b.DecodeVarint()
|
|
||||||
m.Kind = &Value_BoolValue{x != 0}
|
|
||||||
return true, err
|
|
||||||
case 5: // kind.struct_value
|
|
||||||
if wire != proto.WireBytes {
|
|
||||||
return true, proto.ErrInternalBadWireType
|
|
||||||
}
|
|
||||||
msg := new(Struct)
|
|
||||||
err := b.DecodeMessage(msg)
|
|
||||||
m.Kind = &Value_StructValue{msg}
|
|
||||||
return true, err
|
|
||||||
case 6: // kind.list_value
|
|
||||||
if wire != proto.WireBytes {
|
|
||||||
return true, proto.ErrInternalBadWireType
|
|
||||||
}
|
|
||||||
msg := new(ListValue)
|
|
||||||
err := b.DecodeMessage(msg)
|
|
||||||
m.Kind = &Value_ListValue{msg}
|
|
||||||
return true, err
|
|
||||||
default:
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func _Value_OneofSizer(msg proto.Message) (n int) {
|
|
||||||
m := msg.(*Value)
|
|
||||||
// kind
|
|
||||||
switch x := m.Kind.(type) {
|
|
||||||
case *Value_NullValue:
|
|
||||||
n += proto.SizeVarint(1<<3 | proto.WireVarint)
|
|
||||||
n += proto.SizeVarint(uint64(x.NullValue))
|
|
||||||
case *Value_NumberValue:
|
|
||||||
n += proto.SizeVarint(2<<3 | proto.WireFixed64)
|
|
||||||
n += 8
|
|
||||||
case *Value_StringValue:
|
|
||||||
n += proto.SizeVarint(3<<3 | proto.WireBytes)
|
|
||||||
n += proto.SizeVarint(uint64(len(x.StringValue)))
|
|
||||||
n += len(x.StringValue)
|
|
||||||
case *Value_BoolValue:
|
|
||||||
n += proto.SizeVarint(4<<3 | proto.WireVarint)
|
|
||||||
n += 1
|
|
||||||
case *Value_StructValue:
|
|
||||||
s := proto.Size(x.StructValue)
|
|
||||||
n += proto.SizeVarint(5<<3 | proto.WireBytes)
|
|
||||||
n += proto.SizeVarint(uint64(s))
|
|
||||||
n += s
|
|
||||||
case *Value_ListValue:
|
|
||||||
s := proto.Size(x.ListValue)
|
|
||||||
n += proto.SizeVarint(6<<3 | proto.WireBytes)
|
|
||||||
n += proto.SizeVarint(uint64(s))
|
|
||||||
n += s
|
|
||||||
case nil:
|
|
||||||
default:
|
|
||||||
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
|
|
||||||
}
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
// `ListValue` is a wrapper around a repeated field of values.
|
|
||||||
//
|
|
||||||
// The JSON representation for `ListValue` is JSON array.
|
|
||||||
type ListValue struct {
|
|
||||||
// Repeated field of dynamically typed values.
|
|
||||||
Values []*Value `protobuf:"bytes,1,rep,name=values" json:"values,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ListValue) Reset() { *m = ListValue{} }
|
|
||||||
func (m *ListValue) String() string { return proto.CompactTextString(m) }
|
|
||||||
func (*ListValue) ProtoMessage() {}
|
|
||||||
func (*ListValue) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
|
|
||||||
func (*ListValue) XXX_WellKnownType() string { return "ListValue" }
|
|
||||||
|
|
||||||
func (m *ListValue) GetValues() []*Value {
|
|
||||||
if m != nil {
|
|
||||||
return m.Values
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
proto.RegisterType((*Struct)(nil), "google.protobuf.Struct")
|
|
||||||
proto.RegisterType((*Value)(nil), "google.protobuf.Value")
|
|
||||||
proto.RegisterType((*ListValue)(nil), "google.protobuf.ListValue")
|
|
||||||
proto.RegisterEnum("google.protobuf.NullValue", NullValue_name, NullValue_value)
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
proto.RegisterFile("github.com/golang/protobuf/ptypes/struct/struct.proto", fileDescriptor0)
|
|
||||||
}
|
|
||||||
|
|
||||||
var fileDescriptor0 = []byte{
|
|
||||||
// 417 bytes of a gzipped FileDescriptorProto
|
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x41, 0x8b, 0xd3, 0x40,
|
|
||||||
0x14, 0x80, 0x3b, 0xc9, 0x36, 0x98, 0x17, 0x59, 0x97, 0x11, 0xb4, 0xac, 0xa0, 0xa1, 0x7b, 0x09,
|
|
||||||
0x22, 0x09, 0x56, 0x04, 0x31, 0x5e, 0x0c, 0xac, 0xbb, 0x60, 0x58, 0x62, 0x74, 0x57, 0xf0, 0x52,
|
|
||||||
0x9a, 0x34, 0x8d, 0xa1, 0xd3, 0x99, 0x90, 0xcc, 0x28, 0x3d, 0xfa, 0x2f, 0x3c, 0x7b, 0xf4, 0xe8,
|
|
||||||
0xaf, 0xf3, 0x28, 0x33, 0x93, 0x44, 0x69, 0x29, 0x78, 0x9a, 0xbe, 0x37, 0xdf, 0xfb, 0xe6, 0xbd,
|
|
||||||
0xd7, 0xc0, 0xf3, 0xb2, 0xe2, 0x9f, 0x45, 0xe6, 0xe7, 0x6c, 0x13, 0x94, 0x8c, 0x2c, 0x68, 0x19,
|
|
||||||
0xd4, 0x0d, 0xe3, 0x2c, 0x13, 0xab, 0xa0, 0xe6, 0xdb, 0xba, 0x68, 0x83, 0x96, 0x37, 0x22, 0xe7,
|
|
||||||
0xdd, 0xe1, 0xab, 0x5b, 0x7c, 0xa7, 0x64, 0xac, 0x24, 0x85, 0xdf, 0xb3, 0xd3, 0xef, 0x08, 0xac,
|
|
||||||
0xf7, 0x8a, 0xc0, 0x21, 0x58, 0xab, 0xaa, 0x20, 0xcb, 0x76, 0x82, 0x5c, 0xd3, 0x73, 0x66, 0x67,
|
|
||||||
0xfe, 0x0e, 0xec, 0x6b, 0xd0, 0x7f, 0xa3, 0xa8, 0x73, 0xca, 0x9b, 0x6d, 0xda, 0x95, 0x9c, 0xbe,
|
|
||||||
0x03, 0xe7, 0x9f, 0x34, 0x3e, 0x01, 0x73, 0x5d, 0x6c, 0x27, 0xc8, 0x45, 0x9e, 0x9d, 0xca, 0x9f,
|
|
||||||
0xf8, 0x09, 0x8c, 0xbf, 0x2c, 0x88, 0x28, 0x26, 0x86, 0x8b, 0x3c, 0x67, 0x76, 0x6f, 0x4f, 0x7e,
|
|
||||||
0x23, 0x6f, 0x53, 0x0d, 0xbd, 0x34, 0x5e, 0xa0, 0xe9, 0x2f, 0x03, 0xc6, 0x2a, 0x89, 0x43, 0x00,
|
|
||||||
0x2a, 0x08, 0x99, 0x6b, 0x81, 0x94, 0x1e, 0xcf, 0x4e, 0xf7, 0x04, 0x57, 0x82, 0x10, 0xc5, 0x5f,
|
|
||||||
0x8e, 0x52, 0x9b, 0xf6, 0x01, 0x3e, 0x83, 0xdb, 0x54, 0x6c, 0xb2, 0xa2, 0x99, 0xff, 0x7d, 0x1f,
|
|
||||||
0x5d, 0x8e, 0x52, 0x47, 0x67, 0x07, 0xa8, 0xe5, 0x4d, 0x45, 0xcb, 0x0e, 0x32, 0x65, 0xe3, 0x12,
|
|
||||||
0xd2, 0x59, 0x0d, 0x3d, 0x02, 0xc8, 0x18, 0xeb, 0xdb, 0x38, 0x72, 0x91, 0x77, 0x4b, 0x3e, 0x25,
|
|
||||||
0x73, 0x1a, 0x78, 0xa5, 0x2c, 0x22, 0xe7, 0x1d, 0x32, 0x56, 0xa3, 0xde, 0x3f, 0xb0, 0xc7, 0x4e,
|
|
||||||
0x2f, 0x72, 0x3e, 0x4c, 0x49, 0xaa, 0xb6, 0xaf, 0xb5, 0x54, 0xed, 0xfe, 0x94, 0x71, 0xd5, 0xf2,
|
|
||||||
0x61, 0x4a, 0xd2, 0x07, 0x91, 0x05, 0x47, 0xeb, 0x8a, 0x2e, 0xa7, 0x21, 0xd8, 0x03, 0x81, 0x7d,
|
|
||||||
0xb0, 0x94, 0xac, 0xff, 0x47, 0x0f, 0x2d, 0xbd, 0xa3, 0x1e, 0x3f, 0x00, 0x7b, 0x58, 0x22, 0x3e,
|
|
||||||
0x06, 0xb8, 0xba, 0x8e, 0xe3, 0xf9, 0xcd, 0xeb, 0xf8, 0xfa, 0xfc, 0x64, 0x14, 0x7d, 0x43, 0x70,
|
|
||||||
0x37, 0x67, 0x9b, 0x5d, 0x45, 0xe4, 0xe8, 0x69, 0x12, 0x19, 0x27, 0xe8, 0xd3, 0xd3, 0xff, 0xfd,
|
|
||||||
0x30, 0x43, 0x7d, 0xd4, 0xd9, 0x6f, 0x84, 0x7e, 0x18, 0xe6, 0x45, 0x12, 0xfd, 0x34, 0x1e, 0x5e,
|
|
||||||
0x68, 0x79, 0xd2, 0xf7, 0xf7, 0xb1, 0x20, 0xe4, 0x2d, 0x65, 0x5f, 0xe9, 0x07, 0x59, 0x99, 0x59,
|
|
||||||
0x4a, 0xf5, 0xec, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9b, 0x6e, 0x5d, 0x3c, 0xfe, 0x02, 0x00,
|
|
||||||
0x00,
|
|
||||||
}
|
|
96
vendor/github.com/golang/protobuf/ptypes/struct/struct.proto
generated
vendored
96
vendor/github.com/golang/protobuf/ptypes/struct/struct.proto
generated
vendored
|
@ -1,96 +0,0 @@
|
||||||
// Protocol Buffers - Google's data interchange format
|
|
||||||
// Copyright 2008 Google Inc. All rights reserved.
|
|
||||||
// https://developers.google.com/protocol-buffers/
|
|
||||||
//
|
|
||||||
// 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 Google Inc. 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 THE COPYRIGHT
|
|
||||||
// OWNER OR CONTRIBUTORS 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.
|
|
||||||
|
|
||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package google.protobuf;
|
|
||||||
|
|
||||||
option csharp_namespace = "Google.Protobuf.WellKnownTypes";
|
|
||||||
option cc_enable_arenas = true;
|
|
||||||
option go_package = "github.com/golang/protobuf/ptypes/struct;structpb";
|
|
||||||
option java_package = "com.google.protobuf";
|
|
||||||
option java_outer_classname = "StructProto";
|
|
||||||
option java_multiple_files = true;
|
|
||||||
option objc_class_prefix = "GPB";
|
|
||||||
|
|
||||||
|
|
||||||
// `Struct` represents a structured data value, consisting of fields
|
|
||||||
// which map to dynamically typed values. In some languages, `Struct`
|
|
||||||
// might be supported by a native representation. For example, in
|
|
||||||
// scripting languages like JS a struct is represented as an
|
|
||||||
// object. The details of that representation are described together
|
|
||||||
// with the proto support for the language.
|
|
||||||
//
|
|
||||||
// The JSON representation for `Struct` is JSON object.
|
|
||||||
message Struct {
|
|
||||||
// Unordered map of dynamically typed values.
|
|
||||||
map<string, Value> fields = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// `Value` represents a dynamically typed value which can be either
|
|
||||||
// null, a number, a string, a boolean, a recursive struct value, or a
|
|
||||||
// list of values. A producer of value is expected to set one of that
|
|
||||||
// variants, absence of any variant indicates an error.
|
|
||||||
//
|
|
||||||
// The JSON representation for `Value` is JSON value.
|
|
||||||
message Value {
|
|
||||||
// The kind of value.
|
|
||||||
oneof kind {
|
|
||||||
// Represents a null value.
|
|
||||||
NullValue null_value = 1;
|
|
||||||
// Represents a double value.
|
|
||||||
double number_value = 2;
|
|
||||||
// Represents a string value.
|
|
||||||
string string_value = 3;
|
|
||||||
// Represents a boolean value.
|
|
||||||
bool bool_value = 4;
|
|
||||||
// Represents a structured value.
|
|
||||||
Struct struct_value = 5;
|
|
||||||
// Represents a repeated `Value`.
|
|
||||||
ListValue list_value = 6;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// `NullValue` is a singleton enumeration to represent the null value for the
|
|
||||||
// `Value` type union.
|
|
||||||
//
|
|
||||||
// The JSON representation for `NullValue` is JSON `null`.
|
|
||||||
enum NullValue {
|
|
||||||
// Null value.
|
|
||||||
NULL_VALUE = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// `ListValue` is a wrapper around a repeated field of values.
|
|
||||||
//
|
|
||||||
// The JSON representation for `ListValue` is JSON array.
|
|
||||||
message ListValue {
|
|
||||||
// Repeated field of dynamically typed values.
|
|
||||||
repeated Value values = 1;
|
|
||||||
}
|
|
89
vendor/github.com/prometheus/common/log/eventlog_formatter.go
generated
vendored
89
vendor/github.com/prometheus/common/log/eventlog_formatter.go
generated
vendored
|
@ -1,89 +0,0 @@
|
||||||
// Copyright 2015 The Prometheus Authors
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package log
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"golang.org/x/sys/windows/svc/eventlog"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
setEventlogFormatter = func(l logger, name string, debugAsInfo bool) error {
|
|
||||||
if name == "" {
|
|
||||||
return fmt.Errorf("missing name parameter")
|
|
||||||
}
|
|
||||||
|
|
||||||
fmter, err := newEventlogger(name, debugAsInfo, l.entry.Logger.Formatter)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "error creating eventlog formatter: %v\n", err)
|
|
||||||
l.Errorf("can't connect logger to eventlog: %v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
l.entry.Logger.Formatter = fmter
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type eventlogger struct {
|
|
||||||
log *eventlog.Log
|
|
||||||
debugAsInfo bool
|
|
||||||
wrap logrus.Formatter
|
|
||||||
}
|
|
||||||
|
|
||||||
func newEventlogger(name string, debugAsInfo bool, fmter logrus.Formatter) (*eventlogger, error) {
|
|
||||||
logHandle, err := eventlog.Open(name)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &eventlogger{log: logHandle, debugAsInfo: debugAsInfo, wrap: fmter}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *eventlogger) Format(e *logrus.Entry) ([]byte, error) {
|
|
||||||
data, err := s.wrap.Format(e)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "eventlogger: can't format entry: %v\n", err)
|
|
||||||
return data, err
|
|
||||||
}
|
|
||||||
|
|
||||||
switch e.Level {
|
|
||||||
case logrus.PanicLevel:
|
|
||||||
fallthrough
|
|
||||||
case logrus.FatalLevel:
|
|
||||||
fallthrough
|
|
||||||
case logrus.ErrorLevel:
|
|
||||||
err = s.log.Error(102, e.Message)
|
|
||||||
case logrus.WarnLevel:
|
|
||||||
err = s.log.Warning(101, e.Message)
|
|
||||||
case logrus.InfoLevel:
|
|
||||||
err = s.log.Info(100, e.Message)
|
|
||||||
case logrus.DebugLevel:
|
|
||||||
if s.debugAsInfo {
|
|
||||||
err = s.log.Info(100, e.Message)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
err = s.log.Info(100, e.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "eventlogger: can't send log to eventlog: %v\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return data, err
|
|
||||||
}
|
|
382
vendor/github.com/prometheus/common/log/log.go
generated
vendored
382
vendor/github.com/prometheus/common/log/log.go
generated
vendored
|
@ -1,382 +0,0 @@
|
||||||
// Copyright 2015 The Prometheus Authors
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package log
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"net/url"
|
|
||||||
"os"
|
|
||||||
"runtime"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
type levelFlag string
|
|
||||||
|
|
||||||
// String implements flag.Value.
|
|
||||||
func (f levelFlag) String() string {
|
|
||||||
return fmt.Sprintf("%q", origLogger.Level.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set implements flag.Value.
|
|
||||||
func (f levelFlag) Set(level string) error {
|
|
||||||
l, err := logrus.ParseLevel(level)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
origLogger.Level = l
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// setSyslogFormatter is nil if the target architecture does not support syslog.
|
|
||||||
var setSyslogFormatter func(logger, string, string) error
|
|
||||||
|
|
||||||
// setEventlogFormatter is nil if the target OS does not support Eventlog (i.e., is not Windows).
|
|
||||||
var setEventlogFormatter func(logger, string, bool) error
|
|
||||||
|
|
||||||
func setJSONFormatter() {
|
|
||||||
origLogger.Formatter = &logrus.JSONFormatter{}
|
|
||||||
}
|
|
||||||
|
|
||||||
type logFormatFlag url.URL
|
|
||||||
|
|
||||||
// String implements flag.Value.
|
|
||||||
func (f logFormatFlag) String() string {
|
|
||||||
u := url.URL(f)
|
|
||||||
return fmt.Sprintf("%q", u.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set implements flag.Value.
|
|
||||||
func (f logFormatFlag) Set(format string) error {
|
|
||||||
return baseLogger.SetFormat(format)
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
AddFlags(flag.CommandLine)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddFlags adds the flags used by this package to the given FlagSet. That's
|
|
||||||
// useful if working with a custom FlagSet. The init function of this package
|
|
||||||
// adds the flags to flag.CommandLine anyway. Thus, it's usually enough to call
|
|
||||||
// flag.Parse() to make the logging flags take effect.
|
|
||||||
func AddFlags(fs *flag.FlagSet) {
|
|
||||||
fs.Var(
|
|
||||||
levelFlag(origLogger.Level.String()),
|
|
||||||
"log.level",
|
|
||||||
"Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal]",
|
|
||||||
)
|
|
||||||
fs.Var(
|
|
||||||
logFormatFlag(url.URL{Scheme: "logger", Opaque: "stderr"}),
|
|
||||||
"log.format",
|
|
||||||
`Set the log target and format. Example: "logger:syslog?appname=bob&local=7" or "logger:stdout?json=true"`,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Logger is the interface for loggers used in the Prometheus components.
|
|
||||||
type Logger interface {
|
|
||||||
Debug(...interface{})
|
|
||||||
Debugln(...interface{})
|
|
||||||
Debugf(string, ...interface{})
|
|
||||||
|
|
||||||
Info(...interface{})
|
|
||||||
Infoln(...interface{})
|
|
||||||
Infof(string, ...interface{})
|
|
||||||
|
|
||||||
Warn(...interface{})
|
|
||||||
Warnln(...interface{})
|
|
||||||
Warnf(string, ...interface{})
|
|
||||||
|
|
||||||
Error(...interface{})
|
|
||||||
Errorln(...interface{})
|
|
||||||
Errorf(string, ...interface{})
|
|
||||||
|
|
||||||
Fatal(...interface{})
|
|
||||||
Fatalln(...interface{})
|
|
||||||
Fatalf(string, ...interface{})
|
|
||||||
|
|
||||||
With(key string, value interface{}) Logger
|
|
||||||
|
|
||||||
SetFormat(string) error
|
|
||||||
SetLevel(string) error
|
|
||||||
}
|
|
||||||
|
|
||||||
type logger struct {
|
|
||||||
entry *logrus.Entry
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l logger) With(key string, value interface{}) Logger {
|
|
||||||
return logger{l.entry.WithField(key, value)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debug logs a message at level Debug on the standard logger.
|
|
||||||
func (l logger) Debug(args ...interface{}) {
|
|
||||||
l.sourced().Debug(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debug logs a message at level Debug on the standard logger.
|
|
||||||
func (l logger) Debugln(args ...interface{}) {
|
|
||||||
l.sourced().Debugln(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debugf logs a message at level Debug on the standard logger.
|
|
||||||
func (l logger) Debugf(format string, args ...interface{}) {
|
|
||||||
l.sourced().Debugf(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info logs a message at level Info on the standard logger.
|
|
||||||
func (l logger) Info(args ...interface{}) {
|
|
||||||
l.sourced().Info(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info logs a message at level Info on the standard logger.
|
|
||||||
func (l logger) Infoln(args ...interface{}) {
|
|
||||||
l.sourced().Infoln(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Infof logs a message at level Info on the standard logger.
|
|
||||||
func (l logger) Infof(format string, args ...interface{}) {
|
|
||||||
l.sourced().Infof(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warn logs a message at level Warn on the standard logger.
|
|
||||||
func (l logger) Warn(args ...interface{}) {
|
|
||||||
l.sourced().Warn(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warn logs a message at level Warn on the standard logger.
|
|
||||||
func (l logger) Warnln(args ...interface{}) {
|
|
||||||
l.sourced().Warnln(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warnf logs a message at level Warn on the standard logger.
|
|
||||||
func (l logger) Warnf(format string, args ...interface{}) {
|
|
||||||
l.sourced().Warnf(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error logs a message at level Error on the standard logger.
|
|
||||||
func (l logger) Error(args ...interface{}) {
|
|
||||||
l.sourced().Error(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error logs a message at level Error on the standard logger.
|
|
||||||
func (l logger) Errorln(args ...interface{}) {
|
|
||||||
l.sourced().Errorln(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Errorf logs a message at level Error on the standard logger.
|
|
||||||
func (l logger) Errorf(format string, args ...interface{}) {
|
|
||||||
l.sourced().Errorf(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fatal logs a message at level Fatal on the standard logger.
|
|
||||||
func (l logger) Fatal(args ...interface{}) {
|
|
||||||
l.sourced().Fatal(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fatal logs a message at level Fatal on the standard logger.
|
|
||||||
func (l logger) Fatalln(args ...interface{}) {
|
|
||||||
l.sourced().Fatalln(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fatalf logs a message at level Fatal on the standard logger.
|
|
||||||
func (l logger) Fatalf(format string, args ...interface{}) {
|
|
||||||
l.sourced().Fatalf(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l logger) SetLevel(level string) error {
|
|
||||||
lvl, err := logrus.ParseLevel(level)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
l.entry.Logger.Level = lvl
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l logger) SetFormat(format string) error {
|
|
||||||
u, err := url.Parse(format)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if u.Scheme != "logger" {
|
|
||||||
return fmt.Errorf("invalid scheme %s", u.Scheme)
|
|
||||||
}
|
|
||||||
jsonq := u.Query().Get("json")
|
|
||||||
if jsonq == "true" {
|
|
||||||
setJSONFormatter()
|
|
||||||
}
|
|
||||||
|
|
||||||
switch u.Opaque {
|
|
||||||
case "syslog":
|
|
||||||
if setSyslogFormatter == nil {
|
|
||||||
return fmt.Errorf("system does not support syslog")
|
|
||||||
}
|
|
||||||
appname := u.Query().Get("appname")
|
|
||||||
facility := u.Query().Get("local")
|
|
||||||
return setSyslogFormatter(l, appname, facility)
|
|
||||||
case "eventlog":
|
|
||||||
if setEventlogFormatter == nil {
|
|
||||||
return fmt.Errorf("system does not support eventlog")
|
|
||||||
}
|
|
||||||
name := u.Query().Get("name")
|
|
||||||
debugAsInfo := false
|
|
||||||
debugAsInfoRaw := u.Query().Get("debugAsInfo")
|
|
||||||
if parsedDebugAsInfo, err := strconv.ParseBool(debugAsInfoRaw); err == nil {
|
|
||||||
debugAsInfo = parsedDebugAsInfo
|
|
||||||
}
|
|
||||||
return setEventlogFormatter(l, name, debugAsInfo)
|
|
||||||
case "stdout":
|
|
||||||
l.entry.Logger.Out = os.Stdout
|
|
||||||
case "stderr":
|
|
||||||
l.entry.Logger.Out = os.Stderr
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("unsupported logger %q", u.Opaque)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// sourced adds a source field to the logger that contains
|
|
||||||
// the file name and line where the logging happened.
|
|
||||||
func (l logger) sourced() *logrus.Entry {
|
|
||||||
_, file, line, ok := runtime.Caller(2)
|
|
||||||
if !ok {
|
|
||||||
file = "<???>"
|
|
||||||
line = 1
|
|
||||||
} else {
|
|
||||||
slash := strings.LastIndex(file, "/")
|
|
||||||
file = file[slash+1:]
|
|
||||||
}
|
|
||||||
return l.entry.WithField("source", fmt.Sprintf("%s:%d", file, line))
|
|
||||||
}
|
|
||||||
|
|
||||||
var origLogger = logrus.New()
|
|
||||||
var baseLogger = logger{entry: logrus.NewEntry(origLogger)}
|
|
||||||
|
|
||||||
// Base returns the default Logger logging to
|
|
||||||
func Base() Logger {
|
|
||||||
return baseLogger
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewLogger returns a new Logger logging to out.
|
|
||||||
func NewLogger(w io.Writer) Logger {
|
|
||||||
l := logrus.New()
|
|
||||||
l.Out = w
|
|
||||||
return logger{entry: logrus.NewEntry(l)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewNopLogger returns a logger that discards all log messages.
|
|
||||||
func NewNopLogger() Logger {
|
|
||||||
l := logrus.New()
|
|
||||||
l.Out = ioutil.Discard
|
|
||||||
return logger{entry: logrus.NewEntry(l)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// With adds a field to the logger.
|
|
||||||
func With(key string, value interface{}) Logger {
|
|
||||||
return baseLogger.With(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debug logs a message at level Debug on the standard logger.
|
|
||||||
func Debug(args ...interface{}) {
|
|
||||||
baseLogger.sourced().Debug(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debugln logs a message at level Debug on the standard logger.
|
|
||||||
func Debugln(args ...interface{}) {
|
|
||||||
baseLogger.sourced().Debugln(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debugf logs a message at level Debug on the standard logger.
|
|
||||||
func Debugf(format string, args ...interface{}) {
|
|
||||||
baseLogger.sourced().Debugf(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info logs a message at level Info on the standard logger.
|
|
||||||
func Info(args ...interface{}) {
|
|
||||||
baseLogger.sourced().Info(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Infoln logs a message at level Info on the standard logger.
|
|
||||||
func Infoln(args ...interface{}) {
|
|
||||||
baseLogger.sourced().Infoln(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Infof logs a message at level Info on the standard logger.
|
|
||||||
func Infof(format string, args ...interface{}) {
|
|
||||||
baseLogger.sourced().Infof(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warn logs a message at level Warn on the standard logger.
|
|
||||||
func Warn(args ...interface{}) {
|
|
||||||
baseLogger.sourced().Warn(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warnln logs a message at level Warn on the standard logger.
|
|
||||||
func Warnln(args ...interface{}) {
|
|
||||||
baseLogger.sourced().Warnln(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warnf logs a message at level Warn on the standard logger.
|
|
||||||
func Warnf(format string, args ...interface{}) {
|
|
||||||
baseLogger.sourced().Warnf(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error logs a message at level Error on the standard logger.
|
|
||||||
func Error(args ...interface{}) {
|
|
||||||
baseLogger.sourced().Error(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Errorln logs a message at level Error on the standard logger.
|
|
||||||
func Errorln(args ...interface{}) {
|
|
||||||
baseLogger.sourced().Errorln(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Errorf logs a message at level Error on the standard logger.
|
|
||||||
func Errorf(format string, args ...interface{}) {
|
|
||||||
baseLogger.sourced().Errorf(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fatal logs a message at level Fatal on the standard logger.
|
|
||||||
func Fatal(args ...interface{}) {
|
|
||||||
baseLogger.sourced().Fatal(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fatalln logs a message at level Fatal on the standard logger.
|
|
||||||
func Fatalln(args ...interface{}) {
|
|
||||||
baseLogger.sourced().Fatalln(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fatalf logs a message at level Fatal on the standard logger.
|
|
||||||
func Fatalf(format string, args ...interface{}) {
|
|
||||||
baseLogger.sourced().Fatalf(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
type errorLogWriter struct{}
|
|
||||||
|
|
||||||
func (errorLogWriter) Write(b []byte) (int, error) {
|
|
||||||
baseLogger.sourced().Error(string(b))
|
|
||||||
return len(b), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewErrorLogger returns a log.Logger that is meant to be used
|
|
||||||
// in the ErrorLog field of an http.Server to log HTTP server errors.
|
|
||||||
func NewErrorLogger() *log.Logger {
|
|
||||||
return log.New(&errorLogWriter{}, "", 0)
|
|
||||||
}
|
|
126
vendor/github.com/prometheus/common/log/syslog_formatter.go
generated
vendored
126
vendor/github.com/prometheus/common/log/syslog_formatter.go
generated
vendored
|
@ -1,126 +0,0 @@
|
||||||
// Copyright 2015 The Prometheus Authors
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build !windows,!nacl,!plan9
|
|
||||||
|
|
||||||
package log
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log/syslog"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ logrus.Formatter = (*syslogger)(nil)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
setSyslogFormatter = func(l logger, appname, local string) error {
|
|
||||||
if appname == "" {
|
|
||||||
return fmt.Errorf("missing appname parameter")
|
|
||||||
}
|
|
||||||
if local == "" {
|
|
||||||
return fmt.Errorf("missing local parameter")
|
|
||||||
}
|
|
||||||
|
|
||||||
fmter, err := newSyslogger(appname, local, l.entry.Logger.Formatter)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "error creating syslog formatter: %v\n", err)
|
|
||||||
l.entry.Errorf("can't connect logger to syslog: %v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
l.entry.Logger.Formatter = fmter
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var prefixTag []byte
|
|
||||||
|
|
||||||
type syslogger struct {
|
|
||||||
wrap logrus.Formatter
|
|
||||||
out *syslog.Writer
|
|
||||||
}
|
|
||||||
|
|
||||||
func newSyslogger(appname string, facility string, fmter logrus.Formatter) (*syslogger, error) {
|
|
||||||
priority, err := getFacility(facility)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
out, err := syslog.New(priority, appname)
|
|
||||||
_, isJSON := fmter.(*logrus.JSONFormatter)
|
|
||||||
if isJSON {
|
|
||||||
// add cee tag to json formatted syslogs
|
|
||||||
prefixTag = []byte("@cee:")
|
|
||||||
}
|
|
||||||
return &syslogger{
|
|
||||||
out: out,
|
|
||||||
wrap: fmter,
|
|
||||||
}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func getFacility(facility string) (syslog.Priority, error) {
|
|
||||||
switch facility {
|
|
||||||
case "0":
|
|
||||||
return syslog.LOG_LOCAL0, nil
|
|
||||||
case "1":
|
|
||||||
return syslog.LOG_LOCAL1, nil
|
|
||||||
case "2":
|
|
||||||
return syslog.LOG_LOCAL2, nil
|
|
||||||
case "3":
|
|
||||||
return syslog.LOG_LOCAL3, nil
|
|
||||||
case "4":
|
|
||||||
return syslog.LOG_LOCAL4, nil
|
|
||||||
case "5":
|
|
||||||
return syslog.LOG_LOCAL5, nil
|
|
||||||
case "6":
|
|
||||||
return syslog.LOG_LOCAL6, nil
|
|
||||||
case "7":
|
|
||||||
return syslog.LOG_LOCAL7, nil
|
|
||||||
}
|
|
||||||
return syslog.LOG_LOCAL0, fmt.Errorf("invalid local(%s) for syslog", facility)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *syslogger) Format(e *logrus.Entry) ([]byte, error) {
|
|
||||||
data, err := s.wrap.Format(e)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "syslogger: can't format entry: %v\n", err)
|
|
||||||
return data, err
|
|
||||||
}
|
|
||||||
// only append tag to data sent to syslog (line), not to what
|
|
||||||
// is returned
|
|
||||||
line := string(append(prefixTag, data...))
|
|
||||||
|
|
||||||
switch e.Level {
|
|
||||||
case logrus.PanicLevel:
|
|
||||||
err = s.out.Crit(line)
|
|
||||||
case logrus.FatalLevel:
|
|
||||||
err = s.out.Crit(line)
|
|
||||||
case logrus.ErrorLevel:
|
|
||||||
err = s.out.Err(line)
|
|
||||||
case logrus.WarnLevel:
|
|
||||||
err = s.out.Warning(line)
|
|
||||||
case logrus.InfoLevel:
|
|
||||||
err = s.out.Info(line)
|
|
||||||
case logrus.DebugLevel:
|
|
||||||
err = s.out.Debug(line)
|
|
||||||
default:
|
|
||||||
err = s.out.Notice(line)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "syslogger: can't send log to syslog: %v\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return data, err
|
|
||||||
}
|
|
100
vendor/github.com/sirupsen/logrus/CHANGELOG.md
generated
vendored
100
vendor/github.com/sirupsen/logrus/CHANGELOG.md
generated
vendored
|
@ -1,100 +0,0 @@
|
||||||
# 1.0.0
|
|
||||||
|
|
||||||
* Officially changed name to lower-case
|
|
||||||
* bug: colors on Windows 10 (#541)
|
|
||||||
* bug: fix race in accessing level (#512)
|
|
||||||
|
|
||||||
# 0.11.5
|
|
||||||
|
|
||||||
* feature: add writer and writerlevel to entry (#372)
|
|
||||||
|
|
||||||
# 0.11.4
|
|
||||||
|
|
||||||
* bug: fix undefined variable on solaris (#493)
|
|
||||||
|
|
||||||
# 0.11.3
|
|
||||||
|
|
||||||
* formatter: configure quoting of empty values (#484)
|
|
||||||
* formatter: configure quoting character (default is `"`) (#484)
|
|
||||||
* bug: fix not importing io correctly in non-linux environments (#481)
|
|
||||||
|
|
||||||
# 0.11.2
|
|
||||||
|
|
||||||
* bug: fix windows terminal detection (#476)
|
|
||||||
|
|
||||||
# 0.11.1
|
|
||||||
|
|
||||||
* bug: fix tty detection with custom out (#471)
|
|
||||||
|
|
||||||
# 0.11.0
|
|
||||||
|
|
||||||
* performance: Use bufferpool to allocate (#370)
|
|
||||||
* terminal: terminal detection for app-engine (#343)
|
|
||||||
* feature: exit handler (#375)
|
|
||||||
|
|
||||||
# 0.10.0
|
|
||||||
|
|
||||||
* feature: Add a test hook (#180)
|
|
||||||
* feature: `ParseLevel` is now case-insensitive (#326)
|
|
||||||
* feature: `FieldLogger` interface that generalizes `Logger` and `Entry` (#308)
|
|
||||||
* performance: avoid re-allocations on `WithFields` (#335)
|
|
||||||
|
|
||||||
# 0.9.0
|
|
||||||
|
|
||||||
* logrus/text_formatter: don't emit empty msg
|
|
||||||
* logrus/hooks/airbrake: move out of main repository
|
|
||||||
* logrus/hooks/sentry: move out of main repository
|
|
||||||
* logrus/hooks/papertrail: move out of main repository
|
|
||||||
* logrus/hooks/bugsnag: move out of main repository
|
|
||||||
* logrus/core: run tests with `-race`
|
|
||||||
* logrus/core: detect TTY based on `stderr`
|
|
||||||
* logrus/core: support `WithError` on logger
|
|
||||||
* logrus/core: Solaris support
|
|
||||||
|
|
||||||
# 0.8.7
|
|
||||||
|
|
||||||
* logrus/core: fix possible race (#216)
|
|
||||||
* logrus/doc: small typo fixes and doc improvements
|
|
||||||
|
|
||||||
|
|
||||||
# 0.8.6
|
|
||||||
|
|
||||||
* hooks/raven: allow passing an initialized client
|
|
||||||
|
|
||||||
# 0.8.5
|
|
||||||
|
|
||||||
* logrus/core: revert #208
|
|
||||||
|
|
||||||
# 0.8.4
|
|
||||||
|
|
||||||
* formatter/text: fix data race (#218)
|
|
||||||
|
|
||||||
# 0.8.3
|
|
||||||
|
|
||||||
* logrus/core: fix entry log level (#208)
|
|
||||||
* logrus/core: improve performance of text formatter by 40%
|
|
||||||
* logrus/core: expose `LevelHooks` type
|
|
||||||
* logrus/core: add support for DragonflyBSD and NetBSD
|
|
||||||
* formatter/text: print structs more verbosely
|
|
||||||
|
|
||||||
# 0.8.2
|
|
||||||
|
|
||||||
* logrus: fix more Fatal family functions
|
|
||||||
|
|
||||||
# 0.8.1
|
|
||||||
|
|
||||||
* logrus: fix not exiting on `Fatalf` and `Fatalln`
|
|
||||||
|
|
||||||
# 0.8.0
|
|
||||||
|
|
||||||
* logrus: defaults to stderr instead of stdout
|
|
||||||
* hooks/sentry: add special field for `*http.Request`
|
|
||||||
* formatter/text: ignore Windows for colors
|
|
||||||
|
|
||||||
# 0.7.3
|
|
||||||
|
|
||||||
* formatter/\*: allow configuration of timestamp layout
|
|
||||||
|
|
||||||
# 0.7.2
|
|
||||||
|
|
||||||
* formatter/text: Add configuration option for time format (#158)
|
|
21
vendor/github.com/sirupsen/logrus/LICENSE
generated
vendored
21
vendor/github.com/sirupsen/logrus/LICENSE
generated
vendored
|
@ -1,21 +0,0 @@
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2014 Simon Eskildsen
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
501
vendor/github.com/sirupsen/logrus/README.md
generated
vendored
501
vendor/github.com/sirupsen/logrus/README.md
generated
vendored
|
@ -1,501 +0,0 @@
|
||||||
# Logrus <img src="http://i.imgur.com/hTeVwmJ.png" width="40" height="40" alt=":walrus:" class="emoji" title=":walrus:"/> [![Build Status](https://travis-ci.org/sirupsen/logrus.svg?branch=master)](https://travis-ci.org/sirupsen/logrus) [![GoDoc](https://godoc.org/github.com/sirupsen/logrus?status.svg)](https://godoc.org/github.com/sirupsen/logrus)
|
|
||||||
|
|
||||||
Logrus is a structured logger for Go (golang), completely API compatible with
|
|
||||||
the standard library logger. [Godoc][godoc]. **Please note the Logrus API is not
|
|
||||||
yet stable (pre 1.0). Logrus itself is completely stable and has been used in
|
|
||||||
many large deployments. The core API is unlikely to change much but please
|
|
||||||
version control your Logrus to make sure you aren't fetching latest `master` on
|
|
||||||
every build.**
|
|
||||||
|
|
||||||
**Seeing weird case-sensitive problems?** Unfortunately, the author failed to
|
|
||||||
realize the consequences of renaming to lower-case. Due to the Go package
|
|
||||||
environment, this caused issues. Regretfully, there's no turning back now.
|
|
||||||
Everything using `logrus` will need to use the lower-case:
|
|
||||||
`github.com/sirupsen/logrus`. Any package that isn't, should be changed.
|
|
||||||
|
|
||||||
I am terribly sorry for this inconvenience. Logrus strives hard for backwards
|
|
||||||
compatibility, and the author failed to realize the cascading consequences of
|
|
||||||
such a name-change. To fix Glide, see [these
|
|
||||||
comments](https://github.com/sirupsen/logrus/issues/553#issuecomment-306591437).
|
|
||||||
|
|
||||||
Nicely color-coded in development (when a TTY is attached, otherwise just
|
|
||||||
plain text):
|
|
||||||
|
|
||||||
![Colored](http://i.imgur.com/PY7qMwd.png)
|
|
||||||
|
|
||||||
With `log.SetFormatter(&log.JSONFormatter{})`, for easy parsing by logstash
|
|
||||||
or Splunk:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{"animal":"walrus","level":"info","msg":"A group of walrus emerges from the
|
|
||||||
ocean","size":10,"time":"2014-03-10 19:57:38.562264131 -0400 EDT"}
|
|
||||||
|
|
||||||
{"level":"warning","msg":"The group's number increased tremendously!",
|
|
||||||
"number":122,"omg":true,"time":"2014-03-10 19:57:38.562471297 -0400 EDT"}
|
|
||||||
|
|
||||||
{"animal":"walrus","level":"info","msg":"A giant walrus appears!",
|
|
||||||
"size":10,"time":"2014-03-10 19:57:38.562500591 -0400 EDT"}
|
|
||||||
|
|
||||||
{"animal":"walrus","level":"info","msg":"Tremendously sized cow enters the ocean.",
|
|
||||||
"size":9,"time":"2014-03-10 19:57:38.562527896 -0400 EDT"}
|
|
||||||
|
|
||||||
{"level":"fatal","msg":"The ice breaks!","number":100,"omg":true,
|
|
||||||
"time":"2014-03-10 19:57:38.562543128 -0400 EDT"}
|
|
||||||
```
|
|
||||||
|
|
||||||
With the default `log.SetFormatter(&log.TextFormatter{})` when a TTY is not
|
|
||||||
attached, the output is compatible with the
|
|
||||||
[logfmt](http://godoc.org/github.com/kr/logfmt) format:
|
|
||||||
|
|
||||||
```text
|
|
||||||
time="2015-03-26T01:27:38-04:00" level=debug msg="Started observing beach" animal=walrus number=8
|
|
||||||
time="2015-03-26T01:27:38-04:00" level=info msg="A group of walrus emerges from the ocean" animal=walrus size=10
|
|
||||||
time="2015-03-26T01:27:38-04:00" level=warning msg="The group's number increased tremendously!" number=122 omg=true
|
|
||||||
time="2015-03-26T01:27:38-04:00" level=debug msg="Temperature changes" temperature=-4
|
|
||||||
time="2015-03-26T01:27:38-04:00" level=panic msg="It's over 9000!" animal=orca size=9009
|
|
||||||
time="2015-03-26T01:27:38-04:00" level=fatal msg="The ice breaks!" err=&{0x2082280c0 map[animal:orca size:9009] 2015-03-26 01:27:38.441574009 -0400 EDT panic It's over 9000!} number=100 omg=true
|
|
||||||
exit status 1
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Case-sensitivity
|
|
||||||
|
|
||||||
The organization's name was changed to lower-case--and this will not be changed
|
|
||||||
back. If you are getting import conflicts due to case sensitivity, please use
|
|
||||||
the lower-case import: `github.com/sirupsen/logrus`.
|
|
||||||
|
|
||||||
#### Example
|
|
||||||
|
|
||||||
The simplest way to use Logrus is simply the package-level exported logger:
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
log.WithFields(log.Fields{
|
|
||||||
"animal": "walrus",
|
|
||||||
}).Info("A walrus appears")
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Note that it's completely api-compatible with the stdlib logger, so you can
|
|
||||||
replace your `log` imports everywhere with `log "github.com/sirupsen/logrus"`
|
|
||||||
and you'll now have the flexibility of Logrus. You can customize it all you
|
|
||||||
want:
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
// Log as JSON instead of the default ASCII formatter.
|
|
||||||
log.SetFormatter(&log.JSONFormatter{})
|
|
||||||
|
|
||||||
// Output to stdout instead of the default stderr
|
|
||||||
// Can be any io.Writer, see below for File example
|
|
||||||
log.SetOutput(os.Stdout)
|
|
||||||
|
|
||||||
// Only log the warning severity or above.
|
|
||||||
log.SetLevel(log.WarnLevel)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
log.WithFields(log.Fields{
|
|
||||||
"animal": "walrus",
|
|
||||||
"size": 10,
|
|
||||||
}).Info("A group of walrus emerges from the ocean")
|
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
|
||||||
"omg": true,
|
|
||||||
"number": 122,
|
|
||||||
}).Warn("The group's number increased tremendously!")
|
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
|
||||||
"omg": true,
|
|
||||||
"number": 100,
|
|
||||||
}).Fatal("The ice breaks!")
|
|
||||||
|
|
||||||
// A common pattern is to re-use fields between logging statements by re-using
|
|
||||||
// the logrus.Entry returned from WithFields()
|
|
||||||
contextLogger := log.WithFields(log.Fields{
|
|
||||||
"common": "this is a common field",
|
|
||||||
"other": "I also should be logged always",
|
|
||||||
})
|
|
||||||
|
|
||||||
contextLogger.Info("I'll be logged with common and other field")
|
|
||||||
contextLogger.Info("Me too")
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
For more advanced usage such as logging to multiple locations from the same
|
|
||||||
application, you can also create an instance of the `logrus` Logger:
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Create a new instance of the logger. You can have any number of instances.
|
|
||||||
var log = logrus.New()
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// The API for setting attributes is a little different than the package level
|
|
||||||
// exported logger. See Godoc.
|
|
||||||
log.Out = os.Stdout
|
|
||||||
|
|
||||||
// You could set this to any `io.Writer` such as a file
|
|
||||||
// file, err := os.OpenFile("logrus.log", os.O_CREATE|os.O_WRONLY, 0666)
|
|
||||||
// if err == nil {
|
|
||||||
// log.Out = file
|
|
||||||
// } else {
|
|
||||||
// log.Info("Failed to log to file, using default stderr")
|
|
||||||
// }
|
|
||||||
|
|
||||||
log.WithFields(logrus.Fields{
|
|
||||||
"animal": "walrus",
|
|
||||||
"size": 10,
|
|
||||||
}).Info("A group of walrus emerges from the ocean")
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Fields
|
|
||||||
|
|
||||||
Logrus encourages careful, structured logging through logging fields instead of
|
|
||||||
long, unparseable error messages. For example, instead of: `log.Fatalf("Failed
|
|
||||||
to send event %s to topic %s with key %d")`, you should log the much more
|
|
||||||
discoverable:
|
|
||||||
|
|
||||||
```go
|
|
||||||
log.WithFields(log.Fields{
|
|
||||||
"event": event,
|
|
||||||
"topic": topic,
|
|
||||||
"key": key,
|
|
||||||
}).Fatal("Failed to send event")
|
|
||||||
```
|
|
||||||
|
|
||||||
We've found this API forces you to think about logging in a way that produces
|
|
||||||
much more useful logging messages. We've been in countless situations where just
|
|
||||||
a single added field to a log statement that was already there would've saved us
|
|
||||||
hours. The `WithFields` call is optional.
|
|
||||||
|
|
||||||
In general, with Logrus using any of the `printf`-family functions should be
|
|
||||||
seen as a hint you should add a field, however, you can still use the
|
|
||||||
`printf`-family functions with Logrus.
|
|
||||||
|
|
||||||
#### Default Fields
|
|
||||||
|
|
||||||
Often it's helpful to have fields _always_ attached to log statements in an
|
|
||||||
application or parts of one. For example, you may want to always log the
|
|
||||||
`request_id` and `user_ip` in the context of a request. Instead of writing
|
|
||||||
`log.WithFields(log.Fields{"request_id": request_id, "user_ip": user_ip})` on
|
|
||||||
every line, you can create a `logrus.Entry` to pass around instead:
|
|
||||||
|
|
||||||
```go
|
|
||||||
requestLogger := log.WithFields(log.Fields{"request_id": request_id, "user_ip": user_ip})
|
|
||||||
requestLogger.Info("something happened on that request") # will log request_id and user_ip
|
|
||||||
requestLogger.Warn("something not great happened")
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Hooks
|
|
||||||
|
|
||||||
You can add hooks for logging levels. For example to send errors to an exception
|
|
||||||
tracking service on `Error`, `Fatal` and `Panic`, info to StatsD or log to
|
|
||||||
multiple places simultaneously, e.g. syslog.
|
|
||||||
|
|
||||||
Logrus comes with [built-in hooks](hooks/). Add those, or your custom hook, in
|
|
||||||
`init`:
|
|
||||||
|
|
||||||
```go
|
|
||||||
import (
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"gopkg.in/gemnasium/logrus-airbrake-hook.v2" // the package is named "aibrake"
|
|
||||||
logrus_syslog "github.com/sirupsen/logrus/hooks/syslog"
|
|
||||||
"log/syslog"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
|
|
||||||
// Use the Airbrake hook to report errors that have Error severity or above to
|
|
||||||
// an exception tracker. You can create custom hooks, see the Hooks section.
|
|
||||||
log.AddHook(airbrake.NewHook(123, "xyz", "production"))
|
|
||||||
|
|
||||||
hook, err := logrus_syslog.NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "")
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Unable to connect to local syslog daemon")
|
|
||||||
} else {
|
|
||||||
log.AddHook(hook)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
Note: Syslog hook also support connecting to local syslog (Ex. "/dev/log" or "/var/run/syslog" or "/var/run/log"). For the detail, please check the [syslog hook README](hooks/syslog/README.md).
|
|
||||||
|
|
||||||
| Hook | Description |
|
|
||||||
| ----- | ----------- |
|
|
||||||
| [Airbrake "legacy"](https://github.com/gemnasium/logrus-airbrake-legacy-hook) | Send errors to an exception tracking service compatible with the Airbrake API V2. Uses [`airbrake-go`](https://github.com/tobi/airbrake-go) behind the scenes. |
|
|
||||||
| [Airbrake](https://github.com/gemnasium/logrus-airbrake-hook) | Send errors to the Airbrake API V3. Uses the official [`gobrake`](https://github.com/airbrake/gobrake) behind the scenes. |
|
|
||||||
| [Amazon Kinesis](https://github.com/evalphobia/logrus_kinesis) | Hook for logging to [Amazon Kinesis](https://aws.amazon.com/kinesis/) |
|
|
||||||
| [Amqp-Hook](https://github.com/vladoatanasov/logrus_amqp) | Hook for logging to Amqp broker (Like RabbitMQ) |
|
|
||||||
| [Bugsnag](https://github.com/Shopify/logrus-bugsnag/blob/master/bugsnag.go) | Send errors to the Bugsnag exception tracking service. |
|
|
||||||
| [DeferPanic](https://github.com/deferpanic/dp-logrus) | Hook for logging to DeferPanic |
|
|
||||||
| [Discordrus](https://github.com/kz/discordrus) | Hook for logging to [Discord](https://discordapp.com/) |
|
|
||||||
| [ElasticSearch](https://github.com/sohlich/elogrus) | Hook for logging to ElasticSearch|
|
|
||||||
| [Firehose](https://github.com/beaubrewer/logrus_firehose) | Hook for logging to [Amazon Firehose](https://aws.amazon.com/kinesis/firehose/)
|
|
||||||
| [Fluentd](https://github.com/evalphobia/logrus_fluent) | Hook for logging to fluentd |
|
|
||||||
| [Go-Slack](https://github.com/multiplay/go-slack) | Hook for logging to [Slack](https://slack.com) |
|
|
||||||
| [Graylog](https://github.com/gemnasium/logrus-graylog-hook) | Hook for logging to [Graylog](http://graylog2.org/) |
|
|
||||||
| [Hiprus](https://github.com/nubo/hiprus) | Send errors to a channel in hipchat. |
|
|
||||||
| [Honeybadger](https://github.com/agonzalezro/logrus_honeybadger) | Hook for sending exceptions to Honeybadger |
|
|
||||||
| [InfluxDB](https://github.com/Abramovic/logrus_influxdb) | Hook for logging to influxdb |
|
|
||||||
| [Influxus](http://github.com/vlad-doru/influxus) | Hook for concurrently logging to [InfluxDB](http://influxdata.com/) |
|
|
||||||
| [Journalhook](https://github.com/wercker/journalhook) | Hook for logging to `systemd-journald` |
|
|
||||||
| [KafkaLogrus](https://github.com/goibibo/KafkaLogrus) | Hook for logging to kafka |
|
|
||||||
| [LFShook](https://github.com/rifflock/lfshook) | Hook for logging to the local filesystem |
|
|
||||||
| [Logentries](https://github.com/jcftang/logentriesrus) | Hook for logging to [Logentries](https://logentries.com/) |
|
|
||||||
| [Logentrus](https://github.com/puddingfactory/logentrus) | Hook for logging to [Logentries](https://logentries.com/) |
|
|
||||||
| [Logmatic.io](https://github.com/logmatic/logmatic-go) | Hook for logging to [Logmatic.io](http://logmatic.io/) |
|
|
||||||
| [Logrusly](https://github.com/sebest/logrusly) | Send logs to [Loggly](https://www.loggly.com/) |
|
|
||||||
| [Logstash](https://github.com/bshuster-repo/logrus-logstash-hook) | Hook for logging to [Logstash](https://www.elastic.co/products/logstash) |
|
|
||||||
| [Mail](https://github.com/zbindenren/logrus_mail) | Hook for sending exceptions via mail |
|
|
||||||
| [Mongodb](https://github.com/weekface/mgorus) | Hook for logging to mongodb |
|
|
||||||
| [NATS-Hook](https://github.com/rybit/nats_logrus_hook) | Hook for logging to [NATS](https://nats.io) |
|
|
||||||
| [Octokit](https://github.com/dorajistyle/logrus-octokit-hook) | Hook for logging to github via octokit |
|
|
||||||
| [Papertrail](https://github.com/polds/logrus-papertrail-hook) | Send errors to the [Papertrail](https://papertrailapp.com) hosted logging service via UDP. |
|
|
||||||
| [PostgreSQL](https://github.com/gemnasium/logrus-postgresql-hook) | Send logs to [PostgreSQL](http://postgresql.org) |
|
|
||||||
| [Pushover](https://github.com/toorop/logrus_pushover) | Send error via [Pushover](https://pushover.net) |
|
|
||||||
| [Raygun](https://github.com/squirkle/logrus-raygun-hook) | Hook for logging to [Raygun.io](http://raygun.io/) |
|
|
||||||
| [Redis-Hook](https://github.com/rogierlommers/logrus-redis-hook) | Hook for logging to a ELK stack (through Redis) |
|
|
||||||
| [Rollrus](https://github.com/heroku/rollrus) | Hook for sending errors to rollbar |
|
|
||||||
| [Scribe](https://github.com/sagar8192/logrus-scribe-hook) | Hook for logging to [Scribe](https://github.com/facebookarchive/scribe)|
|
|
||||||
| [Sentry](https://github.com/evalphobia/logrus_sentry) | Send errors to the Sentry error logging and aggregation service. |
|
|
||||||
| [Slackrus](https://github.com/johntdyer/slackrus) | Hook for Slack chat. |
|
|
||||||
| [Stackdriver](https://github.com/knq/sdhook) | Hook for logging to [Google Stackdriver](https://cloud.google.com/logging/) |
|
|
||||||
| [Sumorus](https://github.com/doublefree/sumorus) | Hook for logging to [SumoLogic](https://www.sumologic.com/)|
|
|
||||||
| [Syslog](https://github.com/Sirupsen/logrus/blob/master/hooks/syslog/syslog.go) | Send errors to remote syslog server. Uses standard library `log/syslog` behind the scenes. |
|
|
||||||
| [Syslog TLS](https://github.com/shinji62/logrus-syslog-ng) | Send errors to remote syslog server with TLS support. |
|
|
||||||
| [TraceView](https://github.com/evalphobia/logrus_appneta) | Hook for logging to [AppNeta TraceView](https://www.appneta.com/products/traceview/) |
|
|
||||||
| [Typetalk](https://github.com/dragon3/logrus-typetalk-hook) | Hook for logging to [Typetalk](https://www.typetalk.in/) |
|
|
||||||
| [logz.io](https://github.com/ripcurld00d/logrus-logzio-hook) | Hook for logging to [logz.io](https://logz.io), a Log as a Service using Logstash |
|
|
||||||
| [SQS-Hook](https://github.com/tsarpaul/logrus_sqs) | Hook for logging to [Amazon Simple Queue Service (SQS)](https://aws.amazon.com/sqs/) |
|
|
||||||
|
|
||||||
#### Level logging
|
|
||||||
|
|
||||||
Logrus has six logging levels: Debug, Info, Warning, Error, Fatal and Panic.
|
|
||||||
|
|
||||||
```go
|
|
||||||
log.Debug("Useful debugging information.")
|
|
||||||
log.Info("Something noteworthy happened!")
|
|
||||||
log.Warn("You should probably take a look at this.")
|
|
||||||
log.Error("Something failed but I'm not quitting.")
|
|
||||||
// Calls os.Exit(1) after logging
|
|
||||||
log.Fatal("Bye.")
|
|
||||||
// Calls panic() after logging
|
|
||||||
log.Panic("I'm bailing.")
|
|
||||||
```
|
|
||||||
|
|
||||||
You can set the logging level on a `Logger`, then it will only log entries with
|
|
||||||
that severity or anything above it:
|
|
||||||
|
|
||||||
```go
|
|
||||||
// Will log anything that is info or above (warn, error, fatal, panic). Default.
|
|
||||||
log.SetLevel(log.InfoLevel)
|
|
||||||
```
|
|
||||||
|
|
||||||
It may be useful to set `log.Level = logrus.DebugLevel` in a debug or verbose
|
|
||||||
environment if your application has that.
|
|
||||||
|
|
||||||
#### Entries
|
|
||||||
|
|
||||||
Besides the fields added with `WithField` or `WithFields` some fields are
|
|
||||||
automatically added to all logging events:
|
|
||||||
|
|
||||||
1. `time`. The timestamp when the entry was created.
|
|
||||||
2. `msg`. The logging message passed to `{Info,Warn,Error,Fatal,Panic}` after
|
|
||||||
the `AddFields` call. E.g. `Failed to send event.`
|
|
||||||
3. `level`. The logging level. E.g. `info`.
|
|
||||||
|
|
||||||
#### Environments
|
|
||||||
|
|
||||||
Logrus has no notion of environment.
|
|
||||||
|
|
||||||
If you wish for hooks and formatters to only be used in specific environments,
|
|
||||||
you should handle that yourself. For example, if your application has a global
|
|
||||||
variable `Environment`, which is a string representation of the environment you
|
|
||||||
could do:
|
|
||||||
|
|
||||||
```go
|
|
||||||
import (
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
init() {
|
|
||||||
// do something here to set environment depending on an environment variable
|
|
||||||
// or command-line flag
|
|
||||||
if Environment == "production" {
|
|
||||||
log.SetFormatter(&log.JSONFormatter{})
|
|
||||||
} else {
|
|
||||||
// The TextFormatter is default, you don't actually have to do this.
|
|
||||||
log.SetFormatter(&log.TextFormatter{})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
This configuration is how `logrus` was intended to be used, but JSON in
|
|
||||||
production is mostly only useful if you do log aggregation with tools like
|
|
||||||
Splunk or Logstash.
|
|
||||||
|
|
||||||
#### Formatters
|
|
||||||
|
|
||||||
The built-in logging formatters are:
|
|
||||||
|
|
||||||
* `logrus.TextFormatter`. Logs the event in colors if stdout is a tty, otherwise
|
|
||||||
without colors.
|
|
||||||
* *Note:* to force colored output when there is no TTY, set the `ForceColors`
|
|
||||||
field to `true`. To force no colored output even if there is a TTY set the
|
|
||||||
`DisableColors` field to `true`. For Windows, see
|
|
||||||
[github.com/mattn/go-colorable](https://github.com/mattn/go-colorable).
|
|
||||||
* All options are listed in the [generated docs](https://godoc.org/github.com/sirupsen/logrus#TextFormatter).
|
|
||||||
* `logrus.JSONFormatter`. Logs fields as JSON.
|
|
||||||
* All options are listed in the [generated docs](https://godoc.org/github.com/sirupsen/logrus#JSONFormatter).
|
|
||||||
|
|
||||||
Third party logging formatters:
|
|
||||||
|
|
||||||
* [`logstash`](https://github.com/bshuster-repo/logrus-logstash-hook). Logs fields as [Logstash](http://logstash.net) Events.
|
|
||||||
* [`prefixed`](https://github.com/x-cray/logrus-prefixed-formatter). Displays log entry source along with alternative layout.
|
|
||||||
* [`zalgo`](https://github.com/aybabtme/logzalgo). Invoking the P͉̫o̳̼̊w̖͈̰͎e̬͔̭͂r͚̼̹̲ ̫͓͉̳͈ō̠͕͖̚f̝͍̠ ͕̲̞͖͑Z̖̫̤̫ͪa͉̬͈̗l͖͎g̳̥o̰̥̅!̣͔̲̻͊̄ ̙̘̦̹̦.
|
|
||||||
|
|
||||||
You can define your formatter by implementing the `Formatter` interface,
|
|
||||||
requiring a `Format` method. `Format` takes an `*Entry`. `entry.Data` is a
|
|
||||||
`Fields` type (`map[string]interface{}`) with all your fields as well as the
|
|
||||||
default ones (see Entries section above):
|
|
||||||
|
|
||||||
```go
|
|
||||||
type MyJSONFormatter struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
log.SetFormatter(new(MyJSONFormatter))
|
|
||||||
|
|
||||||
func (f *MyJSONFormatter) Format(entry *Entry) ([]byte, error) {
|
|
||||||
// Note this doesn't include Time, Level and Message which are available on
|
|
||||||
// the Entry. Consult `godoc` on information about those fields or read the
|
|
||||||
// source of the official loggers.
|
|
||||||
serialized, err := json.Marshal(entry.Data)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err)
|
|
||||||
}
|
|
||||||
return append(serialized, '\n'), nil
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Logger as an `io.Writer`
|
|
||||||
|
|
||||||
Logrus can be transformed into an `io.Writer`. That writer is the end of an `io.Pipe` and it is your responsibility to close it.
|
|
||||||
|
|
||||||
```go
|
|
||||||
w := logger.Writer()
|
|
||||||
defer w.Close()
|
|
||||||
|
|
||||||
srv := http.Server{
|
|
||||||
// create a stdlib log.Logger that writes to
|
|
||||||
// logrus.Logger.
|
|
||||||
ErrorLog: log.New(w, "", 0),
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Each line written to that writer will be printed the usual way, using formatters
|
|
||||||
and hooks. The level for those entries is `info`.
|
|
||||||
|
|
||||||
This means that we can override the standard library logger easily:
|
|
||||||
|
|
||||||
```go
|
|
||||||
logger := logrus.New()
|
|
||||||
logger.Formatter = &logrus.JSONFormatter{}
|
|
||||||
|
|
||||||
// Use logrus for standard log output
|
|
||||||
// Note that `log` here references stdlib's log
|
|
||||||
// Not logrus imported under the name `log`.
|
|
||||||
log.SetOutput(logger.Writer())
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Rotation
|
|
||||||
|
|
||||||
Log rotation is not provided with Logrus. Log rotation should be done by an
|
|
||||||
external program (like `logrotate(8)`) that can compress and delete old log
|
|
||||||
entries. It should not be a feature of the application-level logger.
|
|
||||||
|
|
||||||
#### Tools
|
|
||||||
|
|
||||||
| Tool | Description |
|
|
||||||
| ---- | ----------- |
|
|
||||||
|[Logrus Mate](https://github.com/gogap/logrus_mate)|Logrus mate is a tool for Logrus to manage loggers, you can initial logger's level, hook and formatter by config file, the logger will generated with different config at different environment.|
|
|
||||||
|[Logrus Viper Helper](https://github.com/heirko/go-contrib/tree/master/logrusHelper)|An Helper around Logrus to wrap with spf13/Viper to load configuration with fangs! And to simplify Logrus configuration use some behavior of [Logrus Mate](https://github.com/gogap/logrus_mate). [sample](https://github.com/heirko/iris-contrib/blob/master/middleware/logrus-logger/example) |
|
|
||||||
|
|
||||||
#### Testing
|
|
||||||
|
|
||||||
Logrus has a built in facility for asserting the presence of log messages. This is implemented through the `test` hook and provides:
|
|
||||||
|
|
||||||
* decorators for existing logger (`test.NewLocal` and `test.NewGlobal`) which basically just add the `test` hook
|
|
||||||
* a test logger (`test.NewNullLogger`) that just records log messages (and does not output any):
|
|
||||||
|
|
||||||
```go
|
|
||||||
import(
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/sirupsen/logrus/hooks/null"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestSomething(t*testing.T){
|
|
||||||
logger, hook := null.NewNullLogger()
|
|
||||||
logger.Error("Helloerror")
|
|
||||||
|
|
||||||
assert.Equal(t, 1, len(hook.Entries))
|
|
||||||
assert.Equal(t, logrus.ErrorLevel, hook.LastEntry().Level)
|
|
||||||
assert.Equal(t, "Helloerror", hook.LastEntry().Message)
|
|
||||||
|
|
||||||
hook.Reset()
|
|
||||||
assert.Nil(t, hook.LastEntry())
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Fatal handlers
|
|
||||||
|
|
||||||
Logrus can register one or more functions that will be called when any `fatal`
|
|
||||||
level message is logged. The registered handlers will be executed before
|
|
||||||
logrus performs a `os.Exit(1)`. This behavior may be helpful if callers need
|
|
||||||
to gracefully shutdown. Unlike a `panic("Something went wrong...")` call which can be intercepted with a deferred `recover` a call to `os.Exit(1)` can not be intercepted.
|
|
||||||
|
|
||||||
```
|
|
||||||
...
|
|
||||||
handler := func() {
|
|
||||||
// gracefully shutdown something...
|
|
||||||
}
|
|
||||||
logrus.RegisterExitHandler(handler)
|
|
||||||
...
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Thread safety
|
|
||||||
|
|
||||||
By default Logger is protected by mutex for concurrent writes, this mutex is invoked when calling hooks and writing logs.
|
|
||||||
If you are sure such locking is not needed, you can call logger.SetNoLock() to disable the locking.
|
|
||||||
|
|
||||||
Situation when locking is not needed includes:
|
|
||||||
|
|
||||||
* You have no hooks registered, or hooks calling is already thread-safe.
|
|
||||||
|
|
||||||
* Writing to logger.Out is already thread-safe, for example:
|
|
||||||
|
|
||||||
1) logger.Out is protected by locks.
|
|
||||||
|
|
||||||
2) logger.Out is a os.File handler opened with `O_APPEND` flag, and every write is smaller than 4k. (This allow multi-thread/multi-process writing)
|
|
||||||
|
|
||||||
(Refer to http://www.notthewizard.com/2014/06/17/are-files-appends-really-atomic/)
|
|
64
vendor/github.com/sirupsen/logrus/alt_exit.go
generated
vendored
64
vendor/github.com/sirupsen/logrus/alt_exit.go
generated
vendored
|
@ -1,64 +0,0 @@
|
||||||
package logrus
|
|
||||||
|
|
||||||
// The following code was sourced and modified from the
|
|
||||||
// https://github.com/tebeka/atexit package governed by the following license:
|
|
||||||
//
|
|
||||||
// Copyright (c) 2012 Miki Tebeka <miki.tebeka@gmail.com>.
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
// this software and associated documentation files (the "Software"), to deal in
|
|
||||||
// the Software without restriction, including without limitation the rights to
|
|
||||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
||||||
// the Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
// subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
|
||||||
// copies or substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
||||||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
var handlers = []func(){}
|
|
||||||
|
|
||||||
func runHandler(handler func()) {
|
|
||||||
defer func() {
|
|
||||||
if err := recover(); err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, "Error: Logrus exit handler error:", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
handler()
|
|
||||||
}
|
|
||||||
|
|
||||||
func runHandlers() {
|
|
||||||
for _, handler := range handlers {
|
|
||||||
runHandler(handler)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exit runs all the Logrus atexit handlers and then terminates the program using os.Exit(code)
|
|
||||||
func Exit(code int) {
|
|
||||||
runHandlers()
|
|
||||||
os.Exit(code)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RegisterExitHandler adds a Logrus Exit handler, call logrus.Exit to invoke
|
|
||||||
// all handlers. The handlers will also be invoked when any Fatal log entry is
|
|
||||||
// made.
|
|
||||||
//
|
|
||||||
// This method is useful when a caller wishes to use logrus to log a fatal
|
|
||||||
// message but also needs to gracefully shutdown. An example usecase could be
|
|
||||||
// closing database connections, or sending a alert that the application is
|
|
||||||
// closing.
|
|
||||||
func RegisterExitHandler(handler func()) {
|
|
||||||
handlers = append(handlers, handler)
|
|
||||||
}
|
|
26
vendor/github.com/sirupsen/logrus/doc.go
generated
vendored
26
vendor/github.com/sirupsen/logrus/doc.go
generated
vendored
|
@ -1,26 +0,0 @@
|
||||||
/*
|
|
||||||
Package logrus is a structured logger for Go, completely API compatible with the standard library logger.
|
|
||||||
|
|
||||||
|
|
||||||
The simplest way to use Logrus is simply the package-level exported logger:
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
log.WithFields(log.Fields{
|
|
||||||
"animal": "walrus",
|
|
||||||
"number": 1,
|
|
||||||
"size": 10,
|
|
||||||
}).Info("A walrus appears")
|
|
||||||
}
|
|
||||||
|
|
||||||
Output:
|
|
||||||
time="2015-09-07T08:48:33Z" level=info msg="A walrus appears" animal=walrus number=1 size=10
|
|
||||||
|
|
||||||
For a full guide visit https://github.com/sirupsen/logrus
|
|
||||||
*/
|
|
||||||
package logrus
|
|
275
vendor/github.com/sirupsen/logrus/entry.go
generated
vendored
275
vendor/github.com/sirupsen/logrus/entry.go
generated
vendored
|
@ -1,275 +0,0 @@
|
||||||
package logrus
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var bufferPool *sync.Pool
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
bufferPool = &sync.Pool{
|
|
||||||
New: func() interface{} {
|
|
||||||
return new(bytes.Buffer)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Defines the key when adding errors using WithError.
|
|
||||||
var ErrorKey = "error"
|
|
||||||
|
|
||||||
// An entry is the final or intermediate Logrus logging entry. It contains all
|
|
||||||
// the fields passed with WithField{,s}. It's finally logged when Debug, Info,
|
|
||||||
// Warn, Error, Fatal or Panic is called on it. These objects can be reused and
|
|
||||||
// passed around as much as you wish to avoid field duplication.
|
|
||||||
type Entry struct {
|
|
||||||
Logger *Logger
|
|
||||||
|
|
||||||
// Contains all the fields set by the user.
|
|
||||||
Data Fields
|
|
||||||
|
|
||||||
// Time at which the log entry was created
|
|
||||||
Time time.Time
|
|
||||||
|
|
||||||
// Level the log entry was logged at: Debug, Info, Warn, Error, Fatal or Panic
|
|
||||||
Level Level
|
|
||||||
|
|
||||||
// Message passed to Debug, Info, Warn, Error, Fatal or Panic
|
|
||||||
Message string
|
|
||||||
|
|
||||||
// When formatter is called in entry.log(), an Buffer may be set to entry
|
|
||||||
Buffer *bytes.Buffer
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewEntry(logger *Logger) *Entry {
|
|
||||||
return &Entry{
|
|
||||||
Logger: logger,
|
|
||||||
// Default is three fields, give a little extra room
|
|
||||||
Data: make(Fields, 5),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the string representation from the reader and ultimately the
|
|
||||||
// formatter.
|
|
||||||
func (entry *Entry) String() (string, error) {
|
|
||||||
serialized, err := entry.Logger.Formatter.Format(entry)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
str := string(serialized)
|
|
||||||
return str, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add an error as single field (using the key defined in ErrorKey) to the Entry.
|
|
||||||
func (entry *Entry) WithError(err error) *Entry {
|
|
||||||
return entry.WithField(ErrorKey, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add a single field to the Entry.
|
|
||||||
func (entry *Entry) WithField(key string, value interface{}) *Entry {
|
|
||||||
return entry.WithFields(Fields{key: value})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add a map of fields to the Entry.
|
|
||||||
func (entry *Entry) WithFields(fields Fields) *Entry {
|
|
||||||
data := make(Fields, len(entry.Data)+len(fields))
|
|
||||||
for k, v := range entry.Data {
|
|
||||||
data[k] = v
|
|
||||||
}
|
|
||||||
for k, v := range fields {
|
|
||||||
data[k] = v
|
|
||||||
}
|
|
||||||
return &Entry{Logger: entry.Logger, Data: data}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This function is not declared with a pointer value because otherwise
|
|
||||||
// race conditions will occur when using multiple goroutines
|
|
||||||
func (entry Entry) log(level Level, msg string) {
|
|
||||||
var buffer *bytes.Buffer
|
|
||||||
entry.Time = time.Now()
|
|
||||||
entry.Level = level
|
|
||||||
entry.Message = msg
|
|
||||||
|
|
||||||
if err := entry.Logger.Hooks.Fire(level, &entry); err != nil {
|
|
||||||
entry.Logger.mu.Lock()
|
|
||||||
fmt.Fprintf(os.Stderr, "Failed to fire hook: %v\n", err)
|
|
||||||
entry.Logger.mu.Unlock()
|
|
||||||
}
|
|
||||||
buffer = bufferPool.Get().(*bytes.Buffer)
|
|
||||||
buffer.Reset()
|
|
||||||
defer bufferPool.Put(buffer)
|
|
||||||
entry.Buffer = buffer
|
|
||||||
serialized, err := entry.Logger.Formatter.Format(&entry)
|
|
||||||
entry.Buffer = nil
|
|
||||||
if err != nil {
|
|
||||||
entry.Logger.mu.Lock()
|
|
||||||
fmt.Fprintf(os.Stderr, "Failed to obtain reader, %v\n", err)
|
|
||||||
entry.Logger.mu.Unlock()
|
|
||||||
} else {
|
|
||||||
entry.Logger.mu.Lock()
|
|
||||||
_, err = entry.Logger.Out.Write(serialized)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err)
|
|
||||||
}
|
|
||||||
entry.Logger.mu.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
// To avoid Entry#log() returning a value that only would make sense for
|
|
||||||
// panic() to use in Entry#Panic(), we avoid the allocation by checking
|
|
||||||
// directly here.
|
|
||||||
if level <= PanicLevel {
|
|
||||||
panic(&entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Debug(args ...interface{}) {
|
|
||||||
if entry.Logger.level() >= DebugLevel {
|
|
||||||
entry.log(DebugLevel, fmt.Sprint(args...))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Print(args ...interface{}) {
|
|
||||||
entry.Info(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Info(args ...interface{}) {
|
|
||||||
if entry.Logger.level() >= InfoLevel {
|
|
||||||
entry.log(InfoLevel, fmt.Sprint(args...))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Warn(args ...interface{}) {
|
|
||||||
if entry.Logger.level() >= WarnLevel {
|
|
||||||
entry.log(WarnLevel, fmt.Sprint(args...))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Warning(args ...interface{}) {
|
|
||||||
entry.Warn(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Error(args ...interface{}) {
|
|
||||||
if entry.Logger.level() >= ErrorLevel {
|
|
||||||
entry.log(ErrorLevel, fmt.Sprint(args...))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Fatal(args ...interface{}) {
|
|
||||||
if entry.Logger.level() >= FatalLevel {
|
|
||||||
entry.log(FatalLevel, fmt.Sprint(args...))
|
|
||||||
}
|
|
||||||
Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Panic(args ...interface{}) {
|
|
||||||
if entry.Logger.level() >= PanicLevel {
|
|
||||||
entry.log(PanicLevel, fmt.Sprint(args...))
|
|
||||||
}
|
|
||||||
panic(fmt.Sprint(args...))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Entry Printf family functions
|
|
||||||
|
|
||||||
func (entry *Entry) Debugf(format string, args ...interface{}) {
|
|
||||||
if entry.Logger.level() >= DebugLevel {
|
|
||||||
entry.Debug(fmt.Sprintf(format, args...))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Infof(format string, args ...interface{}) {
|
|
||||||
if entry.Logger.level() >= InfoLevel {
|
|
||||||
entry.Info(fmt.Sprintf(format, args...))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Printf(format string, args ...interface{}) {
|
|
||||||
entry.Infof(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Warnf(format string, args ...interface{}) {
|
|
||||||
if entry.Logger.level() >= WarnLevel {
|
|
||||||
entry.Warn(fmt.Sprintf(format, args...))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Warningf(format string, args ...interface{}) {
|
|
||||||
entry.Warnf(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Errorf(format string, args ...interface{}) {
|
|
||||||
if entry.Logger.level() >= ErrorLevel {
|
|
||||||
entry.Error(fmt.Sprintf(format, args...))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Fatalf(format string, args ...interface{}) {
|
|
||||||
if entry.Logger.level() >= FatalLevel {
|
|
||||||
entry.Fatal(fmt.Sprintf(format, args...))
|
|
||||||
}
|
|
||||||
Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Panicf(format string, args ...interface{}) {
|
|
||||||
if entry.Logger.level() >= PanicLevel {
|
|
||||||
entry.Panic(fmt.Sprintf(format, args...))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Entry Println family functions
|
|
||||||
|
|
||||||
func (entry *Entry) Debugln(args ...interface{}) {
|
|
||||||
if entry.Logger.level() >= DebugLevel {
|
|
||||||
entry.Debug(entry.sprintlnn(args...))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Infoln(args ...interface{}) {
|
|
||||||
if entry.Logger.level() >= InfoLevel {
|
|
||||||
entry.Info(entry.sprintlnn(args...))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Println(args ...interface{}) {
|
|
||||||
entry.Infoln(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Warnln(args ...interface{}) {
|
|
||||||
if entry.Logger.level() >= WarnLevel {
|
|
||||||
entry.Warn(entry.sprintlnn(args...))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Warningln(args ...interface{}) {
|
|
||||||
entry.Warnln(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Errorln(args ...interface{}) {
|
|
||||||
if entry.Logger.level() >= ErrorLevel {
|
|
||||||
entry.Error(entry.sprintlnn(args...))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Fatalln(args ...interface{}) {
|
|
||||||
if entry.Logger.level() >= FatalLevel {
|
|
||||||
entry.Fatal(entry.sprintlnn(args...))
|
|
||||||
}
|
|
||||||
Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Panicln(args ...interface{}) {
|
|
||||||
if entry.Logger.level() >= PanicLevel {
|
|
||||||
entry.Panic(entry.sprintlnn(args...))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sprintlnn => Sprint no newline. This is to get the behavior of how
|
|
||||||
// fmt.Sprintln where spaces are always added between operands, regardless of
|
|
||||||
// their type. Instead of vendoring the Sprintln implementation to spare a
|
|
||||||
// string allocation, we do the simplest thing.
|
|
||||||
func (entry *Entry) sprintlnn(args ...interface{}) string {
|
|
||||||
msg := fmt.Sprintln(args...)
|
|
||||||
return msg[:len(msg)-1]
|
|
||||||
}
|
|
193
vendor/github.com/sirupsen/logrus/exported.go
generated
vendored
193
vendor/github.com/sirupsen/logrus/exported.go
generated
vendored
|
@ -1,193 +0,0 @@
|
||||||
package logrus
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// std is the name of the standard logger in stdlib `log`
|
|
||||||
std = New()
|
|
||||||
)
|
|
||||||
|
|
||||||
func StandardLogger() *Logger {
|
|
||||||
return std
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetOutput sets the standard logger output.
|
|
||||||
func SetOutput(out io.Writer) {
|
|
||||||
std.mu.Lock()
|
|
||||||
defer std.mu.Unlock()
|
|
||||||
std.Out = out
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetFormatter sets the standard logger formatter.
|
|
||||||
func SetFormatter(formatter Formatter) {
|
|
||||||
std.mu.Lock()
|
|
||||||
defer std.mu.Unlock()
|
|
||||||
std.Formatter = formatter
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetLevel sets the standard logger level.
|
|
||||||
func SetLevel(level Level) {
|
|
||||||
std.mu.Lock()
|
|
||||||
defer std.mu.Unlock()
|
|
||||||
std.setLevel(level)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetLevel returns the standard logger level.
|
|
||||||
func GetLevel() Level {
|
|
||||||
std.mu.Lock()
|
|
||||||
defer std.mu.Unlock()
|
|
||||||
return std.level()
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddHook adds a hook to the standard logger hooks.
|
|
||||||
func AddHook(hook Hook) {
|
|
||||||
std.mu.Lock()
|
|
||||||
defer std.mu.Unlock()
|
|
||||||
std.Hooks.Add(hook)
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithError creates an entry from the standard logger and adds an error to it, using the value defined in ErrorKey as key.
|
|
||||||
func WithError(err error) *Entry {
|
|
||||||
return std.WithField(ErrorKey, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithField creates an entry from the standard logger and adds a field to
|
|
||||||
// it. If you want multiple fields, use `WithFields`.
|
|
||||||
//
|
|
||||||
// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
|
|
||||||
// or Panic on the Entry it returns.
|
|
||||||
func WithField(key string, value interface{}) *Entry {
|
|
||||||
return std.WithField(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithFields creates an entry from the standard logger and adds multiple
|
|
||||||
// fields to it. This is simply a helper for `WithField`, invoking it
|
|
||||||
// once for each field.
|
|
||||||
//
|
|
||||||
// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
|
|
||||||
// or Panic on the Entry it returns.
|
|
||||||
func WithFields(fields Fields) *Entry {
|
|
||||||
return std.WithFields(fields)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debug logs a message at level Debug on the standard logger.
|
|
||||||
func Debug(args ...interface{}) {
|
|
||||||
std.Debug(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print logs a message at level Info on the standard logger.
|
|
||||||
func Print(args ...interface{}) {
|
|
||||||
std.Print(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info logs a message at level Info on the standard logger.
|
|
||||||
func Info(args ...interface{}) {
|
|
||||||
std.Info(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warn logs a message at level Warn on the standard logger.
|
|
||||||
func Warn(args ...interface{}) {
|
|
||||||
std.Warn(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warning logs a message at level Warn on the standard logger.
|
|
||||||
func Warning(args ...interface{}) {
|
|
||||||
std.Warning(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error logs a message at level Error on the standard logger.
|
|
||||||
func Error(args ...interface{}) {
|
|
||||||
std.Error(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Panic logs a message at level Panic on the standard logger.
|
|
||||||
func Panic(args ...interface{}) {
|
|
||||||
std.Panic(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fatal logs a message at level Fatal on the standard logger.
|
|
||||||
func Fatal(args ...interface{}) {
|
|
||||||
std.Fatal(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debugf logs a message at level Debug on the standard logger.
|
|
||||||
func Debugf(format string, args ...interface{}) {
|
|
||||||
std.Debugf(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Printf logs a message at level Info on the standard logger.
|
|
||||||
func Printf(format string, args ...interface{}) {
|
|
||||||
std.Printf(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Infof logs a message at level Info on the standard logger.
|
|
||||||
func Infof(format string, args ...interface{}) {
|
|
||||||
std.Infof(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warnf logs a message at level Warn on the standard logger.
|
|
||||||
func Warnf(format string, args ...interface{}) {
|
|
||||||
std.Warnf(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warningf logs a message at level Warn on the standard logger.
|
|
||||||
func Warningf(format string, args ...interface{}) {
|
|
||||||
std.Warningf(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Errorf logs a message at level Error on the standard logger.
|
|
||||||
func Errorf(format string, args ...interface{}) {
|
|
||||||
std.Errorf(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Panicf logs a message at level Panic on the standard logger.
|
|
||||||
func Panicf(format string, args ...interface{}) {
|
|
||||||
std.Panicf(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fatalf logs a message at level Fatal on the standard logger.
|
|
||||||
func Fatalf(format string, args ...interface{}) {
|
|
||||||
std.Fatalf(format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debugln logs a message at level Debug on the standard logger.
|
|
||||||
func Debugln(args ...interface{}) {
|
|
||||||
std.Debugln(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Println logs a message at level Info on the standard logger.
|
|
||||||
func Println(args ...interface{}) {
|
|
||||||
std.Println(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Infoln logs a message at level Info on the standard logger.
|
|
||||||
func Infoln(args ...interface{}) {
|
|
||||||
std.Infoln(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warnln logs a message at level Warn on the standard logger.
|
|
||||||
func Warnln(args ...interface{}) {
|
|
||||||
std.Warnln(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warningln logs a message at level Warn on the standard logger.
|
|
||||||
func Warningln(args ...interface{}) {
|
|
||||||
std.Warningln(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Errorln logs a message at level Error on the standard logger.
|
|
||||||
func Errorln(args ...interface{}) {
|
|
||||||
std.Errorln(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Panicln logs a message at level Panic on the standard logger.
|
|
||||||
func Panicln(args ...interface{}) {
|
|
||||||
std.Panicln(args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fatalln logs a message at level Fatal on the standard logger.
|
|
||||||
func Fatalln(args ...interface{}) {
|
|
||||||
std.Fatalln(args...)
|
|
||||||
}
|
|
45
vendor/github.com/sirupsen/logrus/formatter.go
generated
vendored
45
vendor/github.com/sirupsen/logrus/formatter.go
generated
vendored
|
@ -1,45 +0,0 @@
|
||||||
package logrus
|
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
const DefaultTimestampFormat = time.RFC3339
|
|
||||||
|
|
||||||
// The Formatter interface is used to implement a custom Formatter. It takes an
|
|
||||||
// `Entry`. It exposes all the fields, including the default ones:
|
|
||||||
//
|
|
||||||
// * `entry.Data["msg"]`. The message passed from Info, Warn, Error ..
|
|
||||||
// * `entry.Data["time"]`. The timestamp.
|
|
||||||
// * `entry.Data["level"]. The level the entry was logged at.
|
|
||||||
//
|
|
||||||
// Any additional fields added with `WithField` or `WithFields` are also in
|
|
||||||
// `entry.Data`. Format is expected to return an array of bytes which are then
|
|
||||||
// logged to `logger.Out`.
|
|
||||||
type Formatter interface {
|
|
||||||
Format(*Entry) ([]byte, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is to not silently overwrite `time`, `msg` and `level` fields when
|
|
||||||
// dumping it. If this code wasn't there doing:
|
|
||||||
//
|
|
||||||
// logrus.WithField("level", 1).Info("hello")
|
|
||||||
//
|
|
||||||
// Would just silently drop the user provided level. Instead with this code
|
|
||||||
// it'll logged as:
|
|
||||||
//
|
|
||||||
// {"level": "info", "fields.level": 1, "msg": "hello", "time": "..."}
|
|
||||||
//
|
|
||||||
// It's not exported because it's still using Data in an opinionated way. It's to
|
|
||||||
// avoid code duplication between the two default formatters.
|
|
||||||
func prefixFieldClashes(data Fields) {
|
|
||||||
if t, ok := data["time"]; ok {
|
|
||||||
data["fields.time"] = t
|
|
||||||
}
|
|
||||||
|
|
||||||
if m, ok := data["msg"]; ok {
|
|
||||||
data["fields.msg"] = m
|
|
||||||
}
|
|
||||||
|
|
||||||
if l, ok := data["level"]; ok {
|
|
||||||
data["fields.level"] = l
|
|
||||||
}
|
|
||||||
}
|
|
34
vendor/github.com/sirupsen/logrus/hooks.go
generated
vendored
34
vendor/github.com/sirupsen/logrus/hooks.go
generated
vendored
|
@ -1,34 +0,0 @@
|
||||||
package logrus
|
|
||||||
|
|
||||||
// A hook to be fired when logging on the logging levels returned from
|
|
||||||
// `Levels()` on your implementation of the interface. Note that this is not
|
|
||||||
// fired in a goroutine or a channel with workers, you should handle such
|
|
||||||
// functionality yourself if your call is non-blocking and you don't wish for
|
|
||||||
// the logging calls for levels returned from `Levels()` to block.
|
|
||||||
type Hook interface {
|
|
||||||
Levels() []Level
|
|
||||||
Fire(*Entry) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Internal type for storing the hooks on a logger instance.
|
|
||||||
type LevelHooks map[Level][]Hook
|
|
||||||
|
|
||||||
// Add a hook to an instance of logger. This is called with
|
|
||||||
// `log.Hooks.Add(new(MyHook))` where `MyHook` implements the `Hook` interface.
|
|
||||||
func (hooks LevelHooks) Add(hook Hook) {
|
|
||||||
for _, level := range hook.Levels() {
|
|
||||||
hooks[level] = append(hooks[level], hook)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fire all the hooks for the passed level. Used by `entry.log` to fire
|
|
||||||
// appropriate hooks for a log entry.
|
|
||||||
func (hooks LevelHooks) Fire(level Level, entry *Entry) error {
|
|
||||||
for _, hook := range hooks[level] {
|
|
||||||
if err := hook.Fire(entry); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
74
vendor/github.com/sirupsen/logrus/json_formatter.go
generated
vendored
74
vendor/github.com/sirupsen/logrus/json_formatter.go
generated
vendored
|
@ -1,74 +0,0 @@
|
||||||
package logrus
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
type fieldKey string
|
|
||||||
type FieldMap map[fieldKey]string
|
|
||||||
|
|
||||||
const (
|
|
||||||
FieldKeyMsg = "msg"
|
|
||||||
FieldKeyLevel = "level"
|
|
||||||
FieldKeyTime = "time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (f FieldMap) resolve(key fieldKey) string {
|
|
||||||
if k, ok := f[key]; ok {
|
|
||||||
return k
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(key)
|
|
||||||
}
|
|
||||||
|
|
||||||
type JSONFormatter struct {
|
|
||||||
// TimestampFormat sets the format used for marshaling timestamps.
|
|
||||||
TimestampFormat string
|
|
||||||
|
|
||||||
// DisableTimestamp allows disabling automatic timestamps in output
|
|
||||||
DisableTimestamp bool
|
|
||||||
|
|
||||||
// FieldMap allows users to customize the names of keys for various fields.
|
|
||||||
// As an example:
|
|
||||||
// formatter := &JSONFormatter{
|
|
||||||
// FieldMap: FieldMap{
|
|
||||||
// FieldKeyTime: "@timestamp",
|
|
||||||
// FieldKeyLevel: "@level",
|
|
||||||
// FieldKeyMsg: "@message",
|
|
||||||
// },
|
|
||||||
// }
|
|
||||||
FieldMap FieldMap
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) {
|
|
||||||
data := make(Fields, len(entry.Data)+3)
|
|
||||||
for k, v := range entry.Data {
|
|
||||||
switch v := v.(type) {
|
|
||||||
case error:
|
|
||||||
// Otherwise errors are ignored by `encoding/json`
|
|
||||||
// https://github.com/sirupsen/logrus/issues/137
|
|
||||||
data[k] = v.Error()
|
|
||||||
default:
|
|
||||||
data[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
prefixFieldClashes(data)
|
|
||||||
|
|
||||||
timestampFormat := f.TimestampFormat
|
|
||||||
if timestampFormat == "" {
|
|
||||||
timestampFormat = DefaultTimestampFormat
|
|
||||||
}
|
|
||||||
|
|
||||||
if !f.DisableTimestamp {
|
|
||||||
data[f.FieldMap.resolve(FieldKeyTime)] = entry.Time.Format(timestampFormat)
|
|
||||||
}
|
|
||||||
data[f.FieldMap.resolve(FieldKeyMsg)] = entry.Message
|
|
||||||
data[f.FieldMap.resolve(FieldKeyLevel)] = entry.Level.String()
|
|
||||||
|
|
||||||
serialized, err := json.Marshal(data)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err)
|
|
||||||
}
|
|
||||||
return append(serialized, '\n'), nil
|
|
||||||
}
|
|
317
vendor/github.com/sirupsen/logrus/logger.go
generated
vendored
317
vendor/github.com/sirupsen/logrus/logger.go
generated
vendored
|
@ -1,317 +0,0 @@
|
||||||
package logrus
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"sync"
|
|
||||||
"sync/atomic"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Logger struct {
|
|
||||||
// The logs are `io.Copy`'d to this in a mutex. It's common to set this to a
|
|
||||||
// file, or leave it default which is `os.Stderr`. You can also set this to
|
|
||||||
// something more adventorous, such as logging to Kafka.
|
|
||||||
Out io.Writer
|
|
||||||
// Hooks for the logger instance. These allow firing events based on logging
|
|
||||||
// levels and log entries. For example, to send errors to an error tracking
|
|
||||||
// service, log to StatsD or dump the core on fatal errors.
|
|
||||||
Hooks LevelHooks
|
|
||||||
// All log entries pass through the formatter before logged to Out. The
|
|
||||||
// included formatters are `TextFormatter` and `JSONFormatter` for which
|
|
||||||
// TextFormatter is the default. In development (when a TTY is attached) it
|
|
||||||
// logs with colors, but to a file it wouldn't. You can easily implement your
|
|
||||||
// own that implements the `Formatter` interface, see the `README` or included
|
|
||||||
// formatters for examples.
|
|
||||||
Formatter Formatter
|
|
||||||
// The logging level the logger should log at. This is typically (and defaults
|
|
||||||
// to) `logrus.Info`, which allows Info(), Warn(), Error() and Fatal() to be
|
|
||||||
// logged. `logrus.Debug` is useful in
|
|
||||||
Level Level
|
|
||||||
// Used to sync writing to the log. Locking is enabled by Default
|
|
||||||
mu MutexWrap
|
|
||||||
// Reusable empty entry
|
|
||||||
entryPool sync.Pool
|
|
||||||
}
|
|
||||||
|
|
||||||
type MutexWrap struct {
|
|
||||||
lock sync.Mutex
|
|
||||||
disabled bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mw *MutexWrap) Lock() {
|
|
||||||
if !mw.disabled {
|
|
||||||
mw.lock.Lock()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mw *MutexWrap) Unlock() {
|
|
||||||
if !mw.disabled {
|
|
||||||
mw.lock.Unlock()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mw *MutexWrap) Disable() {
|
|
||||||
mw.disabled = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Creates a new logger. Configuration should be set by changing `Formatter`,
|
|
||||||
// `Out` and `Hooks` directly on the default logger instance. You can also just
|
|
||||||
// instantiate your own:
|
|
||||||
//
|
|
||||||
// var log = &Logger{
|
|
||||||
// Out: os.Stderr,
|
|
||||||
// Formatter: new(JSONFormatter),
|
|
||||||
// Hooks: make(LevelHooks),
|
|
||||||
// Level: logrus.DebugLevel,
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// It's recommended to make this a global instance called `log`.
|
|
||||||
func New() *Logger {
|
|
||||||
return &Logger{
|
|
||||||
Out: os.Stderr,
|
|
||||||
Formatter: new(TextFormatter),
|
|
||||||
Hooks: make(LevelHooks),
|
|
||||||
Level: InfoLevel,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) newEntry() *Entry {
|
|
||||||
entry, ok := logger.entryPool.Get().(*Entry)
|
|
||||||
if ok {
|
|
||||||
return entry
|
|
||||||
}
|
|
||||||
return NewEntry(logger)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) releaseEntry(entry *Entry) {
|
|
||||||
logger.entryPool.Put(entry)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adds a field to the log entry, note that it doesn't log until you call
|
|
||||||
// Debug, Print, Info, Warn, Fatal or Panic. It only creates a log entry.
|
|
||||||
// If you want multiple fields, use `WithFields`.
|
|
||||||
func (logger *Logger) WithField(key string, value interface{}) *Entry {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
defer logger.releaseEntry(entry)
|
|
||||||
return entry.WithField(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adds a struct of fields to the log entry. All it does is call `WithField` for
|
|
||||||
// each `Field`.
|
|
||||||
func (logger *Logger) WithFields(fields Fields) *Entry {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
defer logger.releaseEntry(entry)
|
|
||||||
return entry.WithFields(fields)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add an error as single field to the log entry. All it does is call
|
|
||||||
// `WithError` for the given `error`.
|
|
||||||
func (logger *Logger) WithError(err error) *Entry {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
defer logger.releaseEntry(entry)
|
|
||||||
return entry.WithError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Debugf(format string, args ...interface{}) {
|
|
||||||
if logger.level() >= DebugLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Debugf(format, args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Infof(format string, args ...interface{}) {
|
|
||||||
if logger.level() >= InfoLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Infof(format, args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Printf(format string, args ...interface{}) {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Printf(format, args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Warnf(format string, args ...interface{}) {
|
|
||||||
if logger.level() >= WarnLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Warnf(format, args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Warningf(format string, args ...interface{}) {
|
|
||||||
if logger.level() >= WarnLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Warnf(format, args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Errorf(format string, args ...interface{}) {
|
|
||||||
if logger.level() >= ErrorLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Errorf(format, args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Fatalf(format string, args ...interface{}) {
|
|
||||||
if logger.level() >= FatalLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Fatalf(format, args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Panicf(format string, args ...interface{}) {
|
|
||||||
if logger.level() >= PanicLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Panicf(format, args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Debug(args ...interface{}) {
|
|
||||||
if logger.level() >= DebugLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Debug(args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Info(args ...interface{}) {
|
|
||||||
if logger.level() >= InfoLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Info(args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Print(args ...interface{}) {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Info(args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Warn(args ...interface{}) {
|
|
||||||
if logger.level() >= WarnLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Warn(args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Warning(args ...interface{}) {
|
|
||||||
if logger.level() >= WarnLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Warn(args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Error(args ...interface{}) {
|
|
||||||
if logger.level() >= ErrorLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Error(args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Fatal(args ...interface{}) {
|
|
||||||
if logger.level() >= FatalLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Fatal(args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Panic(args ...interface{}) {
|
|
||||||
if logger.level() >= PanicLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Panic(args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Debugln(args ...interface{}) {
|
|
||||||
if logger.level() >= DebugLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Debugln(args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Infoln(args ...interface{}) {
|
|
||||||
if logger.level() >= InfoLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Infoln(args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Println(args ...interface{}) {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Println(args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Warnln(args ...interface{}) {
|
|
||||||
if logger.level() >= WarnLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Warnln(args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Warningln(args ...interface{}) {
|
|
||||||
if logger.level() >= WarnLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Warnln(args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Errorln(args ...interface{}) {
|
|
||||||
if logger.level() >= ErrorLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Errorln(args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Fatalln(args ...interface{}) {
|
|
||||||
if logger.level() >= FatalLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Fatalln(args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) Panicln(args ...interface{}) {
|
|
||||||
if logger.level() >= PanicLevel {
|
|
||||||
entry := logger.newEntry()
|
|
||||||
entry.Panicln(args...)
|
|
||||||
logger.releaseEntry(entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//When file is opened with appending mode, it's safe to
|
|
||||||
//write concurrently to a file (within 4k message on Linux).
|
|
||||||
//In these cases user can choose to disable the lock.
|
|
||||||
func (logger *Logger) SetNoLock() {
|
|
||||||
logger.mu.Disable()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) level() Level {
|
|
||||||
return Level(atomic.LoadUint32((*uint32)(&logger.Level)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) setLevel(level Level) {
|
|
||||||
atomic.StoreUint32((*uint32)(&logger.Level), uint32(level))
|
|
||||||
}
|
|
143
vendor/github.com/sirupsen/logrus/logrus.go
generated
vendored
143
vendor/github.com/sirupsen/logrus/logrus.go
generated
vendored
|
@ -1,143 +0,0 @@
|
||||||
package logrus
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Fields type, used to pass to `WithFields`.
|
|
||||||
type Fields map[string]interface{}
|
|
||||||
|
|
||||||
// Level type
|
|
||||||
type Level uint32
|
|
||||||
|
|
||||||
// Convert the Level to a string. E.g. PanicLevel becomes "panic".
|
|
||||||
func (level Level) String() string {
|
|
||||||
switch level {
|
|
||||||
case DebugLevel:
|
|
||||||
return "debug"
|
|
||||||
case InfoLevel:
|
|
||||||
return "info"
|
|
||||||
case WarnLevel:
|
|
||||||
return "warning"
|
|
||||||
case ErrorLevel:
|
|
||||||
return "error"
|
|
||||||
case FatalLevel:
|
|
||||||
return "fatal"
|
|
||||||
case PanicLevel:
|
|
||||||
return "panic"
|
|
||||||
}
|
|
||||||
|
|
||||||
return "unknown"
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseLevel takes a string level and returns the Logrus log level constant.
|
|
||||||
func ParseLevel(lvl string) (Level, error) {
|
|
||||||
switch strings.ToLower(lvl) {
|
|
||||||
case "panic":
|
|
||||||
return PanicLevel, nil
|
|
||||||
case "fatal":
|
|
||||||
return FatalLevel, nil
|
|
||||||
case "error":
|
|
||||||
return ErrorLevel, nil
|
|
||||||
case "warn", "warning":
|
|
||||||
return WarnLevel, nil
|
|
||||||
case "info":
|
|
||||||
return InfoLevel, nil
|
|
||||||
case "debug":
|
|
||||||
return DebugLevel, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var l Level
|
|
||||||
return l, fmt.Errorf("not a valid logrus Level: %q", lvl)
|
|
||||||
}
|
|
||||||
|
|
||||||
// A constant exposing all logging levels
|
|
||||||
var AllLevels = []Level{
|
|
||||||
PanicLevel,
|
|
||||||
FatalLevel,
|
|
||||||
ErrorLevel,
|
|
||||||
WarnLevel,
|
|
||||||
InfoLevel,
|
|
||||||
DebugLevel,
|
|
||||||
}
|
|
||||||
|
|
||||||
// These are the different logging levels. You can set the logging level to log
|
|
||||||
// on your instance of logger, obtained with `logrus.New()`.
|
|
||||||
const (
|
|
||||||
// PanicLevel level, highest level of severity. Logs and then calls panic with the
|
|
||||||
// message passed to Debug, Info, ...
|
|
||||||
PanicLevel Level = iota
|
|
||||||
// FatalLevel level. Logs and then calls `os.Exit(1)`. It will exit even if the
|
|
||||||
// logging level is set to Panic.
|
|
||||||
FatalLevel
|
|
||||||
// ErrorLevel level. Logs. Used for errors that should definitely be noted.
|
|
||||||
// Commonly used for hooks to send errors to an error tracking service.
|
|
||||||
ErrorLevel
|
|
||||||
// WarnLevel level. Non-critical entries that deserve eyes.
|
|
||||||
WarnLevel
|
|
||||||
// InfoLevel level. General operational entries about what's going on inside the
|
|
||||||
// application.
|
|
||||||
InfoLevel
|
|
||||||
// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
|
|
||||||
DebugLevel
|
|
||||||
)
|
|
||||||
|
|
||||||
// Won't compile if StdLogger can't be realized by a log.Logger
|
|
||||||
var (
|
|
||||||
_ StdLogger = &log.Logger{}
|
|
||||||
_ StdLogger = &Entry{}
|
|
||||||
_ StdLogger = &Logger{}
|
|
||||||
)
|
|
||||||
|
|
||||||
// StdLogger is what your logrus-enabled library should take, that way
|
|
||||||
// it'll accept a stdlib logger and a logrus logger. There's no standard
|
|
||||||
// interface, this is the closest we get, unfortunately.
|
|
||||||
type StdLogger interface {
|
|
||||||
Print(...interface{})
|
|
||||||
Printf(string, ...interface{})
|
|
||||||
Println(...interface{})
|
|
||||||
|
|
||||||
Fatal(...interface{})
|
|
||||||
Fatalf(string, ...interface{})
|
|
||||||
Fatalln(...interface{})
|
|
||||||
|
|
||||||
Panic(...interface{})
|
|
||||||
Panicf(string, ...interface{})
|
|
||||||
Panicln(...interface{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// The FieldLogger interface generalizes the Entry and Logger types
|
|
||||||
type FieldLogger interface {
|
|
||||||
WithField(key string, value interface{}) *Entry
|
|
||||||
WithFields(fields Fields) *Entry
|
|
||||||
WithError(err error) *Entry
|
|
||||||
|
|
||||||
Debugf(format string, args ...interface{})
|
|
||||||
Infof(format string, args ...interface{})
|
|
||||||
Printf(format string, args ...interface{})
|
|
||||||
Warnf(format string, args ...interface{})
|
|
||||||
Warningf(format string, args ...interface{})
|
|
||||||
Errorf(format string, args ...interface{})
|
|
||||||
Fatalf(format string, args ...interface{})
|
|
||||||
Panicf(format string, args ...interface{})
|
|
||||||
|
|
||||||
Debug(args ...interface{})
|
|
||||||
Info(args ...interface{})
|
|
||||||
Print(args ...interface{})
|
|
||||||
Warn(args ...interface{})
|
|
||||||
Warning(args ...interface{})
|
|
||||||
Error(args ...interface{})
|
|
||||||
Fatal(args ...interface{})
|
|
||||||
Panic(args ...interface{})
|
|
||||||
|
|
||||||
Debugln(args ...interface{})
|
|
||||||
Infoln(args ...interface{})
|
|
||||||
Println(args ...interface{})
|
|
||||||
Warnln(args ...interface{})
|
|
||||||
Warningln(args ...interface{})
|
|
||||||
Errorln(args ...interface{})
|
|
||||||
Fatalln(args ...interface{})
|
|
||||||
Panicln(args ...interface{})
|
|
||||||
}
|
|
10
vendor/github.com/sirupsen/logrus/terminal_appengine.go
generated
vendored
10
vendor/github.com/sirupsen/logrus/terminal_appengine.go
generated
vendored
|
@ -1,10 +0,0 @@
|
||||||
// +build appengine
|
|
||||||
|
|
||||||
package logrus
|
|
||||||
|
|
||||||
import "io"
|
|
||||||
|
|
||||||
// IsTerminal returns true if stderr's file descriptor is a terminal.
|
|
||||||
func IsTerminal(f io.Writer) bool {
|
|
||||||
return true
|
|
||||||
}
|
|
10
vendor/github.com/sirupsen/logrus/terminal_bsd.go
generated
vendored
10
vendor/github.com/sirupsen/logrus/terminal_bsd.go
generated
vendored
|
@ -1,10 +0,0 @@
|
||||||
// +build darwin freebsd openbsd netbsd dragonfly
|
|
||||||
// +build !appengine
|
|
||||||
|
|
||||||
package logrus
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
const ioctlReadTermios = syscall.TIOCGETA
|
|
||||||
|
|
||||||
type Termios syscall.Termios
|
|
14
vendor/github.com/sirupsen/logrus/terminal_linux.go
generated
vendored
14
vendor/github.com/sirupsen/logrus/terminal_linux.go
generated
vendored
|
@ -1,14 +0,0 @@
|
||||||
// Based on ssh/terminal:
|
|
||||||
// Copyright 2013 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build !appengine
|
|
||||||
|
|
||||||
package logrus
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
const ioctlReadTermios = syscall.TCGETS
|
|
||||||
|
|
||||||
type Termios syscall.Termios
|
|
28
vendor/github.com/sirupsen/logrus/terminal_notwindows.go
generated
vendored
28
vendor/github.com/sirupsen/logrus/terminal_notwindows.go
generated
vendored
|
@ -1,28 +0,0 @@
|
||||||
// Based on ssh/terminal:
|
|
||||||
// Copyright 2011 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build linux darwin freebsd openbsd netbsd dragonfly
|
|
||||||
// +build !appengine
|
|
||||||
|
|
||||||
package logrus
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// IsTerminal returns true if stderr's file descriptor is a terminal.
|
|
||||||
func IsTerminal(f io.Writer) bool {
|
|
||||||
var termios Termios
|
|
||||||
switch v := f.(type) {
|
|
||||||
case *os.File:
|
|
||||||
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(v.Fd()), ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
|
|
||||||
return err == 0
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
21
vendor/github.com/sirupsen/logrus/terminal_solaris.go
generated
vendored
21
vendor/github.com/sirupsen/logrus/terminal_solaris.go
generated
vendored
|
@ -1,21 +0,0 @@
|
||||||
// +build solaris,!appengine
|
|
||||||
|
|
||||||
package logrus
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
)
|
|
||||||
|
|
||||||
// IsTerminal returns true if the given file descriptor is a terminal.
|
|
||||||
func IsTerminal(f io.Writer) bool {
|
|
||||||
switch v := f.(type) {
|
|
||||||
case *os.File:
|
|
||||||
_, err := unix.IoctlGetTermios(int(v.Fd()), unix.TCGETA)
|
|
||||||
return err == nil
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
82
vendor/github.com/sirupsen/logrus/terminal_windows.go
generated
vendored
82
vendor/github.com/sirupsen/logrus/terminal_windows.go
generated
vendored
|
@ -1,82 +0,0 @@
|
||||||
// Based on ssh/terminal:
|
|
||||||
// Copyright 2011 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows,!appengine
|
|
||||||
|
|
||||||
package logrus
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
var kernel32 = syscall.NewLazyDLL("kernel32.dll")
|
|
||||||
|
|
||||||
var (
|
|
||||||
procGetConsoleMode = kernel32.NewProc("GetConsoleMode")
|
|
||||||
procSetConsoleMode = kernel32.NewProc("SetConsoleMode")
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
enableProcessedOutput = 0x0001
|
|
||||||
enableWrapAtEolOutput = 0x0002
|
|
||||||
enableVirtualTerminalProcessing = 0x0004
|
|
||||||
)
|
|
||||||
|
|
||||||
func getVersion() (float64, error) {
|
|
||||||
stdout, stderr := &bytes.Buffer{}, &bytes.Buffer{}
|
|
||||||
cmd := exec.Command("cmd", "ver")
|
|
||||||
cmd.Stdout = stdout
|
|
||||||
cmd.Stderr = stderr
|
|
||||||
err := cmd.Run()
|
|
||||||
if err != nil {
|
|
||||||
return -1, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// The output should be like "Microsoft Windows [Version XX.X.XXXXXX]"
|
|
||||||
version := strings.Replace(stdout.String(), "\n", "", -1)
|
|
||||||
version = strings.Replace(version, "\r\n", "", -1)
|
|
||||||
|
|
||||||
x1 := strings.Index(version, "[Version")
|
|
||||||
|
|
||||||
if x1 == -1 || strings.Index(version, "]") == -1 {
|
|
||||||
return -1, errors.New("Can't determine Windows version")
|
|
||||||
}
|
|
||||||
|
|
||||||
return strconv.ParseFloat(version[x1+9:x1+13], 64)
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
ver, err := getVersion()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Activate Virtual Processing for Windows CMD
|
|
||||||
// Info: https://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx
|
|
||||||
if ver >= 10 {
|
|
||||||
handle := syscall.Handle(os.Stderr.Fd())
|
|
||||||
procSetConsoleMode.Call(uintptr(handle), enableProcessedOutput|enableWrapAtEolOutput|enableVirtualTerminalProcessing)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsTerminal returns true if stderr's file descriptor is a terminal.
|
|
||||||
func IsTerminal(f io.Writer) bool {
|
|
||||||
switch v := f.(type) {
|
|
||||||
case *os.File:
|
|
||||||
var st uint32
|
|
||||||
r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, uintptr(v.Fd()), uintptr(unsafe.Pointer(&st)), 0)
|
|
||||||
return r != 0 && e == 0
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
189
vendor/github.com/sirupsen/logrus/text_formatter.go
generated
vendored
189
vendor/github.com/sirupsen/logrus/text_formatter.go
generated
vendored
|
@ -1,189 +0,0 @@
|
||||||
package logrus
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"sort"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
nocolor = 0
|
|
||||||
red = 31
|
|
||||||
green = 32
|
|
||||||
yellow = 33
|
|
||||||
blue = 34
|
|
||||||
gray = 37
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
baseTimestamp time.Time
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
baseTimestamp = time.Now()
|
|
||||||
}
|
|
||||||
|
|
||||||
type TextFormatter struct {
|
|
||||||
// Set to true to bypass checking for a TTY before outputting colors.
|
|
||||||
ForceColors bool
|
|
||||||
|
|
||||||
// Force disabling colors.
|
|
||||||
DisableColors bool
|
|
||||||
|
|
||||||
// Disable timestamp logging. useful when output is redirected to logging
|
|
||||||
// system that already adds timestamps.
|
|
||||||
DisableTimestamp bool
|
|
||||||
|
|
||||||
// Enable logging the full timestamp when a TTY is attached instead of just
|
|
||||||
// the time passed since beginning of execution.
|
|
||||||
FullTimestamp bool
|
|
||||||
|
|
||||||
// TimestampFormat to use for display when a full timestamp is printed
|
|
||||||
TimestampFormat string
|
|
||||||
|
|
||||||
// The fields are sorted by default for a consistent output. For applications
|
|
||||||
// that log extremely frequently and don't use the JSON formatter this may not
|
|
||||||
// be desired.
|
|
||||||
DisableSorting bool
|
|
||||||
|
|
||||||
// QuoteEmptyFields will wrap empty fields in quotes if true
|
|
||||||
QuoteEmptyFields bool
|
|
||||||
|
|
||||||
// QuoteCharacter can be set to the override the default quoting character "
|
|
||||||
// with something else. For example: ', or `.
|
|
||||||
QuoteCharacter string
|
|
||||||
|
|
||||||
// Whether the logger's out is to a terminal
|
|
||||||
isTerminal bool
|
|
||||||
|
|
||||||
sync.Once
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *TextFormatter) init(entry *Entry) {
|
|
||||||
if len(f.QuoteCharacter) == 0 {
|
|
||||||
f.QuoteCharacter = "\""
|
|
||||||
}
|
|
||||||
if entry.Logger != nil {
|
|
||||||
f.isTerminal = IsTerminal(entry.Logger.Out)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *TextFormatter) Format(entry *Entry) ([]byte, error) {
|
|
||||||
var b *bytes.Buffer
|
|
||||||
keys := make([]string, 0, len(entry.Data))
|
|
||||||
for k := range entry.Data {
|
|
||||||
keys = append(keys, k)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !f.DisableSorting {
|
|
||||||
sort.Strings(keys)
|
|
||||||
}
|
|
||||||
if entry.Buffer != nil {
|
|
||||||
b = entry.Buffer
|
|
||||||
} else {
|
|
||||||
b = &bytes.Buffer{}
|
|
||||||
}
|
|
||||||
|
|
||||||
prefixFieldClashes(entry.Data)
|
|
||||||
|
|
||||||
f.Do(func() { f.init(entry) })
|
|
||||||
|
|
||||||
isColored := (f.ForceColors || f.isTerminal) && !f.DisableColors
|
|
||||||
|
|
||||||
timestampFormat := f.TimestampFormat
|
|
||||||
if timestampFormat == "" {
|
|
||||||
timestampFormat = DefaultTimestampFormat
|
|
||||||
}
|
|
||||||
if isColored {
|
|
||||||
f.printColored(b, entry, keys, timestampFormat)
|
|
||||||
} else {
|
|
||||||
if !f.DisableTimestamp {
|
|
||||||
f.appendKeyValue(b, "time", entry.Time.Format(timestampFormat))
|
|
||||||
}
|
|
||||||
f.appendKeyValue(b, "level", entry.Level.String())
|
|
||||||
if entry.Message != "" {
|
|
||||||
f.appendKeyValue(b, "msg", entry.Message)
|
|
||||||
}
|
|
||||||
for _, key := range keys {
|
|
||||||
f.appendKeyValue(b, key, entry.Data[key])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
b.WriteByte('\n')
|
|
||||||
return b.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []string, timestampFormat string) {
|
|
||||||
var levelColor int
|
|
||||||
switch entry.Level {
|
|
||||||
case DebugLevel:
|
|
||||||
levelColor = gray
|
|
||||||
case WarnLevel:
|
|
||||||
levelColor = yellow
|
|
||||||
case ErrorLevel, FatalLevel, PanicLevel:
|
|
||||||
levelColor = red
|
|
||||||
default:
|
|
||||||
levelColor = blue
|
|
||||||
}
|
|
||||||
|
|
||||||
levelText := strings.ToUpper(entry.Level.String())[0:4]
|
|
||||||
|
|
||||||
if f.DisableTimestamp {
|
|
||||||
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m %-44s ", levelColor, levelText, entry.Message)
|
|
||||||
} else if !f.FullTimestamp {
|
|
||||||
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d] %-44s ", levelColor, levelText, int(entry.Time.Sub(baseTimestamp)/time.Second), entry.Message)
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %-44s ", levelColor, levelText, entry.Time.Format(timestampFormat), entry.Message)
|
|
||||||
}
|
|
||||||
for _, k := range keys {
|
|
||||||
v := entry.Data[k]
|
|
||||||
fmt.Fprintf(b, " \x1b[%dm%s\x1b[0m=", levelColor, k)
|
|
||||||
f.appendValue(b, v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *TextFormatter) needsQuoting(text string) bool {
|
|
||||||
if f.QuoteEmptyFields && len(text) == 0 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
for _, ch := range text {
|
|
||||||
if !((ch >= 'a' && ch <= 'z') ||
|
|
||||||
(ch >= 'A' && ch <= 'Z') ||
|
|
||||||
(ch >= '0' && ch <= '9') ||
|
|
||||||
ch == '-' || ch == '.') {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *TextFormatter) appendKeyValue(b *bytes.Buffer, key string, value interface{}) {
|
|
||||||
|
|
||||||
b.WriteString(key)
|
|
||||||
b.WriteByte('=')
|
|
||||||
f.appendValue(b, value)
|
|
||||||
b.WriteByte(' ')
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *TextFormatter) appendValue(b *bytes.Buffer, value interface{}) {
|
|
||||||
switch value := value.(type) {
|
|
||||||
case string:
|
|
||||||
if !f.needsQuoting(value) {
|
|
||||||
b.WriteString(value)
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(b, "%s%v%s", f.QuoteCharacter, value, f.QuoteCharacter)
|
|
||||||
}
|
|
||||||
case error:
|
|
||||||
errmsg := value.Error()
|
|
||||||
if !f.needsQuoting(errmsg) {
|
|
||||||
b.WriteString(errmsg)
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(b, "%s%v%s", f.QuoteCharacter, errmsg, f.QuoteCharacter)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
fmt.Fprint(b, value)
|
|
||||||
}
|
|
||||||
}
|
|
62
vendor/github.com/sirupsen/logrus/writer.go
generated
vendored
62
vendor/github.com/sirupsen/logrus/writer.go
generated
vendored
|
@ -1,62 +0,0 @@
|
||||||
package logrus
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"io"
|
|
||||||
"runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (logger *Logger) Writer() *io.PipeWriter {
|
|
||||||
return logger.WriterLevel(InfoLevel)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) WriterLevel(level Level) *io.PipeWriter {
|
|
||||||
return NewEntry(logger).WriterLevel(level)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) Writer() *io.PipeWriter {
|
|
||||||
return entry.WriterLevel(InfoLevel)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) WriterLevel(level Level) *io.PipeWriter {
|
|
||||||
reader, writer := io.Pipe()
|
|
||||||
|
|
||||||
var printFunc func(args ...interface{})
|
|
||||||
|
|
||||||
switch level {
|
|
||||||
case DebugLevel:
|
|
||||||
printFunc = entry.Debug
|
|
||||||
case InfoLevel:
|
|
||||||
printFunc = entry.Info
|
|
||||||
case WarnLevel:
|
|
||||||
printFunc = entry.Warn
|
|
||||||
case ErrorLevel:
|
|
||||||
printFunc = entry.Error
|
|
||||||
case FatalLevel:
|
|
||||||
printFunc = entry.Fatal
|
|
||||||
case PanicLevel:
|
|
||||||
printFunc = entry.Panic
|
|
||||||
default:
|
|
||||||
printFunc = entry.Print
|
|
||||||
}
|
|
||||||
|
|
||||||
go entry.writerScanner(reader, printFunc)
|
|
||||||
runtime.SetFinalizer(writer, writerFinalizer)
|
|
||||||
|
|
||||||
return writer
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) writerScanner(reader *io.PipeReader, printFunc func(args ...interface{})) {
|
|
||||||
scanner := bufio.NewScanner(reader)
|
|
||||||
for scanner.Scan() {
|
|
||||||
printFunc(scanner.Text())
|
|
||||||
}
|
|
||||||
if err := scanner.Err(); err != nil {
|
|
||||||
entry.Errorf("Error while reading from Writer: %s", err)
|
|
||||||
}
|
|
||||||
reader.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
func writerFinalizer(writer *io.PipeWriter) {
|
|
||||||
writer.Close()
|
|
||||||
}
|
|
36
vendor/vendor.json
vendored
36
vendor/vendor.json
vendored
|
@ -269,12 +269,6 @@
|
||||||
"revision": "84bc9597164f671c0130543778228928d6865c5c",
|
"revision": "84bc9597164f671c0130543778228928d6865c5c",
|
||||||
"revisionTime": "2017-06-08T03:40:07Z"
|
"revisionTime": "2017-06-08T03:40:07Z"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"checksumSHA1": "ga3jt9r+dQBMSXG0gnpNcXp2xYA=",
|
|
||||||
"path": "github.com/coreos/etcd/pkg/fileutil",
|
|
||||||
"revision": "b32a8010a7768f3e44eb5ed74e4bebac5106234b",
|
|
||||||
"revisionTime": "2017-01-10T07:37:23Z"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"checksumSHA1": "Z2AOGSmDKKvI6nuxa+UPjQWpIeM=",
|
"checksumSHA1": "Z2AOGSmDKKvI6nuxa+UPjQWpIeM=",
|
||||||
"origin": "k8s.io/client-go/1.5/vendor/github.com/coreos/go-oidc/http",
|
"origin": "k8s.io/client-go/1.5/vendor/github.com/coreos/go-oidc/http",
|
||||||
|
@ -310,18 +304,6 @@
|
||||||
"revision": "c589d0c9f0d81640c518354c7bcae77d99820aa3",
|
"revision": "c589d0c9f0d81640c518354c7bcae77d99820aa3",
|
||||||
"revisionTime": "2016-09-30T00:14:02Z"
|
"revisionTime": "2016-09-30T00:14:02Z"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"checksumSHA1": "d50/+u/LFlXvEV10HiEoXB9OsGg=",
|
|
||||||
"path": "github.com/coreos/go-systemd/journal",
|
|
||||||
"revision": "7c9533367ef925dc1078d75e5b7141e10da2c4e8",
|
|
||||||
"revisionTime": "2016-12-12T10:46:09Z"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"checksumSHA1": "wqEybhAfMhCq2uOu4bT737mqu6U=",
|
|
||||||
"path": "github.com/coreos/pkg/capnslog",
|
|
||||||
"revision": "447b7ec906e523386d9c53be15b55a8ae86ea944",
|
|
||||||
"revisionTime": "2016-10-26T22:29:26Z"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"checksumSHA1": "O0UMBRCOD9ItMayDqLQ2MJEjkVE=",
|
"checksumSHA1": "O0UMBRCOD9ItMayDqLQ2MJEjkVE=",
|
||||||
"origin": "k8s.io/client-go/1.5/vendor/github.com/coreos/pkg/health",
|
"origin": "k8s.io/client-go/1.5/vendor/github.com/coreos/pkg/health",
|
||||||
|
@ -522,12 +504,6 @@
|
||||||
"revision": "84bc9597164f671c0130543778228928d6865c5c",
|
"revision": "84bc9597164f671c0130543778228928d6865c5c",
|
||||||
"revisionTime": "2017-06-08T03:40:07Z"
|
"revisionTime": "2017-06-08T03:40:07Z"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"checksumSHA1": "Z5Cpi8mr3kfpZ/CdmudThTWQ0Mo=",
|
|
||||||
"path": "github.com/golang/protobuf/ptypes/struct",
|
|
||||||
"revision": "5a0f697c9ed9d68fef0116532c6e05cfeae00e55",
|
|
||||||
"revisionTime": "2017-06-01T23:02:30Z"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"checksumSHA1": "2a/SsTUBMKtcM6VtpbdPGO+c6c8=",
|
"checksumSHA1": "2a/SsTUBMKtcM6VtpbdPGO+c6c8=",
|
||||||
"path": "github.com/golang/snappy",
|
"path": "github.com/golang/snappy",
|
||||||
|
@ -830,12 +806,6 @@
|
||||||
"revision": "9e0844febd9e2856f839c9cb974fbd676d1755a8",
|
"revision": "9e0844febd9e2856f839c9cb974fbd676d1755a8",
|
||||||
"revisionTime": "2017-04-18T15:52:10Z"
|
"revisionTime": "2017-04-18T15:52:10Z"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"checksumSHA1": "esljoY35OOHttvpjBctA6WGZc70=",
|
|
||||||
"path": "github.com/prometheus/common/log",
|
|
||||||
"revision": "94eb3fe3a55f1b5d12d335b27a4f6e37cd73ed7e",
|
|
||||||
"revisionTime": "2017-06-16T09:39:39Z"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"checksumSHA1": "3VoqH7TFfzA6Ds0zFzIbKCUvBmw=",
|
"checksumSHA1": "3VoqH7TFfzA6Ds0zFzIbKCUvBmw=",
|
||||||
"path": "github.com/prometheus/common/model",
|
"path": "github.com/prometheus/common/model",
|
||||||
|
@ -903,12 +873,6 @@
|
||||||
"revision": "84bc9597164f671c0130543778228928d6865c5c",
|
"revision": "84bc9597164f671c0130543778228928d6865c5c",
|
||||||
"revisionTime": "2017-06-08T03:40:07Z"
|
"revisionTime": "2017-06-08T03:40:07Z"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"checksumSHA1": "VHULZdEZKBxJvlZnlhX7Ug19lgY=",
|
|
||||||
"path": "github.com/sirupsen/logrus",
|
|
||||||
"revision": "85b1699d505667d13f8ac4478c1debbf85d6c5de",
|
|
||||||
"revisionTime": "2017-06-08T22:14:41Z"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"checksumSHA1": "STxYqRb4gnlSr3mRpT+Igfdz/kM=",
|
"checksumSHA1": "STxYqRb4gnlSr3mRpT+Igfdz/kM=",
|
||||||
"path": "github.com/spf13/pflag",
|
"path": "github.com/spf13/pflag",
|
||||||
|
|
Loading…
Reference in a new issue