Skip to content
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

Feature request #6

Open
maxb-odessa opened this issue Sep 18, 2018 · 2 comments
Open

Feature request #6

maxb-odessa opened this issue Sep 18, 2018 · 2 comments

Comments

@maxb-odessa
Copy link

Please, add a function to load configuration from a string, not only from file

@jeanphorn
Copy link
Owner

jeanphorn commented Sep 30, 2018

Please, add a function to load configuration from a string, not only from file

@vesemir-odessa , I have add json centent config to origin "LoadJsonConfiguration()" function to support both file and json content. Usage almost likes before, json content or filename all would be okay.

lg4_json

@maxb-odessa
Copy link
Author

maxb-odessa commented Oct 1, 2018

@jeanphorn Thanx, but I've made a small patch to make it work:

--- src/github.com/jeanphorn/log4go/jsonconfig.go	2018-10-01 12:33:06.537508548 +0300
+++ jsonconfig.go	2018-10-01 12:32:37.727476566 +0300
@@ -1,12 +1,12 @@
 package log4go
 
 import (
+	"bytes"
 	"encoding/json"
 	"fmt"
+	"github.com/toolkits/file"
 	"os"
 	"strings"
-
-	"github.com/toolkits/file"
 )
 
 type ConsoleConfig struct {
@@ -65,10 +65,12 @@
 		lc      LogConfig
 		content string
 	)
-	err := json.Compact(dst, []byte(filename))
+
+	var dst bytes.Buffer
+	err := json.Compact(&dst, []byte(filename))
 
 	if err != nil {
-		content, err = file.ReadFile(filename)
+		content, err = ReadFile(filename)
 		if err != nil {
 			fmt.Fprintf(os.Stderr, "LoadJsonConfiguration: Error: Could not read %q: %s\n", filename, err)
 			os.Exit(1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants