-
Notifications
You must be signed in to change notification settings - Fork 407
feat: add frankenphp_log_message() as a PHP function
#1979
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
0f0d182
ee4dbbb
ee7d418
ba25c2c
68345ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -682,6 +682,42 @@ func go_log(threadIndex C.uintptr_t, message *C.char, level C.int) { | |||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| //export go_log_attrs | ||||||||||||||||||||||||||||||||||||||||
| func go_log_attrs(threadIndex C.uintptr_t, message *C.char, len C.int, level C.int, cattrs *C.zval) *C.char { | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
| func go_log_attrs(threadIndex C.uintptr_t, message *C.char, len C.int, level C.int, cattrs *C.zval) *C.char { | |
| func go_log_attrs(threadIndex C.uintptr_t, message *C.zend_string, level C.zend_long, cattrs *C.zval) *C.char { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AlliBalliBaba marked this conversation as resolved.
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| m := C.GoStringN(message, len) | |
| lvl := slog.Level(level) | |
| ctx := phpThreads[threadIndex].context() | |
| if globalLogger.Enabled(ctx, lvl) { | |
| globalLogger.LogAttrs(ctx, lvl, m, mapToAttr(attrs)...) | |
| } | |
| return nil | |
| } | |
| ctx := phpThreads[threadIndex].context() | |
| if globalLogger.Enabled(ctx, lvl) { | |
| globalLogger.LogAttrs(ctx, slog.Level(level), GoString(unsafe.Pointer(m)), mapToAttr(attrs)...) | |
| } | |
| return nil | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php | ||
|
|
||
| // NOTE: use CGO frankenphp_log method. | ||
| // The message and it's optional arguments are expected to be logged by go' std slog system. | ||
| // The log level should be respected out of the box by the std' slog. | ||
| // | ||
| // ac[0] expect the log message as string | ||
| // ac[1] expect the slog.Level, from -8 to +8 | ||
| // ac[2] is an optional php map, which will be converted to a []slog.Attr | ||
|
|
||
| frankenphp_log("some debug message", -4, [ | ||
| "key int" => 1, | ||
| ]); | ||
|
|
||
| frankenphp_log("some info message", 0, [ | ||
| "key string" => "string", | ||
| ]); | ||
|
|
||
| frankenphp_log("some warn message", 4); | ||
|
|
||
| frankenphp_log("some error message", 8, [ | ||
| "err" => ["a", "v"], | ||
| ]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
68345ec