-
Notifications
You must be signed in to change notification settings - Fork 103
feat: add toolkit logging impl #202
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
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f93e427
feat: toolkit log impl
ShyunnY 46d479e
test: toolkit logging pluging test
ShyunnY f71d786
fix: add logging item in CI
ShyunnY 75ed46e
Merge branch 'main' into log-impl
wu-sheng fc35d08
fix: rename plugins/toolkit and undefine a duplicate interface
ShyunnY d15ddbd
Merge branch 'log-impl' into log-test
ShyunnY e312a8c
fix: add change record
ShyunnY 24e21a4
fix: refact getLogContext logic
ShyunnY 760c6f9
fix: fix compile error
ShyunnY 56203b4
test: add getLogContext related unit test
ShyunnY 3819119
fix: fix toolkit logging package nameing
ShyunnY 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
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
File renamed without changes.
File renamed without changes.
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
33 changes: 33 additions & 0 deletions
33
plugins/toolkit-activation/logging/debug_entry_intercepter.go
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,33 @@ | ||
// Licensed to Apache Software Foundation (ASF) under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Apache Software Foundation (ASF) 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 log | ||
ShyunnY marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import ( | ||
"github.com/apache/skywalking-go/plugins/core/operator" | ||
) | ||
|
||
type DebugEntryInterceptor struct{} | ||
|
||
func (h *DebugEntryInterceptor) BeforeInvoke(invocation operator.Invocation) error { | ||
sendLogEntry(debugLevel, invocation.Args()...) | ||
return nil | ||
} | ||
|
||
func (h *DebugEntryInterceptor) AfterInvoke(_ operator.Invocation, _ ...interface{}) error { | ||
return nil | ||
} |
31 changes: 31 additions & 0 deletions
31
plugins/toolkit-activation/logging/error_entry_intercepter.go
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,31 @@ | ||
// Licensed to Apache Software Foundation (ASF) under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Apache Software Foundation (ASF) 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 log | ||
|
||
import "github.com/apache/skywalking-go/plugins/core/operator" | ||
|
||
type ErrorEntryInterceptor struct{} | ||
|
||
func (h *ErrorEntryInterceptor) BeforeInvoke(invocation operator.Invocation) error { | ||
sendLogEntry(errorLevel, invocation.Args()...) | ||
return nil | ||
} | ||
|
||
func (h *ErrorEntryInterceptor) AfterInvoke(_ operator.Invocation, _ ...interface{}) error { | ||
return nil | ||
} |
31 changes: 31 additions & 0 deletions
31
plugins/toolkit-activation/logging/info_entry_intercepter.go
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,31 @@ | ||
// Licensed to Apache Software Foundation (ASF) under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Apache Software Foundation (ASF) 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 log | ||
|
||
import "github.com/apache/skywalking-go/plugins/core/operator" | ||
|
||
type InfoEntryInterceptor struct{} | ||
|
||
func (h *InfoEntryInterceptor) BeforeInvoke(invocation operator.Invocation) error { | ||
sendLogEntry(infoLevel, invocation.Args()...) | ||
return nil | ||
} | ||
|
||
func (h *InfoEntryInterceptor) AfterInvoke(_ operator.Invocation, _ ...interface{}) error { | ||
return nil | ||
} |
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,60 @@ | ||
// Licensed to Apache Software Foundation (ASF) under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Apache Software Foundation (ASF) 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 log | ||
|
||
import ( | ||
"github.com/apache/skywalking-go/plugins/core/operator" | ||
) | ||
|
||
const ( | ||
debugLevel = "debug" | ||
infoLevel = "info" | ||
warnLevel = "warn" | ||
errorLevel = "error" | ||
) | ||
|
||
func sendLogEntry(level string, args ...interface{}) { | ||
if len(args) == 0 { | ||
return | ||
} | ||
logReporter, ok := operator.GetOperator().LogReporter().(operator.LogReporter) | ||
if !ok || logReporter == nil { | ||
return | ||
} | ||
|
||
msg := args[0].(string) | ||
labels := parseLabels(args[1]) | ||
logReporter.ReportLog(logReporter.GetLogContext(true), args[1], level, msg, labels) | ||
} | ||
|
||
// parseLabels parses multiple args into a map of labels | ||
func parseLabels(args interface{}) map[string]string { | ||
keyValues, ok := args.([]string) | ||
if !ok || len(keyValues) < 2 { | ||
return nil | ||
} | ||
|
||
ret := make(map[string]string) | ||
for i := 0; i < len(keyValues); i += 2 { | ||
v1 := keyValues[i] | ||
v2 := keyValues[i+1] | ||
ret[v1] = v2 | ||
} | ||
|
||
return ret | ||
} |
Oops, something went wrong.
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.