Skip to content

Commit

Permalink
Merge pull request #62 from subeshb1/maint-2.2
Browse files Browse the repository at this point in the history
Implement Accessible to check if context filter is injected for JSONLogFormatter
  • Loading branch information
benhalstead authored Sep 11, 2020
2 parents 26c204b + 68f0c1a commit 5ccaeb3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
13 changes: 7 additions & 6 deletions granitic.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,23 @@ import (
"bytes"
"encoding/base64"
"encoding/gob"
"os"
"os/signal"
"runtime"
"syscall"
"time"

"github.com/graniticio/granitic/v2/config"
"github.com/graniticio/granitic/v2/facility"
"github.com/graniticio/granitic/v2/instance"
"github.com/graniticio/granitic/v2/ioc"
"github.com/graniticio/granitic/v2/logging"
"github.com/graniticio/granitic/v2/uuid"
"os"
"os/signal"
"runtime"
"syscall"
"time"
)

const (
//Version is the semantic version number for this version of Granitic
Version = "2.2.1"
Version = "2.2.2"
initiatorComponentName string = instance.FrameworkPrefix + "Init"
systemPath = "System"
configAccessorComponentName string = instance.FrameworkPrefix + "Accessor"
Expand Down
9 changes: 5 additions & 4 deletions logging/structured.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/graniticio/granitic/v2/instance"
"github.com/graniticio/granitic/v2/types"
"strings"
"time"

"github.com/graniticio/granitic/v2/instance"
"github.com/graniticio/granitic/v2/types"
)

// A JSONLogFormatter is a component able to take a message to be written to a log file and format it as JSON document
Expand All @@ -30,8 +31,8 @@ func (jlf *JSONLogFormatter) Format(ctx context.Context, levelLabel, loggerName,
return cfg.Prefix + string(entry) + cfg.Suffix
}

// StartComponent checks that a context filter has been injected (if the field configuration needs on)
func (jlf *JSONLogFormatter) StartComponent() error {
// AllowAccess checks that a context filter has been injected (if the field configuration needs on)
func (jlf *JSONLogFormatter) AllowAccess() error {

mb := jlf.MapBuilder

Expand Down
11 changes: 6 additions & 5 deletions logging/structured_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ package logging

import (
"context"
"github.com/graniticio/granitic/v2/instance"
"strings"
"testing"

"github.com/graniticio/granitic/v2/instance"
)

func TestUnsupportedContent(t *testing.T) {
Expand Down Expand Up @@ -141,7 +142,7 @@ func TestMissingContextFilter(t *testing.T) {
jf.Config = &cfg
jf.MapBuilder = mb

if jf.StartComponent() == nil {
if jf.AllowAccess() == nil {
t.Fatalf("Failed to detect missing context filter")
}

Expand Down Expand Up @@ -171,7 +172,7 @@ func TestContextVal(t *testing.T) {

jf.SetContextFilter(cf)

if jf.StartComponent() != nil {
if jf.AllowAccess() != nil {
t.Fatalf("Failed to detect supplied context filter")
}

Expand Down Expand Up @@ -323,7 +324,7 @@ func TestMessageFromStackTrace(t *testing.T) {

jf.SetContextFilter(cf)

if jf.StartComponent() != nil {
if jf.AllowAccess() != nil {
t.Fatalf("Failed to detect supplied context filter")
}

Expand Down Expand Up @@ -369,7 +370,7 @@ func TestStackTraceNoMessage(t *testing.T) {

jf.SetContextFilter(cf)

if jf.StartComponent() != nil {
if jf.AllowAccess() != nil {
t.Fatalf("Failed to detect supplied context filter")
}

Expand Down

0 comments on commit 5ccaeb3

Please sign in to comment.