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

I suggest to update the README page. #213

Open
kevinlee85 opened this issue May 23, 2017 · 3 comments
Open

I suggest to update the README page. #213

kevinlee85 opened this issue May 23, 2017 · 3 comments

Comments

@kevinlee85
Copy link

log.debug("A tagged log message", userInfo: Dev.dave | Tag.sensitive)

That's somehow will confuse the user who only advantages one kind of Tag.
Then I suggest appending one demo code as below for that scenario.
log.debug("A tagged log message", userInfo: Tag.sensitive.dictionary)

@phimage
Copy link

phimage commented Aug 18, 2017

I also try to use one tag without .dictionary. This api is experimental, so... (maybe an auto casting with UserInfoConvertibleProtocol could be achieve)

In readme there is

Since the userInfo: parameter needs a dictionary, you can't pass in a single Dev or Tag object. You need to use at least two with the | operator to have it automatically convert to a compatible dictionary. If you only want one Tag for example, you must access the .dictionary parameter manually: userInfo: Tag("Blah").dictionary

@hk05
Copy link

hk05 commented Feb 5, 2019

Me too would love to have the opportunity to add simple tags without obfuscating code too much with long and complex log messages, for example:

log.debug("A tagged log message", .sensitive)
log.debug("A named log message", .dave)
log.debug("A tagged and named log message", .sensitive | .dave)

That is: not having to use the site long "userInfo: [Tag.sometag | Dev.somedeveloper ]".

If anyone knows a clean and elegant way to achieve this, this would in my opinion be a very nice addition to XCGLogger.

@phimage
Copy link

phimage commented Feb 5, 2019

I have made a PR #222 long time ago
This PR allow to be more generic on userInfo by creating protocols.

I keep some code for a following PR after the first one merged, that I commit after see @hk05 your message
https://github.com/DaveWoodCom/XCGLogger/compare/master...phimage:feature/userInfoProtocol?expand=1
This code is the following step, use the protocol in logger methods instead of dictionary. Dictionary conform to the protocol so no compatibility issue and you do do
log.debug("A tagged log message", userInfo: Tag.sensitive)
instead of
log.debug("A tagged log message", userInfo: Tag.sensitive.dictionary)


However to achieve what @hk05 want

log.debug("A named log message", .dave)

then we could duplicate all log functions of logger using Tag for instance with a default value .none or nil if Tag?

extension XCGLogger {
    open func debug(_ closure: @autoclosure () -> Any?, functionName: StaticString = #function, fileName: StaticString = #file, lineNumber: Int = #line, userInfo: Tag = .none) {
        self.logln(.debug, functionName: functionName, fileName: fileName, lineNumber: lineNumber, userInfo: userInfo, closure: closure) // userInfo.dictionary with current master code
    }
}

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

3 participants