diff --git a/.golangci.yml b/.golangci.yml index 5af1f808..a26b2eb4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -29,7 +29,6 @@ linters: - gci - ginkgolinter - gocheckcompilerdirectives - - gochecknoinits - gochecksumtype - gocognit - goconst @@ -104,6 +103,7 @@ linters: - exhaustruct - funlen - gochecknoglobals + - gochecknoinits - gomnd - lll - nlreturn diff --git a/context.go b/context.go index 4bf2ab9b..e99d6383 100644 --- a/context.go +++ b/context.go @@ -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 @@ -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() @@ -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)