Comments (12)
+1
from go-logging.
I'm open to suggestions. It would be neat to use some library which abstracted these colors to make them work on both Unix and Windows et al.
from go-logging.
This library supports colorized output on Unix and Windows.
from go-logging.
It would also be great if we could specify the color for each call (apart from changing the default colors at log levels).
Here's one use case where I think this feature will really help.
Suppose I am executing a test case. When the execution starts, I would want to print an INFO
message (in default color), saying Executing foobar test case
. At the end of the execution, if the test passes, I'd want to print another INFO
message [PASS]
in green color. In case it fails, I'd want to print an INFO
message in red color [FAIL]
and I can log the stack trace at ERROR
level.
from go-logging.
@mahendrakariya That you can do today already using eg. the library you linked to together with this library.
from go-logging.
I've made a patch which can override default levels, though it looks like it'll be extra work to add the same feature for formatting "verbs"; I had a stab at the latter but it looks like doFmtVerbLevelColor is called within a StringFormatter, which doesn't have access to the LogBackend, where I put my custom colour scheme option.
See the PR above.
from go-logging.
Here's the initial attempt I made at applying it to {color} in formatters, but I ran into the snag I mentioned above so the draft doesn't compile as I haven't got access to my colour scheme in the StringFormatter currently, as I detailed above.
I'd welcome @op 's comments on the signature change on doFmtVerbLevelColor though, and any suggestions as to the most sensible way to pass the desired colour in.
from go-logging.
Sorry, I don't have time to look at this right now.
Maybe you could call a function when creating the formatter, eg getColorFunc(string) (func(io.Writer), error)
. The error is used when creating the formatter in case the color is unknown or unsupported (Windows?). This function could know that it should paint eg. red. Then when creating the log line, use the function as is. Quick sketch (this doesn't work at all);
In new;
if strings.HasPrefix(name, "color") {
if f, err := getColorFunc(name); err != nil {
return err
} else {
// save func
}
}
When creating the output format;
for i, part := range parts {
// ...
if part.verb == color {
f.colorFuncs[i](output)
}
// ...
}
from go-logging.
I'm not sure I understand your suggestion; it sounds like you're suggesting having the formatter string hard code colours in? That seems strange as it wouldn't respect the log level, which is the only thing which woud usually decide the colour used, I would think. My original approach was just going to be to use the custom colours defined for specific log levels, so that instead of being able to only override the colour for the whole line, you could still use the formatter to determine where that colour is applied (eg. in my applications I have it only colourising the WAR/ERR/INF part).
Personally I don't think I'm likely to use more than the feature I've added in that pull request, and I think that's also all this issue expressed a desire for, so I'll leave the verb formatting alone.
It's worth noting, though, that with both the log message colouring on, and {color} used in the formatter, the default log colour will only apply up to the first {color} and then be reset to white, and this is true in the existing code, before my PR.
from go-logging.
Sorry @giftig, sounds like I missunderstood. I thought you wanted to support color:red
. Mixed this up with another issue. I'll re-read this later when I have some more time. :)
from go-logging.
Sorry for the delayed update. But after a long discussion, we finally came to a conclusion that for our use case, what we need is "console reporting". Logging is a different functionality and it should not be confused with reporting. So, we will continue using this library for logging, but not for reporting on console. Which means we no longer need the functionality we requested in this issue. But I will keep it open as other users may benefit if this is implemented.
from go-logging.
👍 for set up custom colors to the levels
from go-logging.
Related Issues (20)
- change delimiter in output format
- Logger registry singleton
- Duplicate print in log HOT 3
- *Logger type uses global backend in IsEnabledFor method
- log rotate functionality HOT 1
- build fails on raspberry pi 3 running debian stretch HOT 1
- Diffrent format / config for diffrent level HOT 1
- Set Logging Level HOT 5
- Add mqttlog backend to README
- Getting formatted logs in file and on cmd HOT 1
- go1.12 and too many arguments HOT 1
- Test failure: TestLogCallpath incorrect callpath HOT 2
- Disable logging HOT 1
- Rotating files HOT 1
- How to customize the request id? HOT 1
- Add a standard logger
- Question: Can you set maximum logging level HOT 1
- How to turn off line numbers in production env? HOT 1
- How do I set up multiple log files?
- [Question] How to log to a file? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-logging.