Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disable logging by default and add SetLogLevel functions #24

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ linters:
- gci
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoinits
- gochecksumtype
- gocognit
- goconst
Expand Down Expand Up @@ -104,6 +103,7 @@ linters:
- exhaustruct
- funlen
- gochecknoglobals
- gochecknoinits
- gomnd
- lll
- nlreturn
Expand Down
26 changes: 26 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,22 @@ import (
"unsafe"
)

type LogLevel C.PJ_LOG_LEVEL

const (
LogLevelNone LogLevel = C.PJ_LOG_NONE
LogLevelError LogLevel = C.PJ_LOG_ERROR
LogLevelDebug LogLevel = C.PJ_LOG_DEBUG
LogLevelTrace LogLevel = C.PJ_LOG_TRACE
LogLevelTell LogLevel = C.PJ_LOG_TELL
)

var defaultContext = &Context{}

func init() {
C.proj_log_level(nil, C.PJ_LOG_NONE)
}

// A Context is a context.
type Context struct {
mutex sync.Mutex
Expand Down Expand Up @@ -39,6 +53,13 @@ func (c *Context) Destroy() {
}
}

// SetLogLevel sets the log level.
func (c *Context) SetLogLevel(logLevel LogLevel) {
c.Lock()
defer c.Unlock()
C.proj_log_level(c.pjContext, C.PJ_LOG_LEVEL(logLevel))
}

// SetSearchPaths sets the paths PROJ should be exploring to find the PROJ Data files.
func (c *Context) SetSearchPaths(paths []string) {
c.Lock()
Expand Down Expand Up @@ -167,6 +188,11 @@ func (c *Context) newPJ(cPJ *C.PJ) (*PJ, error) {
return pj, nil
}

// SetLogLevel sets the log level for the default context.
func SetLogLevel(logLevel LogLevel) {
defaultContext.SetLogLevel(logLevel)
}

// New returns a PJ with the given definition.
func New(definition string) (*PJ, error) {
return defaultContext.New(definition)
Expand Down