Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ipfs/go-log
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.2
Choose a base ref
...
head repository: ipfs/go-log
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.3
Choose a head ref
  • 6 commits
  • 7 files changed
  • 2 contributors

Commits on Mar 24, 2020

  1. ci: circle

    Stebalien committed Mar 24, 2020
    Copy the full SHA
    f48534c View commit details
  2. chore: fix lint issues

    Stebalien committed Mar 24, 2020
    Copy the full SHA
    f525860 View commit details
  3. Merge pull request #75 from ipfs/feat/circle-ci

    ci: circle
    Stebalien authored Mar 24, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    125e1f0 View commit details
  4. fix: normalize paths on windows

    Fixes #73 by normalizing paths to UNC on windows. This is _slightly_ less hacky
    than registering a new schema.
    
    The underlying issue was twofold:
    
    1. When specifying a windows file URL as `file://c:/foo/bar`, go barfs because
    `:` can't be in a domain name.
    2. When specifying a windows file URL as `file:///c:/foo/bar`, we'd end up
    trying to open `/c:/foo/bar` which is actually `CURRENT_DRIVE:/c:/foo/bar`.
    Stebalien committed Mar 24, 2020
    Copy the full SHA
    45b384f View commit details
  5. Copy the full SHA
    be98d3d View commit details
  6. Merge pull request #74 from ipfs/fix/log-path-windows

    fix: normalize paths on windows
    Stebalien authored Mar 24, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6277577 View commit details
Showing with 79 additions and 40 deletions.
  1. +14 −0 .circleci/config.yml
  2. +0 −31 .travis.yml
  3. +0 −2 log.go
  4. +12 −3 logbench_test.go
  5. +11 −0 path_other.go
  6. +35 −0 path_windows.go
  7. +7 −4 setup.go
14 changes: 14 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2.1
orbs:
ci-go: ipfs/ci-go@0.2.4

workflows:
version: 2
test:
jobs:
- ci-go/build
- ci-go/lint
- ci-go/test
- ci-go/test:
race: true
name: "ci-go/test/race"
31 changes: 0 additions & 31 deletions .travis.yml

This file was deleted.

2 changes: 0 additions & 2 deletions log.go
Original file line number Diff line number Diff line change
@@ -9,8 +9,6 @@ import (
"go.uber.org/zap"
)

var log = Logger("eventlog")

// StandardLogger provides API compatibility with standard printf loggers
// eg. go-logging
type StandardLogger interface {
15 changes: 12 additions & 3 deletions logbench_test.go
Original file line number Diff line number Diff line change
@@ -12,7 +12,10 @@ import (

func BenchmarkSimpleInfo(b *testing.B) {
l := Logger("bench")
SetLogLevel("bench", "info")
err := SetLogLevel("bench", "info")
if err != nil {
b.Fatal(err)
}

b.ResetTimer()
b.ReportAllocs()
@@ -25,7 +28,10 @@ var logString = "String, IDK what to write, let's punch a keyboard. jkdlsjklfdjf

func BenchmarkFormatInfo(b *testing.B) {
l := Logger("bench")
SetLogLevel("bench", "info")
err := SetLogLevel("bench", "info")
if err != nil {
b.Fatal(err)
}

b.ResetTimer()
b.ReportAllocs()
@@ -36,7 +42,10 @@ func BenchmarkFormatInfo(b *testing.B) {

func BenchmarkFormatInfoMulti(b *testing.B) {
l := Logger("bench")
SetLogLevel("bench", "info")
err := SetLogLevel("bench", "info")
if err != nil {
b.Fatal(err)
}
var wg sync.WaitGroup

goroutines := 16
11 changes: 11 additions & 0 deletions path_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//+build !windows

package log

import (
"path/filepath"
)

func normalizePath(p string) (string, error) {
return filepath.Abs(p)
}
35 changes: 35 additions & 0 deletions path_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//+build windows

package log

import (
"fmt"
"path/filepath"
"strings"
)

func normalizePath(p string) (string, error) {
if p == "" {
return "", fmt.Errorf("path empty")
}
p, err := filepath.Abs(p)
if err != nil {
return "", err
}
// Is this _really_ an absolute path?
if !strings.HasPrefix(p, "\\\\") {
// It's a drive: path!
// Return a UNC path.
p = "\\\\%3F\\" + p
}

// This will return file:////?/c:/foobar
//
// Why? Because:
// 1. Go will choke on file://c:/ because the "domain" includes a :.
// 2. Windows will choke on file:///c:/ because the path will be
// /c:/... which is _relative_ to the current drive.
//
// This path (a) has no "domain" and (b) starts with a slash. Yay!
return "file://" + filepath.ToSlash(p), nil
}
11 changes: 7 additions & 4 deletions setup.go
Original file line number Diff line number Diff line change
@@ -28,8 +28,7 @@ const (
envLogging = "GOLOG_LOG_LEVEL"
envLoggingFmt = "GOLOG_LOG_FMT"

envLoggingFile = "GOLOG_FILE" // /path/to/file
envTracingFile = "GOLOG_TRACING_FILE" // /path/to/file
envLoggingFile = "GOLOG_FILE" // /path/to/file
)

// ErrNoSuchLogger is returned when the util pkg is asked for a non existant logger
@@ -69,7 +68,11 @@ func SetupLogging() {
zapCfg.OutputPaths = []string{"stderr"}
// check if we log to a file
if logfp := os.Getenv(envLoggingFile); len(logfp) > 0 {
zapCfg.OutputPaths = append(zapCfg.OutputPaths, logfp)
if path, err := normalizePath(logfp); err != nil {
fmt.Fprintf(os.Stderr, "failed to resolve log path '%q', logging to stderr only: %s\n", logfp, err)
} else {
zapCfg.OutputPaths = append(zapCfg.OutputPaths, path)
}
}

// set the backend(s)
@@ -84,7 +87,7 @@ func SetupLogging() {
var err error
lvl, err = LevelFromString(logenv)
if err != nil {
fmt.Println("error setting log levels", err)
fmt.Fprintf(os.Stderr, "error setting log levels: %s\n", err)
}
}
zapCfg.Level.SetLevel(zapcore.Level(lvl))