0
0
Fork 0

clean up logging to use package level *log.Logger

by default messages go to ioutil.Discard
This commit is contained in:
Marty Schoch 2014-12-28 12:14:48 -08:00
parent a3a891fdb2
commit 0ddfa774ec
12 changed files with 469 additions and 469 deletions

View File

@ -21,7 +21,6 @@ package icu
import "C"
import (
"log"
"unsafe"
"github.com/blevesearch/bleve/analysis"
@ -66,7 +65,6 @@ func (t *UnicodeWordBoundaryTokenizer) Tokenize(input []byte) analysis.TokenStre
bi := C.ubrk_open(C.UBRK_WORD, t.locale, myUCharPointer, -1, &err)
if err > C.U_ZERO_ERROR {
log.Printf("error opening boundary iterator")
return rv
}
@ -85,7 +83,6 @@ func (t *UnicodeWordBoundaryTokenizer) Tokenize(input []byte) analysis.TokenStre
C.u_strToUTF8(nilCString, 0, &indexA, myUCharPointer, prev, &err)
if err > C.U_ZERO_ERROR && err != C.U_BUFFER_OVERFLOW_ERROR {
log.Printf("error converting boundary %d", err)
return rv
} else {
err = C.U_ZERO_ERROR
@ -94,7 +91,6 @@ func (t *UnicodeWordBoundaryTokenizer) Tokenize(input []byte) analysis.TokenStre
var indexB C.int32_t
C.u_strToUTF8(nilCString, 0, &indexB, myUCharPointer, p, &err)
if err > C.U_ZERO_ERROR && err != C.U_BUFFER_OVERFLOW_ERROR {
log.Printf("error converting boundary %d", err)
return rv
} else {
err = C.U_ZERO_ERROR

View File

@ -11,6 +11,8 @@ package bleve
import (
"expvar"
"io/ioutil"
"log"
"time"
"github.com/blevesearch/bleve/index/upside_down"
@ -161,3 +163,11 @@ func init() {
bootDuration := time.Since(bootStart)
bleveExpVar.Add("bootDuration", int64(bootDuration))
}
var logger = log.New(ioutil.Discard, "bleve", log.LstdFlags)
// SetLog sets the logger used for logging
// by default log messages are sent to ioutil.Discard
func SetLog(logger *log.Logger) {
logger = logger
}

View File

@ -11,7 +11,6 @@ package document
import (
"fmt"
"log"
)
type Document struct {
@ -48,7 +47,6 @@ func (d *Document) GoString() string {
}
compositeFields := ""
for i, field := range d.CompositeFields {
log.Printf("see composite field")
if i != 0 {
compositeFields += ", "
}

View File

@ -13,7 +13,6 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"github.com/blevesearch/bleve"
@ -54,7 +53,7 @@ func (h *SearchHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}
log.Printf("request body: %s", requestBody)
logger.Printf("request body: %s", requestBody)
// parse the request
var searchRequest bleve.SearchRequest
@ -64,7 +63,7 @@ func (h *SearchHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}
log.Printf("parsed request %#v", searchRequest)
logger.Printf("parsed request %#v", searchRequest)
// validate the query
err = searchRequest.Query.Validate()

View File

@ -12,13 +12,14 @@ package http
import (
"encoding/json"
"io"
"io/ioutil"
"log"
"net/http"
)
func showError(w http.ResponseWriter, r *http.Request,
msg string, code int) {
log.Printf("Reporting error %v/%v", code, msg)
logger.Printf("Reporting error %v/%v", code, msg)
http.Error(w, msg, code)
}
@ -35,3 +36,11 @@ func mustEncode(w io.Writer, i interface{}) {
}
type varLookupFunc func(req *http.Request) string
var logger = log.New(ioutil.Discard, "bleve.http", log.LstdFlags)
// SetLog sets the logger used for logging
// by default log messages are sent to ioutil.Discard
func SetLog(logger *log.Logger) {
logger = logger
}

View File

@ -10,7 +10,6 @@
package bleve
import (
"log"
"time"
"github.com/blevesearch/bleve/analysis"
@ -123,7 +122,7 @@ func (fm *FieldMapping) processTime(propertyValueTime time.Time, pathString stri
if err == nil {
context.doc.AddField(field)
} else {
log.Printf("could not build date %v", err)
logger.Printf("could not build date %v", err)
}
if !fm.IncludeInAll {

View File

@ -11,7 +11,6 @@ package bleve
import (
"encoding/json"
"log"
"github.com/blevesearch/bleve/analysis"
"github.com/blevesearch/bleve/document"
@ -339,10 +338,10 @@ func (im *IndexMapping) mapDocument(doc *document.Document, data interface{}) er
}
data = convertedData
} else {
log.Printf("error creating byte array converter: %v", err)
logger.Printf("error creating byte array converter: %v", err)
}
} else {
log.Printf("no byte array converter named: %s", im.ByteArrayConverter)
logger.Printf("no byte array converter named: %s", im.ByteArrayConverter)
}
}
@ -410,7 +409,7 @@ func (im *IndexMapping) analyzerNameForPath(path string) string {
func (im *IndexMapping) analyzerNamed(name string) *analysis.Analyzer {
analyzer, err := im.cache.AnalyzerNamed(name)
if err != nil {
log.Printf("error using analyzer named: %s", name)
logger.Printf("error using analyzer named: %s", name)
return nil
}
return analyzer
@ -419,7 +418,7 @@ func (im *IndexMapping) analyzerNamed(name string) *analysis.Analyzer {
func (im *IndexMapping) dateTimeParserNamed(name string) analysis.DateTimeParser {
dateTimeParser, err := im.cache.DateTimeParserNamed(name)
if err != nil {
log.Printf("error using datetime parser named: %s", name)
logger.Printf("error using datetime parser named: %s", name)
return nil
}
return dateTimeParser

View File

@ -11,7 +11,6 @@ package bleve
import (
"fmt"
"log"
"github.com/blevesearch/bleve/index"
"github.com/blevesearch/bleve/search"
@ -99,7 +98,6 @@ func (q *matchQuery) Searcher(i index.IndexReader, m *IndexMapping, explain bool
tqs := make([]Query, len(tokens))
if q.FuzzinessVal != 0 {
log.Printf("fuzziness is %d", q.FuzzinessVal)
for i, token := range tokens {
query := NewFuzzyQuery(string(token.Term))
query.SetFuzziness(q.FuzzinessVal)

View File

@ -34,10 +34,8 @@
//
package bleve
import("log")
func logDebugTokens(format string, v ...interface{}) {
if debugLexer {
log.Printf(format, v...)
logger.Printf(format, v...)
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,10 @@
%{
package bleve
import "log"
import "strconv"
func logDebugGrammar(format string, v ...interface{}) {
if debugParser {
log.Printf(format, v...)
logger.Printf(format, v...)
}
}
%}

View File

@ -3,16 +3,15 @@ package bleve
import __yyfmt__ "fmt"
//line query_string.y:2
import "log"
import "strconv"
func logDebugGrammar(format string, v ...interface{}) {
if debugParser {
log.Printf(format, v...)
logger.Printf(format, v...)
}
}
//line query_string.y:13
//line query_string.y:12
type yySymType struct {
yys int
s string
@ -358,22 +357,22 @@ yydefault:
switch yynt {
case 1:
//line query_string.y:35
//line query_string.y:34
{
logDebugGrammar("INPUT")
}
case 2:
//line query_string.y:40
//line query_string.y:39
{
logDebugGrammar("SEARCH PARTS")
}
case 3:
//line query_string.y:44
//line query_string.y:43
{
logDebugGrammar("SEARCH PART")
}
case 4:
//line query_string.y:49
//line query_string.y:48
{
query := yyS[yypt-1].q
query.SetBoost(yyS[yypt-0].f)
@ -387,29 +386,29 @@ yydefault:
}
}
case 5:
//line query_string.y:64
//line query_string.y:63
{
yyVAL.n = queryShould
}
case 6:
//line query_string.y:68
//line query_string.y:67
{
yyVAL.n = yyS[yypt-0].n
}
case 7:
//line query_string.y:74
//line query_string.y:73
{
logDebugGrammar("PLUS")
yyVAL.n = queryMust
}
case 8:
//line query_string.y:79
//line query_string.y:78
{
logDebugGrammar("MINUS")
yyVAL.n = queryMustNot
}
case 9:
//line query_string.y:85
//line query_string.y:84
{
str := yyS[yypt-0].s
logDebugGrammar("STRING - %s", str)
@ -417,7 +416,7 @@ yydefault:
yyVAL.q = q
}
case 10:
//line query_string.y:92
//line query_string.y:91
{
str := yyS[yypt-1].s
logDebugGrammar("STRING - %s", str)
@ -426,7 +425,7 @@ yydefault:
yyVAL.q = q
}
case 11:
//line query_string.y:100
//line query_string.y:99
{
str := yyS[yypt-1].s
fuzziness, _ := strconv.ParseFloat(yyS[yypt-0].s, 64)
@ -436,7 +435,7 @@ yydefault:
yyVAL.q = q
}
case 12:
//line query_string.y:109
//line query_string.y:108
{
str := yyS[yypt-0].s
logDebugGrammar("STRING - %s", str)
@ -444,7 +443,7 @@ yydefault:
yyVAL.q = q
}
case 13:
//line query_string.y:116
//line query_string.y:115
{
phrase := yyS[yypt-0].s
logDebugGrammar("PHRASE - %s", phrase)
@ -452,7 +451,7 @@ yydefault:
yyVAL.q = q
}
case 14:
//line query_string.y:123
//line query_string.y:122
{
field := yyS[yypt-2].s
str := yyS[yypt-0].s
@ -461,7 +460,7 @@ yydefault:
yyVAL.q = q
}
case 15:
//line query_string.y:131
//line query_string.y:130
{
field := yyS[yypt-2].s
str := yyS[yypt-0].s
@ -470,7 +469,7 @@ yydefault:
yyVAL.q = q
}
case 16:
//line query_string.y:139
//line query_string.y:138
{
field := yyS[yypt-2].s
phrase := yyS[yypt-0].s
@ -479,7 +478,7 @@ yydefault:
yyVAL.q = q
}
case 17:
//line query_string.y:147
//line query_string.y:146
{
field := yyS[yypt-3].s
min, _ := strconv.ParseFloat(yyS[yypt-0].s, 64)
@ -489,7 +488,7 @@ yydefault:
yyVAL.q = q
}
case 18:
//line query_string.y:156
//line query_string.y:155
{
field := yyS[yypt-4].s
min, _ := strconv.ParseFloat(yyS[yypt-0].s, 64)
@ -499,7 +498,7 @@ yydefault:
yyVAL.q = q
}
case 19:
//line query_string.y:165
//line query_string.y:164
{
field := yyS[yypt-3].s
max, _ := strconv.ParseFloat(yyS[yypt-0].s, 64)
@ -509,7 +508,7 @@ yydefault:
yyVAL.q = q
}
case 20:
//line query_string.y:174
//line query_string.y:173
{
field := yyS[yypt-4].s
max, _ := strconv.ParseFloat(yyS[yypt-0].s, 64)
@ -519,19 +518,19 @@ yydefault:
yyVAL.q = q
}
case 21:
//line query_string.y:184
//line query_string.y:183
{
boost, _ := strconv.ParseFloat(yyS[yypt-0].s, 64)
yyVAL.f = boost
logDebugGrammar("BOOST %f", boost)
}
case 22:
//line query_string.y:191
//line query_string.y:190
{
yyVAL.f = 1.0
}
case 23:
//line query_string.y:195
//line query_string.y:194
{
}