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

Custom log formatter secondpr #4179

Merged
merged 4 commits into from
Aug 22, 2020

Conversation

IamCathal
Copy link
Contributor

Second PR of the custom log formatter. I found this one to be very closely coupled to the third part so I found it quite hard. LogFormatter is implemented but no custom formatting is implemented yet which will come in the third PR.

Most of the work will come in the third actually so this pr isn't very important at all

Works fully with

package main

import (
	beego "github.com/astaxie/beego/pkg"
	"github.com/astaxie/beego/pkg/logs"
)

type MainController struct {
	beego.Controller
}

func main() {
	// ctrl := &MainController{}
	// beego.Router("/yuppa", ctrl, "get:Yuppa")
	beego.BConfig.Log.AccessLogs = true
	beego.BConfig.Log.AccessLogsFormat = "JSON_FORMAT"
	logs.SetLogger("console", "")
	logs.SetLogger("file", `{"filename":"test.json"}`)

	logs.EnableFullFilePath(true)
	logs.EnableFuncCallDepth(true)
	beego.Run()
}

@IamCathal IamCathal force-pushed the custom-log-formatter-secondpr branch from 3dda0f2 to e1da804 Compare August 20, 2020 18:20
@IamCathal
Copy link
Contributor Author

CI failed on second build. This failure below usually seems to happen so I'm not sure what the problem is:

unable to WriteMsg to adapter:conn,error:dial tcp :7020: connect: connection refused
--- FAIL: TestReconnect (0.00s)

I'll push another commit and see if it fixes itself

Copy link
Collaborator

@flycash flycash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!
Next PR maybe we could focus on:
How users register their custom LogFormat and how all implementations use those LogFormat?

@flycash flycash changed the base branch from develop-2.0 to ftr/log_format August 22, 2020 13:35
@flycash
Copy link
Collaborator

flycash commented Aug 22, 2020

CI failed on second build. This failure below usually seems to happen so I'm not sure what the problem is:

unable to WriteMsg to adapter:conn,error:dial tcp :7020: connect: connection refused
--- FAIL: TestReconnect (0.00s)

I'll push another commit and see if it fixes itself

Just ignore this error. This unit test is not stable. I can retry CI until it success.

@flycash flycash merged commit 09afe0a into beego:ftr/log_format Aug 22, 2020
@IamCathal
Copy link
Contributor Author

Yes so the last PR will be the full implementation of users setting their own formatters right?

Just to get this right the order for the formatters should go as follows:

adapter-specific formatter > global formatter > default formatter

So using SetLoggerWithOpts overrides a global set formatter and that also overrides any default set formatter.

@IamCathal
Copy link
Contributor Author

I'll write up a PR with the new logging documentation on beedoc after I finish this next PR.

@flycash
Copy link
Collaborator

flycash commented Aug 23, 2020

Just kindly remind you that I create a new branch named "ftr/log_format" and please use this branch as base branch.

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

Successfully merging this pull request may close these issues.

2 participants