Terminate all log.Printf with a new line.

This commit is contained in:
Sascha L. Teichmann 2015-07-20 14:19:41 +02:00
parent 91a50a4622
commit ecd599e44d
11 changed files with 47 additions and 47 deletions

View File

@ -31,7 +31,7 @@ func (ct *ChangeTracker) BlockChanged(key []byte) {
var err error
var coord common.Coord
if coord, err = common.DecodeStringBytesToCoord(key); err != nil {
log.Printf("decoding key failed: %s", err)
log.Printf("decoding key failed: %s\n", err)
return
}
ct.mutex.Lock()
@ -63,12 +63,12 @@ func (ct *ChangeTracker) FlushChanges(url string) {
var buf bytes.Buffer
encoder := json.NewEncoder(&buf)
if err = encoder.Encode(changes); err != nil {
log.Printf("WARN: encode changes to JSON failed: %s", err)
log.Printf("WARN: encode changes to JSON failed: %s\n", err)
return
}
if _, err = http.Post(
url, "application/json", bytes.NewBuffer(buf.Bytes())); err != nil {
log.Printf("WARN: posting changes to %s failed: %s", url, err)
log.Printf("WARN: posting changes to %s failed: %s\n", url, err)
}
}()
return

View File

@ -285,7 +285,7 @@ func (ldbs *LevelDBSession) plainSpatialQuery(first, second []byte, done chan st
pos int64
)
if pos, err = common.DecodeStringFromBytes(key); err != nil {
log.Printf("decoding key failed: %s", err)
log.Printf("decoding key failed: %s\n", err)
return
}
if pos > to {
@ -298,7 +298,7 @@ func (ldbs *LevelDBSession) plainSpatialQuery(first, second []byte, done chan st
}
}
if err = it.GetError(); err != nil {
log.Printf("iterating failed: %s", err)
log.Printf("iterating failed: %s\n", err)
return
}
}
@ -345,7 +345,7 @@ func (ldbs *LevelDBSession) interleavedSpatialQuery(first, second []byte, done c
encodedKey []byte
)
//log.Printf("seeking to: %d", zmin)
//log.Printf("seeking to: %d\n", zmin)
it.Seek(common.ToBigEndian(zmin))
for it.Valid() {
zcode := common.FromBigEndian(it.Key())
@ -356,7 +356,7 @@ func (ldbs *LevelDBSession) interleavedSpatialQuery(first, second []byte, done c
if c := common.InterleavedToCoord(zcode); cub.Contains(c) {
if encodedKey, err = common.EncodeStringToBytes(common.CoordToPlain(c)); err != nil {
log.Printf("error encoding key: %s", err)
log.Printf("error encoding key: %s\n", err)
return
}
select {
@ -367,14 +367,14 @@ func (ldbs *LevelDBSession) interleavedSpatialQuery(first, second []byte, done c
it.Next()
} else {
next := common.BigMin(zmin, zmax, zcode)
//log.Printf("seeking to: %d", next)
//log.Printf("seeking to: %d\n", next)
it.Seek(common.ToBigEndian(next))
//log.Printf("seeking done: %d", next)
//log.Printf("seeking done: %d\n", next)
}
}
//log.Println("iterating done")
if err = it.GetError(); err != nil {
log.Printf("error while iterating: %s", err)
log.Printf("error while iterating: %s\n", err)
return
}
}()

View File

@ -122,7 +122,7 @@ func main() {
log.Fatal(err)
}
defer listener.Close()
log.Printf("Server started at %s", listener.Addr())
log.Printf("Server started at %s\n", listener.Addr())
connChan := make(chan net.Conn)
defer close(connChan)
@ -135,12 +135,12 @@ func main() {
if err != nil {
log.Fatal(err)
}
log.Printf("Client accepted from: %s", conn.RemoteAddr())
log.Printf("Client accepted from: %s\n", conn.RemoteAddr())
connChan <- conn
}
}()
log.Printf("Doing garbage collection every: %s", gcDur)
log.Printf("Doing garbage collection every: %s\n", gcDur)
gcChan := time.Tick(gcDur)
for {
@ -148,7 +148,7 @@ func main() {
case conn := <-connChan:
var session Session
if session, err = backend.NewSession(); err != nil {
log.Printf("Cannot create session: %s", err)
log.Printf("Cannot create session: %s\n", err)
conn.Close()
} else {
go NewConnection(conn, session, maxBulkStringSize).Run()

View File

@ -173,7 +173,7 @@ func asString(i interface{}) string {
func (rce *RedisCommandExecutor) execute() bool {
l := len(rce.args)
if l < 1 {
log.Printf("WARN: Too less argument for command.")
log.Println("WARN: Too less argument for command.")
return false
}
cmd := strings.ToUpper(asString(rce.args[0]))
@ -259,7 +259,7 @@ func (rce *RedisCommandExecutor) ConsumeInteger(i int64) bool {
}
func (rce *RedisCommandExecutor) ConsumeError(err error) bool {
log.Printf("error: %s", err)
log.Printf("error: %s\n", err)
return true
}

View File

@ -272,7 +272,7 @@ func (ss *SqliteSession) AllKeys(hash []byte, done chan struct{}) (keys chan []b
for rows.Next() {
var key int64
if err := rows.Scan(&key); err != nil {
log.Printf("WARN: %s", err)
log.Printf("WARN: %s\n", err)
break
}
var encoded []byte
@ -334,14 +334,14 @@ func (ss *SqliteSession) interleavedSpatialQuery(first, second []byte, done chan
rows *sql.Rows
)
if rows, err = rangeStmt.Query(zmin, zmax); err != nil {
log.Printf("Error in range query: %s", err)
log.Printf("Error in range query: %s\n", err)
return
}
for rows.Next() {
var zcode int64
var data []byte
if err = rows.Scan(&zcode, &data); err != nil {
log.Printf("Error in scanning row: %s", err)
log.Printf("Error in scanning row: %s\n", err)
rows.Close()
return
}
@ -349,7 +349,7 @@ func (ss *SqliteSession) interleavedSpatialQuery(first, second []byte, done chan
if cub.Contains(c) {
var encodedKey []byte
if encodedKey, err = common.EncodeStringToBytes(common.CoordToPlain(c)); err != nil {
log.Printf("Key encoding failed: %s", err)
log.Printf("Key encoding failed: %s\n", err)
rows.Close()
return
}
@ -366,7 +366,7 @@ func (ss *SqliteSession) interleavedSpatialQuery(first, second []byte, done chan
}
}
if err = rows.Err(); err != nil {
log.Printf("Error in range query: %s", err)
log.Printf("Error in range query: %s\n", err)
}
rows.Close()
}
@ -413,19 +413,19 @@ func (ss *SqliteSession) plainSpatialQuery(first, second []byte, done chan struc
// Ordering should not be necessary.
from, to := order(common.CoordToPlain(a), common.CoordToPlain(b))
if rows, err = rangeStmt.Query(from, to); err != nil {
log.Printf("Error in range query: %s", err)
log.Printf("Error in range query: %s\n", err)
return
}
for rows.Next() {
var key int64
var data []byte
if err = rows.Scan(&key, &data); err != nil {
log.Printf("Error in scanning row: %s", err)
log.Printf("Error in scanning row: %s\n", err)
break
}
var encodedKey []byte
if encodedKey, err = common.EncodeStringToBytes(key); err != nil {
log.Printf("Key encoding failed: %s", err)
log.Printf("Key encoding failed: %s\n", err)
break
}
select {
@ -436,7 +436,7 @@ func (ss *SqliteSession) plainSpatialQuery(first, second []byte, done chan struc
}
}
if err = rows.Err(); err != nil {
log.Printf("Error in range query: %s", err)
log.Printf("Error in range query: %s\n", err)
}
rows.Close()
}

View File

@ -77,9 +77,9 @@ func createBaseLevel(
for x, i := int16(xMin), 0; x <= int16(xMax); x += 16 {
xDir := filepath.Join(baseDir, strconv.Itoa(i))
log.Printf("creating dir: %s", xDir)
log.Printf("creating dir: %s\n", xDir)
if err = os.MkdirAll(xDir, os.ModePerm); err != nil {
log.Fatalf("Cannot create directory '%s': %s", xDir, err)
log.Fatalf("Cannot create directory '%s': %s\n", xDir, err)
}
for z, j := int16(zMin), 0; z <= int16(zMax); z += 16 {
jobs <- blockPos{x: x, z: z, i: i, j: j}

View File

@ -92,7 +92,7 @@ func main() {
numBlocks := 0
drawBlock := func(block *common.Block) {
if err := yOrder.RenderBlock(block, colors); err != nil {
log.Printf("WARN: rendering block failed: %s", err)
log.Printf("WARN: rendering block failed: %s\n", err)
}
numBlocks++
}
@ -109,7 +109,7 @@ func main() {
log.Fatalf("query failed: %s", err)
}
if err = yOrder.Drain(colors); err != nil {
log.Printf("WARN: rendering block failed: %s", err)
log.Printf("WARN: rendering block failed: %s\n", err)
}
if renderer.IsFilled() {
break

View File

@ -97,7 +97,7 @@ func (sb *subBaseLine) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
rw.Header().Set("Content-Type", "image/png")
if err = png.Encode(rw, img); err != nil {
log.Printf("WARN: encoding image failed: %s", err)
log.Printf("WARN: encoding image failed: %s\n", err)
}
}
@ -147,7 +147,7 @@ func blowUp(src image.Image) *image.RGBA {
py += dy
}
//log.Printf("Rendering took: %s", time.Since(start))
//log.Printf("Rendering took: %s\n", time.Since(start))
return dst
}
@ -185,7 +185,7 @@ func blowUpRGBA(src *image.RGBA) *image.RGBA {
py += dy
}
//log.Printf("Rendering took: %s", time.Since(start))
//log.Printf("Rendering took: %s\n", time.Since(start))
return dst
}
@ -219,7 +219,7 @@ func toUint(s string) uint {
var err error
var x int
if x, err = strconv.Atoi(s); err != nil {
log.Printf("WARN: Cannot convert to int: %s", err)
log.Printf("WARN: Cannot convert to int: %s\n", err)
return 0
}
return uint(x)

View File

@ -95,7 +95,7 @@ func (tu *tileUpdater) checkIP(r *http.Request) bool {
var host []string
if host = strings.SplitN(r.RemoteAddr, ":", 2); len(host) < 1 {
log.Printf("WARN: cannot extract host from '%s'\n", r.RemoteAddr)
log.Printf("WARN: cannot extract host from '%s'.\n", r.RemoteAddr)
return false
}
@ -116,7 +116,7 @@ func (tu *tileUpdater) checkIP(r *http.Request) bool {
func (tu *tileUpdater) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
if !tu.checkIP(r) {
log.Printf("WARN: Unauthorized update request from '%s'", r.RemoteAddr)
log.Printf("WARN: Unauthorized update request from '%s'\n", r.RemoteAddr)
http.Error(rw, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
return
}
@ -125,7 +125,7 @@ func (tu *tileUpdater) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
var newChanges []xz
decoder := json.NewDecoder(r.Body)
if err = decoder.Decode(&newChanges); err != nil {
log.Printf("WARN: JSON document broken: %s", err)
log.Printf("WARN: JSON document broken: %s\n", err)
http.Error(rw, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}
@ -163,7 +163,7 @@ func (tu *tileUpdater) doUpdates() {
var client *common.RedisClient
var err error
if client, err = common.NewRedisClient("tcp", tu.redisAddress); err != nil {
log.Printf("WARN: Cannot connect to redis server: %s", err)
log.Printf("WARN: Cannot connect to redis server: %s\n", err)
continue
}
btc := common.NewBaseTileCreator(client, tu.colors, tu.transparent, baseDir, true)
@ -174,7 +174,7 @@ func (tu *tileUpdater) doUpdates() {
parentJobs := make(map[xz]uint16)
for c := range changes {
//log.Printf("job: %+v", c)
//log.Printf("job: %+v\n", c)
jobs <- c
pxz := c.parent()
parentJobs[pxz.P] |= pxz.Mask
@ -211,7 +211,7 @@ func updatePyramidTiles(level int, baseDir string, jobs chan xzm, done *sync.Wai
for job := range jobs {
if err := updatePyramidTile(scratch, level, baseDir, job); err != nil {
log.Printf("Updating pyramid tile failed: %s", err)
log.Printf("Updating pyramid tile failed: %s\n", err)
}
}
}
@ -248,7 +248,7 @@ func updatePyramidTile(scratch *image.RGBA, level int, baseDir string, j xzm) er
for i := uint16(0); i < 4; i++ {
if j.Mask&(1<<i) != 0 {
//log.Printf("level %d: modified %d", level, i)
//log.Printf("level %d: modified %d\n", level, i)
o := ofs[i]
bx, bz := int(2*j.P.X), int(2*j.P.Z)
path := filepath.Join(
@ -266,7 +266,7 @@ func updatePyramidTile(scratch *image.RGBA, level int, baseDir string, j xzm) er
if orig == nil {
orig = common.LoadPNG(origPath)
}
//log.Printf("level %d: copied %d", level, i)
//log.Printf("level %d: copied %d\n", level, i)
min := orig.Bounds().Min.Add(dps[i])
r := image.Rectangle{min, min.Add(windowSize)}
draw.Draw(scratch, r, orig, min, draw.Src)
@ -283,7 +283,7 @@ func updateBaseTiles(jobs chan xz, btc *common.BaseTileCreator, done *sync.WaitG
xz := job.dequantize()
//log.Printf("%d/%d %d/%d", x, z, job.X, job.Z)
if err := btc.CreateTile(xz.X-1, xz.Z-1, int(job.X), int(job.Z)); err != nil {
log.Printf("WARN: create tile failed: %s", err)
log.Printf("WARN: create tile failed: %s\n", err)
}
}
}

View File

@ -78,7 +78,7 @@ func (btc *BaseTileCreator) CreateTile(x, z int16, i, j int) error {
drawBlock := func(block *Block) {
if err := btc.yOrder.RenderBlock(block, btc.colors); err != nil {
log.Printf("WARN: rendering block failed: %s", err)
log.Printf("WARN: rendering block failed: %s\n", err)
}
}
@ -111,7 +111,7 @@ func (btc *BaseTileCreator) CreateTile(x, z int16, i, j int) error {
return err
}
if err := btc.yOrder.Drain(btc.colors); err != nil {
log.Printf("WARN: rendering block failed: %s", err)
log.Printf("WARN: rendering block failed: %s\n", err)
}
}
oareas, nareas = nareas, oareas[0:0]
@ -123,7 +123,7 @@ func (btc *BaseTileCreator) CreateTile(x, z int16, i, j int) error {
path := filepath.Join(btc.baseDir, strconv.Itoa(i), fmt.Sprintf("%d.png", j))
log.Printf("Writing (%d, %d) to file %s", x, z, path)
log.Printf("Writing (%d, %d) to file %s\n", x, z, path)
if !btc.update {
return SaveAsPNG(path, image)

View File

@ -83,14 +83,14 @@ func LoadPNG(path string) image.Image {
var err error
var file *os.File
if file, err = os.Open(path); err != nil {
//log.Printf("WARN: %s", err)
//log.Printf("WARN: %s\n", err)
return image.White
}
defer file.Close()
reader := bufio.NewReader(file)
var img image.Image
if img, err = png.Decode(reader); err != nil {
log.Printf("WARN: %s", err)
log.Printf("WARN: %s\n", err)
return image.White
}
return img