zap | Blazing fast, structured, leveled logging in Go

 by   uber-go Go Version: v1.24.0 License: MIT

kandi X-RAY | zap Summary

kandi X-RAY | zap Summary

zap is a Go library typically used in Logging, Kafka applications. zap has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

Blazing fast, structured, leveled logging in Go.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              zap has a medium active ecosystem.
              It has 18932 star(s) with 1340 fork(s). There are 252 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 95 open issues and 502 have been closed. On average issues are closed in 113 days. There are 28 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of zap is v1.24.0

            kandi-Quality Quality

              zap has 0 bugs and 0 code smells.

            kandi-Security Security

              zap has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              zap code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              zap is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              zap releases are available to install and integrate.
              Installation instructions, examples and code snippets are available.
              It has 13238 lines of code, 939 functions and 128 files.
              It has medium code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of zap
            Get all kandi verified functions for this library.

            zap Key Features

            No Key Features are available at this moment for zap.

            zap Examples and Code Snippets

            No Code Snippets are available at this moment for zap.

            Community Discussions

            QUESTION

            Is it possible to update the log level of a zap logger at runtime?
            Asked 2022-Mar-17 at 18:11

            I created a logger with kubebuilder, it is based on zap logger:

            ...

            ANSWER

            Answered 2022-Mar-17 at 18:11

            Better answer: as suggested by @Oliver Dain, use zap.AtomicLevel. See their answer for details.

            Another option is to create a core with a custom LevelEnabler function. You can use zap.LevelEnablerFunc to convert a closure to a zapcore.LevelEnabler.

            The relevant docs:

            LevelEnabler decides whether a given logging level is enabled when logging a message.

            LevelEnablerFunc is a convenient way to implement zapcore.LevelEnabler with an anonymous function.

            That function may then return true or false based on some other variable that changes at runtime:

            Source https://stackoverflow.com/questions/69738222

            QUESTION

            UDF executing multiple times with Structured References
            Asked 2022-Feb-08 at 04:44

            I am experiencing performance problems with a large (wide and long) table that uses a UDF that has variables passed as structured references.

            It seems that when a structured reference for a specific cell, eg "[@A]" is passed to the UDF, it flags the whole column, ie "[A]" as dirty and every cell in the column the UDF references is recalculated (this is the source of the performance problem).

            I have found that if I change the UDF within the table to use cell address, eg "A2", then the UDF only executes when that cell changes.

            To test, create a simple function with debug.print to highlight when it is run:

            ...

            ANSWER

            Answered 2022-Feb-07 at 14:40

            I used this formula in column C =zap([@A],[@B]) and as you can see in the video below I cannot reproduce your issue. It only re-calculates the formula in the row I changed something.

            Source https://stackoverflow.com/questions/71020105

            QUESTION

            How to access Fields in zap Hooks?
            Asked 2022-Jan-23 at 13:43

            How can I access the full information about the logging event in uber-zap's hooks?

            For example, I am trying to add a zapcore.Field to the logging event, but it does not show up in the zapcore.Entry.

            If it is not possible, can I at least have the fully-formatted string somehow? The goal is to send an email/automated message/Sentry/etc in case of errors.

            ...

            ANSWER

            Answered 2022-Jan-23 at 13:43

            Fields are not available in Zap hooks. The docs of zap.Hooks say this explicitly:

            [...] Hooks are useful for simple side effects, like capturing metrics for the number of emitted logs. More complex side effects, including anything that requires access to the Entry's structured fields, should be implemented as a zapcore.Core instead. [...]

            So to dump logs with go-spew, you need a custom core. You have two main options.

            Custom core with custom encoder

            This has the advantage of allowing more customization.

            The entry's fields are available in zapcore.Encoder.EncodeEntry. The strategy is, as usual, to embed a zapcore.Encoder into your struct and reimplement EncodeEntry:

            Source https://stackoverflow.com/questions/70512120

            QUESTION

            Why custom encoding is lost after calling logger.With in Uber Zap?
            Asked 2021-Dec-28 at 07:33

            (based on this question: Uber Zap Logger: how to prepend every log entry with a string)

            I replaced the Encoder of my uber-zap logger with a custom one to prepend every log entry with a SystemD-friendly error level (), but now after I use the logger with additional fields (With(fields ...Field)), the custom prepending is gone:

            ...

            ANSWER

            Answered 2021-Dec-28 at 07:33

            You have to also implement Clone() from the zapcore.Encoder interface. If you wish to keep the parent logger unaltered, you have to construct an actual clone — possibly with the same config, so you might want to store it as a field:

            Source https://stackoverflow.com/questions/70502026

            QUESTION

            Uber Zap Logger: how to prepend every log entry with a string
            Asked 2021-Dec-28 at 07:09

            I am using my app as a SystemD service and need to prepend every message with an entry level for JournalD like:

            ...

            ANSWER

            Answered 2021-Dec-28 at 07:09

            You can use a custom encoder that embeds a zapcore.Encoder.

            Embedding the encoder gives you the implementation of all methods "for free" with the same configuration you have now. Then you can implement only EncodeEntry with the additional logic you require.

            NOTE: You still have to implement Clone() if you plan to use structured logging, e.g. logger.With(). More info: Why custom encoding is lost after calling logger.With in Uber Zap?

            Back to your main question, this is a working example; see the comments in code for additional explanation:

            Source https://stackoverflow.com/questions/70489167

            QUESTION

            How to properly capture zap logger output in unit tests
            Asked 2021-Dec-18 at 13:13

            Based off the configurations for zap.NewDevelopmentConfig() and zap.NewProductionConfig(), I've assumed that zap writes logs to stderr. However, I can't seem to capture the output in unit tests.

            I have the following captureOutput func:

            ...

            ANSWER

            Answered 2021-Dec-18 at 13:13
            Test that messages are logged at all

            Use zapcore.NewTee. In your unit tests, you instantiate a logger whose core is comprised of your own highly modified core and the observed core tee'd together. The observed core will receive the log entries, so you can assert that single fields are what you expect (level, message, fields, etc.)

            Source https://stackoverflow.com/questions/70400426

            QUESTION

            How do I create the OpenAPI section for the 404 page?
            Asked 2021-Dec-10 at 14:11

            I'm using OpenApi 3. A tool I use, Owasp Zap looks at the OpenAPI doc and creates fake requests. When it gets a 404, it complains that it doesn't have the media type that the OpenAPI promises.

            But I didn't write anything in the OpenAPI doc about how 404s are handled. Obviously I can't write an infinite number of bad end points & document that they return 404s.

            What is the right way to record this in the OpenAPI yaml or json?

            Here is a minimal yaml file... I know for sure that this file does say anything about 404, ie. 404s aren't in the contract so tools are complaining that 404s are valid responses, but 404 is what a site should return when a resource is missing

            ...

            ANSWER

            Answered 2021-Dec-10 at 14:11

            This has been proposed already but not implemented: https://github.com/OAI/OpenAPI-Specification/issues/521

            In the comments someone gave a suggestion: https://github.com/OAI/OpenAPI-Specification/issues/521#issuecomment-513055351, which reduces a little your code, but you would still have to insert N*M entries for N paths * M methods.

            Since we don't have the ability to make the specification change to our needs, all that remains is we adapting ourselves.

            From your profile, you seem to be a windows user. You can for example, create a new explorer context menu to your .yaml files (Add menu item to windows context menu only for specific filetype, Adding a context menu item in Windows for a specific file extension), and make it run a script that auto-fills your file.

            Here, an example python script called yamlfill404.py that would be used in the context call in a way like path/to/pythonexecutable/python.exe path/to/python/script/yamlfill404.py %1, where %1 is the path to the file being right clicked.

            Python file:

            Source https://stackoverflow.com/questions/70036785

            QUESTION

            Mail service using AWS ses in GO
            Asked 2021-Nov-19 at 18:55

            I am using AWS SES for mail service. Following the package "github.com/aws/aws-sdk-go/service/ses"

            using this I found that HTML data is passing as a string

            in one of my scenario i want to show year dynamically.. means now i want to show 2021 next year 2022 in mail footer section

            ...

            ANSWER

            Answered 2021-Nov-19 at 18:55

            QUESTION

            zap-api-scan.py: How to limit the time / recursion / depth?
            Asked 2021-Nov-16 at 11:57

            I have a command for zap-api-scan.py, but unlike zap-full-scan.py, there seems to be no way to limit these.

            via OWASP's official docker image:

            ...

            ANSWER

            Answered 2021-Nov-09 at 00:34

            -T max time in minutes to wait for ZAP to start and the passive scan to run

            Per:

            Source https://stackoverflow.com/questions/69889328

            QUESTION

            Google Sign In with firebase on android keeps failing
            Asked 2021-Nov-15 at 07:23

            I have spent the whole day trying to get my anroid app to sign in using firebase. But no turtorial solved my problem.

            I have a firebase Project, and the SHA1 was updated.

            I used this code here

            The exception only says login faild. I thougt the problem might be the pre installed google app on the emulator, so I tried it on another device, didn't help. I wiped the data on all emulators, didn't help.

            What else could I try? Did you have the same problem, how did you solve it?

            Edit:

            ...

            ANSWER

            Answered 2021-Nov-15 at 07:23

            This solved the problem link

            The problem is a bug in the Firebase API, this is only a workaround.

            It took me only a few days...

            Source https://stackoverflow.com/questions/69916285

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install zap

            Note that zap only supports the two most recent minor versions of Go.
            In contexts where performance is nice, but not critical, use the SugaredLogger. It's 4-10x faster than other structured logging packages and includes both structured and printf-style APIs. When performance and type safety are critical, use the Logger. It's even faster than the SugaredLogger and allocates far less, but it only supports structured logging. See the documentation and FAQ for more details.

            Support

            We encourage and support an active, healthy community of contributors — including you! Details are in the contribution guide and the code of conduct. The zap maintainers keep an eye on issues and pull requests, but you can also report any negative conduct to oss-conduct@uber.com. That email list is a private, safe space; even the zap maintainers don't have access, so don't hesitate to hold us to a high standard. Released under the MIT License. 1 In particular, keep in mind that we may be benchmarking against slightly older versions of other packages. Versions are pinned in the benchmarks/go.mod file. ↩.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/uber-go/zap.git

          • CLI

            gh repo clone uber-go/zap

          • sshUrl

            git@github.com:uber-go/zap.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link