-
Notifications
You must be signed in to change notification settings - Fork 87
[APIP + AIWS] Enhance logging and configuration in platform API #2477
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
Merged
Thushani-Jayasekera
merged 5 commits into
wso2:main
from
Thushani-Jayasekera:improvements
Jul 7, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f85d42a
Enhance logging and configuration in platform API
Thushani-Jayasekera b29be61
Merge remote-tracking branch 'upstream/main' into improvements
Thushani-Jayasekera 70b5f1e
Fix merge conflicts
Thushani-Jayasekera 4892663
Refactor startup banner for platform API and AI Workspace BFF
Thushani-Jayasekera 988a045
Enhance logging configuration for AI Workspace BFF
Thushani-Jayasekera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,10 @@ type Config struct { | |
| Addr string // host:port to listen on, e.g. ":5380" | ||
| StaticDir string // directory containing the built SPA (index.html + assets) | ||
|
|
||
| // Logging | ||
| LogLevel string // "debug" | "info" | "warn" | "error" (default "info") | ||
| LogFormat string // "text" | "json" (default "text") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: new configs for ai workspace |
||
|
|
||
| // TLS for the BFF listener | ||
| TLS TLSConfig | ||
|
|
||
|
|
@@ -201,6 +205,8 @@ func Load() (*Config, error) { | |
| cfg := &Config{ | ||
| Addr: getenv("BFF_ADDR", ":5380"), | ||
| StaticDir: getenv("STATIC_DIR", "/app"), | ||
| LogLevel: strings.ToLower(getenv("LOG_LEVEL", "info")), | ||
| LogFormat: strings.ToLower(getenv("LOG_FORMAT", "text")), | ||
| TLS: TLSConfig{ | ||
| SelfSigned: selfSigned, | ||
| // Convention matches the legacy entrypoint.sh mount path. buildTLS | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| * Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com). | ||
| * | ||
| * WSO2 LLC. licenses this file to you under the Apache License, | ||
| * Version 2.0 (the "License"); you may not use this file except | ||
| * in compliance with the License. You may obtain a copy of the | ||
| * License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| // Package logger builds the BFF's process-wide slog logger. It mirrors | ||
| // platform-api's internal/logger package so both services produce logs of | ||
| // the same shape; keep the two in sync if one changes. | ||
| package logger | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "log/slog" | ||
| "os" | ||
| "strings" | ||
| ) | ||
|
|
||
| // Config holds logger configuration. | ||
| type Config struct { | ||
| Level string // "debug", "info", "warn", "error" | ||
| Format string // "text" (default) or "json" | ||
| } | ||
|
|
||
| // NewLogger creates a new slog logger with configurable log level and format. | ||
| func NewLogger(cfg Config) *slog.Logger { | ||
| level := ParseLevel(cfg.Level) | ||
|
|
||
| opts := &slog.HandlerOptions{ | ||
| Level: level, | ||
| AddSource: true, | ||
| ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr { | ||
| if a.Key == slog.SourceKey { | ||
| if src, ok := a.Value.Any().(*slog.Source); ok { | ||
| return slog.String("source", fmt.Sprintf("%s:%d", shortenSource(src.File), src.Line)) | ||
| } | ||
| } | ||
| return a | ||
| }, | ||
| } | ||
|
|
||
| var handler slog.Handler | ||
| if strings.ToLower(cfg.Format) == "json" { | ||
| handler = slog.NewJSONHandler(os.Stdout, opts) | ||
| } else { | ||
| // Default to text. | ||
| handler = slog.NewTextHandler(os.Stdout, opts) | ||
| } | ||
|
|
||
| return slog.New(handler) | ||
| } | ||
|
|
||
| // shortenSource turns an absolute compile-time file path into a compact, | ||
| // module-relative one so logs read e.g. "server/server.go" instead of the full | ||
| // filesystem path. It handles both a local build (".../ai-workspace-bff/internal/...") | ||
| // and the BFF imported as a dependency (".../ai-workspace-bff@v1.2.3/internal/..."). | ||
| // The "internal/" prefix is dropped; other roots are kept. Paths outside the | ||
| // ai-workspace-bff module (e.g. other modules) are returned as-is. | ||
| func shortenSource(file string) string { | ||
| const mod = "ai-workspace-bff" | ||
| idx := strings.LastIndex(file, mod) | ||
| if idx == -1 { | ||
| return file | ||
| } | ||
| rest := file[idx+len(mod):] | ||
| // Module-cache paths carry an "@version" segment right after the module dir. | ||
| if strings.HasPrefix(rest, "@") { | ||
| if slash := strings.IndexByte(rest, '/'); slash != -1 { | ||
| rest = rest[slash:] | ||
| } | ||
| } | ||
| rest = strings.TrimPrefix(rest, "/") | ||
| if rest == "" { | ||
| return file | ||
| } | ||
| return strings.TrimPrefix(rest, "internal/") | ||
| } | ||
|
|
||
| // ParseLevel converts a log level string to slog.Level. | ||
| func ParseLevel(level string) slog.Level { | ||
| switch strings.ToLower(level) { | ||
| case "debug": | ||
| return slog.LevelDebug | ||
| case "info": | ||
| return slog.LevelInfo | ||
| case "warn", "warning": | ||
| return slog.LevelWarn | ||
| case "error": | ||
| return slog.LevelError | ||
| default: | ||
| return slog.LevelInfo | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.