forked from ebhomengo/niki
1
0
Fork 0
niki/vendor/github.com/go-openapi/spec/debug.go

77 lines
1.3 KiB
Go
Raw Normal View History

2024-05-14 13:07:09 +00:00
// Copyright 2015 go-swagger maintainers
2024-05-14 13:07:09 +00:00
//
2024-05-14 13:07:09 +00:00
// Licensed under the Apache License, Version 2.0 (the "License");
2024-05-14 13:07:09 +00:00
// you may not use this file except in compliance with the License.
2024-05-14 13:07:09 +00:00
// You may obtain a copy of the License at
2024-05-14 13:07:09 +00:00
//
2024-05-14 13:07:09 +00:00
// http://www.apache.org/licenses/LICENSE-2.0
2024-05-14 13:07:09 +00:00
//
2024-05-14 13:07:09 +00:00
// Unless required by applicable law or agreed to in writing, software
2024-05-14 13:07:09 +00:00
// distributed under the License is distributed on an "AS IS" BASIS,
2024-05-14 13:07:09 +00:00
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2024-05-14 13:07:09 +00:00
// See the License for the specific language governing permissions and
2024-05-14 13:07:09 +00:00
// limitations under the License.
package spec
import (
"fmt"
"log"
"os"
"path"
"runtime"
)
// Debug is true when the SWAGGER_DEBUG env var is not empty.
2024-05-14 13:07:09 +00:00
//
2024-05-14 13:07:09 +00:00
// It enables a more verbose logging of this package.
2024-05-14 13:07:09 +00:00
var Debug = os.Getenv("SWAGGER_DEBUG") != ""
var (
2024-05-14 13:07:09 +00:00
// specLogger is a debug logger for this package
2024-05-14 13:07:09 +00:00
specLogger *log.Logger
)
func init() {
2024-05-14 13:07:09 +00:00
debugOptions()
2024-05-14 13:07:09 +00:00
}
func debugOptions() {
2024-05-14 13:07:09 +00:00
specLogger = log.New(os.Stdout, "spec:", log.LstdFlags)
2024-05-14 13:07:09 +00:00
}
func debugLog(msg string, args ...interface{}) {
2024-05-14 13:07:09 +00:00
// A private, trivial trace logger, based on go-openapi/spec/expander.go:debugLog()
2024-05-14 13:07:09 +00:00
if Debug {
2024-05-14 13:07:09 +00:00
_, file1, pos1, _ := runtime.Caller(1)
2024-05-14 13:07:09 +00:00
specLogger.Printf("%s:%d: %s", path.Base(file1), pos1, fmt.Sprintf(msg, args...))
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
}