Skip to content

Commit

Permalink
Add logging by callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Daan-Adrichem committed Aug 11, 2021
1 parent 17dd8c5 commit 2d79d07
Show file tree
Hide file tree
Showing 61 changed files with 23 additions and 7,235 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ jobs:
- name: Build
run: |
export LD_LIBRARY_PATH="/opt/pdfium/lib"
go build -o ./bin/pdfium.exe ./main.go
go build -o ./bin/subprocess.exe ./subprocess/main.go
go build -o ./bin/pdfium ./main.go
go build -o ./bin/subprocess ./subprocess/main.go
- name: Archive production artifacts
uses: actions/upload-artifact@v2
with:
name: binary
path: |
./bin/pdfium.exe
./bin/subprocess.exe
./bin/pdfium
./bin/subprocess
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ module github.com/klippa-app/go-pdfium
go 1.15

require (
github.com/getsentry/sentry-go v0.5.1
github.com/golang/protobuf v1.4.2 // indirect
github.com/google/go-cmp v0.5.2 // indirect
github.com/hashicorp/go-hclog v0.14.1
github.com/hashicorp/go-plugin v1.4.0
github.com/jolestar/go-commons-pool/v2 v2.1.1
github.com/kr/pretty v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.6.0
github.com/stretchr/testify v1.7.0
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0 // indirect
google.golang.org/genproto v0.0.0-20200521103424-e9a78aa275b7 // indirect
Expand Down
144 changes: 0 additions & 144 deletions go.sum

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package main

import "github.com/klippa-app/go-pdfium/pdfium"
import (
"fmt"

"github.com/klippa-app/go-pdfium/pdfium"
)

func main() {
pdfium.InitLibrary(pdfium.Config{
MinIdle: 1,
MaxIdle: 1,
MaxTotal: 1,
LogCallback: func(s string) {
fmt.Println("[PDFIUM ERROR]: " + s)
},
})
}
21 changes: 8 additions & 13 deletions pdfium/pdfium.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import (
pool "github.com/jolestar/go-commons-pool/v2"
"github.com/klippa-app/go-pdfium/pdfium/internal/commons"

"github.com/getsentry/sentry-go"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
log "github.com/sirupsen/logrus"
)

type worker struct {
Expand All @@ -27,9 +25,10 @@ type worker struct {
var workerPool *pool.ObjectPool

type Config struct {
MinIdle int
MaxIdle int
MaxTotal int
MinIdle int
MaxIdle int
MaxTotal int
LogCallback func(string)
}

func InitLibrary(config Config) { // serve one thread that is "native" through cgo
Expand Down Expand Up @@ -95,29 +94,25 @@ func InitLibrary(config Config) { // serve one thread that is "native" through c
}, nil, func(ctx goctx.Context, object *pool.PooledObject) bool {
worker := object.Object.(*worker)
if worker.pluginClient.Exited() {
log.Println("[pdfium error] Worker exited")
sentry.CaptureException(fmt.Errorf("[pdfium error] Worker exited"))
config.LogCallback("Worker exited")
return false
}

err := worker.rpcClient.Ping()
if err != nil {
log.Printf("[pdfium error] Error on RPC ping: %s", err.Error())
sentry.CaptureException(fmt.Errorf("[pdfium error] Error on RPC ping: %s", err.Error()))
config.LogCallback(fmt.Sprintf("Error on RPC ping: %s", err.Error()))
return false
}

pong, err := worker.plugin.Ping()
if err != nil {
log.Printf("[pdfium error] Error on plugin ping: %s", err.Error())
sentry.CaptureException(fmt.Errorf("[pdfium error] Error on plugin ping: %s", err.Error()))
config.LogCallback(fmt.Sprintf("Error on plugin ping:: %s", err.Error()))
return false
}

if pong != "Pong" {
err = errors.New("Wrong ping/pong result")
log.Printf("[pdfium error] Error on plugin ping: %s", err.Error())
sentry.CaptureException(fmt.Errorf("[pdfium error] Error on plugin ping: %s", err.Error()))
config.LogCallback(fmt.Sprintf("Error on plugin ping:: %s", err.Error()))
return false
}

Expand Down
19 changes: 0 additions & 19 deletions vendor/github.com/getsentry/sentry-go/.craft.yml

This file was deleted.

6 changes: 0 additions & 6 deletions vendor/github.com/getsentry/sentry-go/.gitignore

This file was deleted.

50 changes: 0 additions & 50 deletions vendor/github.com/getsentry/sentry-go/.golangci.yml

This file was deleted.

49 changes: 0 additions & 49 deletions vendor/github.com/getsentry/sentry-go/.travis.yml

This file was deleted.

Loading

0 comments on commit 2d79d07

Please sign in to comment.