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

Not able to load logconfig - Error - resource nonexistent #10

Open
Avik1993 opened this issue Oct 5, 2018 · 4 comments
Open

Not able to load logconfig - Error - resource nonexistent #10

Avik1993 opened this issue Oct 5, 2018 · 4 comments

Comments

@Avik1993
Copy link

Avik1993 commented Oct 5, 2018

Hi
I am facing couple of issues while implementing log rolling using this library:

  1. If I need to use this library in multiple go files in a project, do i need to load the configuration in each go file? If not, I am trying to load it in single go file and exposing single variable for others to use in them.

  2. While loading the configuration file using relative path (generated absolute path on the go using filesystem.AbsPath()), it gives error - config file .. is nonexistent

Any pointers what could be the issue and how to resolve it?

@jeanphorn
Copy link
Owner

@Avik1993
no1: Load the configuration once is okay.
no2: Please make sure you config path is right. Print and check

@Avik1993
Copy link
Author

Avik1993 commented Oct 8, 2018

@jeanphorn
I am extracting absolute path using filesystem.absPath("relativepath"), which prints correct path as well but still I get the same error.
Any more pointers?

@jeanphorn
Copy link
Owner

@Avik1993
Can you provide your demo code?

@Avik1993
Copy link
Author

Avik1993 commented Oct 8, 2018

Sample Project:
logConfig.json

{
    "console": {
        "enable": true,
        "level": "INFO"
    },  
    "files": [{
        "enable": true,
        "level": "ERROR",
        "filename":"./test.log",
        "category": "logger",
        "pattern": "[%D %T] [%C] [%L] (%S) %M"
    },{ 
        "enable": true,
        "level": "ERROR",
        "filename":"./rotate_test_dao.log",
        "category": "logRotateDAO",
        "pattern": "[%D %T] [%C] [%L] (%S) %M",
        "rotate": true,
        "maxsize": "1M",
        "maxlines": "3",
        "daily": true
    },{ 
        "enable": true,
        "level": "ERROR",
        "filename":"./rotate_test_service.log",
        "category": "logRotateController",
        "pattern": "[%D %T] [%C] [%L] (%S) %M",
        "rotate": true,
        "maxsize": "1M",
        "maxlines": "3",
        "daily": true
    }]
}

Utility.go: Used to log event:-

func init() {
	absPath, _ := filepath.Abs("./logger/logConfig.json")
	log.Println("file Path 5::::: " + absPath)
	log4go.LoadConfiguration(absPath)
}

//LogEvent - Used to log some event
func LogEvent() {
	log.Println("Inside LogEvent ! will be logged in rotate_test_dao log file")

	log4go.LOGGER("logRotateDAO").Debug("Log4go is working fine!!")
	log4go.LOGGER("logRotateDAO").Error("error level log!!")

	log4go.LOGGER("logger").Debug("Logger Debug level is working fine!!")
	log4go.LOGGER("logger").Error("Logger Error level is working fine!!")

	log4go.LOGGER("logRotateController").Debug("logRotateController Debug level is working fine!!")
	log4go.LOGGER("logRotateController").Error("logRotateController Error level is working fine!!")
}

This successfully loads config and creates appropriate log files, but doesnt actually log any event in the log files!
Any help here?

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