Git Product home page Git Product logo

Comments (4)

WineChord avatar WineChord commented on June 12, 2024

Try log.With.

from trpc-go.

rhoninzhang avatar rhoninzhang commented on June 12, 2024

log.With add a field in json mode, can't format, any other way?
code:

log.With(log.Field{Key: "test_field", Value: "123456789"}).Debug("try log with")

output:

2023-12-13 16:45:54.457	DEBUG	demo/test.go:48	try log with	{"test_field": "123456789"}

from trpc-go.

WineChord avatar WineChord commented on June 12, 2024

@rhoninzhang, please check out the changes made in #146.

I have provided an example in zaplogger_test.go. The idea is to implement a custom encoder. However, I found it challenging to get it right, and the implementation is not straightforward. For instance, the fields argument in EncodeEntry(entry zapcore.Entry, fields []zapcore.Field) is always an empty array, regardless of whether the logger is decorated with additional fields. This can be quite confusing. I suggest you switch to this branch and explore it yourself. Feel free to provide more feedback.

from trpc-go.

WineChord avatar WineChord commented on June 12, 2024

image

I noticed that the InlineMarshalerType might be what you're looking for when dealing with unstructured JSON values (where only the value itself is shown, rather than {key: value}). However, I found that this utility seems to be inaccessible from the trpc-go logging package. It provides its own log.Field type and uses zapcore.Any to extract possible value types, but unfortunately, InlineMarshalerType is not included.

from trpc-go.

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.