mirror of
https://github.com/dunglas/frankenphp.git
synced 2025-12-24 13:38:11 +08:00
fix: crash when using the logger outside of the a request context
This commit is contained in:
committed by
Kévin Dunglas
parent
4092ecb5b5
commit
25d9cb9600
@@ -660,10 +660,28 @@ func go_read_cookies(threadIndex C.uintptr_t) *C.char {
|
|||||||
return C.CString(cookie)
|
return C.CString(cookie)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getLogger(threadIndex C.uintptr_t) (*slog.Logger, context.Context) {
|
||||||
|
ctxHolder := phpThreads[threadIndex]
|
||||||
|
if ctxHolder == nil {
|
||||||
|
return globalLogger, globalCtx
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := ctxHolder.context()
|
||||||
|
if ctxHolder.handler == nil {
|
||||||
|
return globalLogger, ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
fCtx := ctxHolder.frankenPHPContext()
|
||||||
|
if fCtx == nil || fCtx.logger == nil {
|
||||||
|
return globalLogger, ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
return fCtx.logger, ctx
|
||||||
|
}
|
||||||
|
|
||||||
//export go_log
|
//export go_log
|
||||||
func go_log(threadIndex C.uintptr_t, message *C.char, level C.int) {
|
func go_log(threadIndex C.uintptr_t, message *C.char, level C.int) {
|
||||||
ctx := phpThreads[threadIndex].context()
|
logger, ctx := getLogger(threadIndex)
|
||||||
logger := phpThreads[threadIndex].frankenPHPContext().logger
|
|
||||||
|
|
||||||
m := C.GoString(message)
|
m := C.GoString(message)
|
||||||
le := syslogLevelInfo
|
le := syslogLevelInfo
|
||||||
@@ -697,8 +715,7 @@ func go_log(threadIndex C.uintptr_t, message *C.char, level C.int) {
|
|||||||
|
|
||||||
//export go_log_attrs
|
//export go_log_attrs
|
||||||
func go_log_attrs(threadIndex C.uintptr_t, message *C.zend_string, cLevel C.zend_long, cAttrs *C.zval) *C.char {
|
func go_log_attrs(threadIndex C.uintptr_t, message *C.zend_string, cLevel C.zend_long, cAttrs *C.zval) *C.char {
|
||||||
ctx := phpThreads[threadIndex].context()
|
logger, ctx := getLogger(threadIndex)
|
||||||
logger := phpThreads[threadIndex].frankenPHPContext().logger
|
|
||||||
|
|
||||||
level := slog.Level(cLevel)
|
level := slog.Level(cLevel)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user