mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-04 22:43:12 +00:00
Add log level
This commit is contained in:
parent
9c286e5b50
commit
66e3fde545
@ -96,6 +96,10 @@ package main
|
||||
return codex_peer_id(codexCtx, (CodexCallback) callback, resp);
|
||||
}
|
||||
|
||||
static int cGoCodexLogLevel(void* codexCtx, char* logLevel, void* resp) {
|
||||
return codex_log_level(codexCtx, logLevel, (CodexCallback) callback, resp);
|
||||
}
|
||||
|
||||
static int cGoCodexStart(void* codexCtx, void* resp) {
|
||||
return codex_start(codexCtx, (CodexCallback) callback, resp);
|
||||
}
|
||||
@ -405,6 +409,21 @@ func (self *CodexNode) CodexPeerId() (string, error) {
|
||||
return bridge.wait()
|
||||
}
|
||||
|
||||
func (self *CodexNode) CodexLogLevel(logLevel LogLevel) error {
|
||||
bridge := newBridgeCtx()
|
||||
defer bridge.free()
|
||||
|
||||
var cLogLevel = C.CString(fmt.Sprintf("%s", logLevel))
|
||||
defer C.free(unsafe.Pointer(cLogLevel))
|
||||
|
||||
if C.cGoCodexLogLevel(self.ctx, cLogLevel, bridge.resp) != C.RET_OK {
|
||||
return bridge.CallError("cGoCodexLogLevel")
|
||||
}
|
||||
|
||||
_, err := bridge.wait()
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *CodexNode) CodexStart() error {
|
||||
bridge := newBridgeCtx()
|
||||
defer bridge.free()
|
||||
@ -545,6 +564,13 @@ func main() {
|
||||
|
||||
log.Println("Codex Peer Id:", peerId)
|
||||
|
||||
err = node.CodexLogLevel(Trace)
|
||||
if err != nil {
|
||||
log.Fatal("Error happened:", err.Error())
|
||||
}
|
||||
|
||||
log.Println("Codex Log Level set to TRACE")
|
||||
|
||||
// Wait for a SIGINT or SIGTERM signal
|
||||
ch := make(chan os.Signal, 1)
|
||||
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
@ -3,9 +3,8 @@
|
||||
import std/[options]
|
||||
import chronos
|
||||
import chronicles
|
||||
# import confutils
|
||||
import codexdht/discv5/spr
|
||||
# import ../../../codex/conf
|
||||
import ../../../codex/conf
|
||||
import ../../../codex/rest/json
|
||||
import ../../../codex/node
|
||||
|
||||
|
||||
@ -60,6 +60,12 @@ int codex_peer_id(
|
||||
CodexCallback callback,
|
||||
void* userData);
|
||||
|
||||
int codex_log_level(
|
||||
void* ctx,
|
||||
const char* logLevel,
|
||||
CodexCallback callback,
|
||||
void* userData);
|
||||
|
||||
int codex_start(void* ctx,
|
||||
CodexCallback callback,
|
||||
void* userData);
|
||||
|
||||
@ -34,7 +34,7 @@ import ./codex_thread_requests/requests/node_info_request
|
||||
import ./codex_thread_requests/requests/node_debug_request
|
||||
import ./ffi_types
|
||||
|
||||
from ../codex/conf import codexVersion
|
||||
from ../codex/conf import codexVersion, updateLogLevel
|
||||
|
||||
template checkLibcodexParams*(
|
||||
ctx: ptr CodexContext, callback: CodexCallback, userData: pointer
|
||||
@ -198,6 +198,26 @@ proc codex_peer_id(
|
||||
|
||||
return RET_OK
|
||||
|
||||
## Set the log level of the library at runtime.
|
||||
## It uses updateLogLevel which is a synchronous proc and
|
||||
## cannot be used inside an async context because of gcsafe issue.
|
||||
proc codex_log_level(
|
||||
ctx: ptr CodexContext, logLevel: cstring, callback: CodexCallback, userData: pointer
|
||||
): cint {.dynlib, exportc.} =
|
||||
initializeLibrary()
|
||||
checkLibcodexParams(ctx, callback, userData)
|
||||
|
||||
try:
|
||||
updateLogLevel($logLevel)
|
||||
except ValueError as e:
|
||||
let msg = "Cannot set log level: " & $e.msg
|
||||
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
|
||||
return RET_ERR
|
||||
|
||||
callback(RET_OK, cast[ptr cchar](""), cast[csize_t](len("")), userData)
|
||||
|
||||
return RET_OK
|
||||
|
||||
proc codex_destroy(
|
||||
ctx: ptr CodexContext, callback: CodexCallback, userData: pointer
|
||||
): cint {.dynlib, exportc.} =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user