Git Product home page Git Product logo

Comments (4)

deankarn avatar deankarn commented on September 27, 2024 1

OK @dengshuan updated to pass handler struct for FormatFunc + exposed the necessary fields, see commit 4b4ebd1

please let me know if I missed anything and thanks for you thoughts 👍

from log.

deankarn avatar deankarn commented on September 27, 2024

Hey @dengshuan although not useless, it may be a little easier if I passed the handler's Struct to the format function and added some getters.

I was originally thinking that one would dynamically create the function and therefore have access to any variable that would have been passed or set on the handler and not need the handler fields, but I can see how it may be more useful to expose the fields.

I will take a look at look at it this morning and see what I can't come up with.

from log.

dengshuan avatar dengshuan commented on September 27, 2024

Great, thank you for your quick reply and fix. With this commit, I can now truly customize syslog format function. The default format function in syslog handler prints timestamp and log level twice, because stdsyslog already prints timestamp and log level (priority actually) according to syslog standard

The full format of a syslog message seen on the wire has three
discernable parts. The first part is called the PRI, the second part
is the HEADER, and the third part is the MSG.

which the PRI part contains priority and HEADER part contains timestamp

But since there's an exported function SetFormatFunc for the handler, users can define their own format function. I don't know if this is a real problem

from log.

deankarn avatar deankarn commented on September 27, 2024

The main reasons it was done that way is because the libraries levels don't line up 100% with syslog log levels i.e.

case log.TraceLevel, log.InfoLevel:
            s.writer.Info(line)

case log.PanicLevel, log.AlertLevel:
            s.writer.Alert(line)

if you do not wish to lose that it was a TRACE or PANIC vs INFO or ALERT you need to print the level

and secondly not all syslog recipients handle nanosecond precision and so was also printing that out to ensure the logs could handle that precision.

I agree that not everyone may need or want that, but as you said, one only has to define their own format, so don;t think it's an issue.

Glad I could help, let me know if there's anything else 😄

from log.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.