-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-9975] logging: Docs and Examples
Change-Id: I22e58542d88cabf1b9b1111268155944eb882ce2 Signed-off-by: Firas Qutishat <firas.qutishat@securekey.com>
- Loading branch information
Showing
2 changed files
with
142 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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,117 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package logging | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hyperledger/fabric-sdk-go/pkg/core/logging/testdata" | ||
) | ||
|
||
var modName = "module-xyz" | ||
|
||
func Example() { | ||
|
||
Initialize(testdata.GetSampleLoggingProvider(&buf)) | ||
//Create new logger | ||
logger := NewLogger(modName) | ||
|
||
logger.Info("log test data") | ||
|
||
fmt.Println("log info is completed") | ||
|
||
// Output: log info is completed | ||
|
||
} | ||
|
||
func ExampleNewLogger() { | ||
|
||
Initialize(testdata.GetSampleLoggingProvider(&buf)) | ||
//Create new logger | ||
NewLogger(modName) | ||
|
||
fmt.Println("log is completed") | ||
|
||
// Output: log is completed | ||
|
||
} | ||
|
||
func ExampleInitialize() { | ||
|
||
Initialize(testdata.GetSampleLoggingProvider(&buf)) | ||
|
||
fmt.Println("log is completed") | ||
|
||
// Output: log is completed | ||
|
||
} | ||
|
||
func ExampleSetLevel() { | ||
|
||
Initialize(testdata.GetSampleLoggingProvider(&buf)) | ||
|
||
SetLevel(modName, INFO) | ||
|
||
fmt.Println("log is completed") | ||
|
||
// Output: log is completed | ||
|
||
} | ||
|
||
func ExampleGetLevel() { | ||
|
||
Initialize(testdata.GetSampleLoggingProvider(&buf)) | ||
|
||
SetLevel(modName, DEBUG) | ||
|
||
l := GetLevel(modName) | ||
if l != DEBUG { | ||
fmt.Println("log level is not debug") | ||
return | ||
} | ||
|
||
fmt.Println("log is completed") | ||
|
||
// Output: log is completed | ||
|
||
} | ||
|
||
func ExampleIsEnabledFor() { | ||
|
||
Initialize(testdata.GetSampleLoggingProvider(&buf)) | ||
|
||
isEnabled := IsEnabledFor(modName, DEBUG) | ||
|
||
if !isEnabled { | ||
fmt.Println("log level debug is enabled") | ||
return | ||
} | ||
|
||
fmt.Println("log is completed") | ||
|
||
// Output: log is completed | ||
|
||
} | ||
|
||
func ExampleLogLevel() { | ||
|
||
Initialize(testdata.GetSampleLoggingProvider(&buf)) | ||
|
||
level, err := LogLevel("debug") | ||
if err != nil { | ||
fmt.Printf("failed LogLevel: %v", err) | ||
return | ||
} | ||
|
||
if level != DEBUG { | ||
fmt.Println("log level is not debug") | ||
return | ||
} | ||
fmt.Println("log is completed") | ||
|
||
// Output: log is completed | ||
|
||
} |
This file contains 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