logrus | Structured , pluggable logging for Go
kandi X-RAY | logrus Summary
kandi X-RAY | logrus Summary
Logrus is a structured logger for Go (golang), completely API compatible with the standard library logger. Logrus is in maintenance-mode. We will not be introducing new features. It's simply too hard to do in a way that won't break many people's projects, which is the last thing you want from your Logging library (again...). This does not mean Logrus is dead. Logrus will continue to be maintained for security, (backwards compatible) bug fixes, and performance (where we are limited by the interface). I believe Logrus' biggest contribution is to have played a part in today's widespread use of structured logging in Golang. There doesn't seem to be a reason to do a major, breaking iteration into Logrus V2, since the fantastic Go community has built those independently. Many fantastic alternatives have sprung up. Logrus would look like those, had it been re-designed with what we know about structured logging in Go today. Check out, for example, Zerolog, Zap, and Apex. Seeing weird case-sensitive problems? It's in the past been possible to import Logrus as both upper- and lower-case. Due to the Go package environment, this caused issues in the community and we needed a standard. Some environments experienced problems with the upper-case variant, so the lower-case was decided. Everything using logrus will need to use the lower-case: github.com/sirupsen/logrus. Any package that isn't, should be changed. To fix Glide, see these comments. For an in-depth explanation of the casing issue, see this comment.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of logrus
logrus Key Features
logrus Examples and Code Snippets
Community Discussions
Trending Discussions on logrus
QUESTION
I'm trying to implement pgxpool in a new go app. I keep getting a "pool closed" error after attempting a scan into a struct.
The pgx logger into gives me this after connecting. I thought the pgxpool was meant to remain open.
{"level":"info","msg":"closed connection","pid":5499,"time":"2022-02-24T16:36:33+10:30"}
Here is my router code
...ANSWER
Answered 2022-Feb-25 at 01:02It appears that you are doing something like the following:
QUESTION
With v1 of the SDK i could use logrus for my custom logger, like:
...ANSWER
Answered 2022-Jan-29 at 10:55It seems that sdk v2 offers a func wrapper to satisfy logging.logger:
QUESTION
I'm trying to compare the behavior of go mod tidy
(and the resulting content of go.sum) to the output of go list -m all
.
Reading the docs, I understand go.sum contains the whole list of dependent modules declared in go.mod and in dependencies' go.mod files, go list -m all
shows the modules really loaded during the execution.
As an example, an application including logrus and prometheus like this:
go.mod
...ANSWER
Answered 2022-Jan-12 at 17:09Yes, it correct to say the modules really "used" by the application are listed by go list -m all
(as per documentation you provided the link of). By "used", it means the package selected at build time for the compilation of the go code of your application.
We had a similar issue with a static analysis tool and we had to change the configuration to use the output of go list -m all
(dumped in a file) instead of go.sum
.
QUESTION
I'm using logrus
for logging in golang. I use the following statements for logging.
ANSWER
Answered 2022-Jan-07 at 07:58Write custom Hook
that will check if entry has severity
field set and if not insert default value. Attach that hook to either default global or your own logger.
You can limit hook to fire only on entries on logrus.ErrorLevel
by including only that level in return value of Hook.Levels()
:
QUESTION
I have a main.go
file that I use to run an app that starts a server that exposes a port where I can run endpoints from. I was trying to dockerise it and got as far as making working containers that hold the app and the db, but I still seem to have to run go run main.go
after running docker-compose up -d
.
ANSWER
Answered 2022-Jan-03 at 20:42Please, change the following line in the .env
file:
QUESTION
I'm trying to create a dockerfile for my go server but it keeps failing as it does not recognize some local dependencies (they are modules on the code itself, not external dependencies).
example:
...ANSWER
Answered 2021-Dec-02 at 22:41ADD ./src .
- that copies the contents of src
to the current folder, stripping away the src
part.
It should just be COPY . ./
Also note that it's not recommended to have a src
subfolder in your source tree - the folder that contains go.mod
is already the source tree.
QUESTION
I need to log relatively heavy JSON data within the web request handler. Does the logrus use blocking I/O? Should I call the logger.WithFields(fields).Info(heavy_message)
in a separate goroutine?
ANSWER
Answered 2021-Nov-17 at 18:04https://github.com/sirupsen/logrus/blob/79c5ab66aa2ce7d9ff7b3c437ebc22fcc519a967/entry.go#L221-L262 it looks like it is blocking i/o, so yes - you should call it in a goroutine.
QUESTION
I use logrus and lumberjack for log file on macOS.
...ANSWER
Answered 2021-Nov-01 at 11:20Based on the stated behaviour, I assume this is happening on an OS which implements POSIX-compatible behaviour for files (so it's running on some kernel with Unix heritage — such as *BSD or Linux, — or it's a Mac OS system).
On these systems, removing a file from a file system does nothing to that file's storage on that file system — as long as it is opened in at least a single running process.
Specifically, to cite the POSIX documentation on open(2)
:
If the link count of the file is 0, when all file descriptors associated with the file are closed, the space occupied by the file shall be freed and the file shall no longer be accessible.
Having a file open is considered to increment its link count by 1, and removing a file from its filesystem is the same as decrementing that link count by 1.
You might read more about link counts here.
Supposedly the logging package you're using keep the log file opened, and so what happens is that you merely remove the file's name from the filesystem's directory it was it, but this does not in any way affect the logging process.
Moreover, the process which has the file open is not notified when any of the file names goes away (on Unix-like systems a file might have many names at the same time—read about hard links).
Typically for Unix-like OSes is to have a way to explicitly ask the process to re-open its log file(s).
Casually, a SIGUSR1
signal is used for this, so you could setup a handler (via signal.Notify
) to setup a handler for such a signal and then make your log rotation code to kill -USR1
the running process to tell it re-open the log file, which will be recreated.
Of course, more involved schemes could be implemented as you can use any form of IPC to communicate that command to your running process.
QUESTION
I would like to dynamically load config file and not restart my Go app. I wrote the below files, which runs but has data race.
config.go
...ANSWER
Answered 2021-Aug-25 at 04:20You lock viperLock
called vipe.WatchConfig()
and set vipe.OnConfigChange
with a function it is also locking viperLock
.
Because you already called vipe.WatchConfig()
and then it started to call vipe.OnConfigChange
in separate go routine. it is also try to acquire the same lock. That's why there is a race condition.
Call vipe.WatchConfig()
after setting the vipe.OnConfigChange
and after release the lock.
It should be corrected as below.
QUESTION
TLDR: I am looking for a way to update headers on an open stream for each call to stream.Send(msg)
without closing the stream and opening a new one.
Summary
I have a GRPC client and server built to handle bidirectional streams. To authenticate with the server the client must send a JWT in the request headers, set as "authorization". The token is valid for 30 minutes. After the token has expired, the server will terminate the connection.
I am looking for a way to refresh my authorization token from the client, and keep the stream open. The client should run in a loop executing a new request every 30 minutes with the updated token, and the updated payload. I have not seen a way to update a header from the client side for an already opened stream.
Let's look at some code to get an idea of what the client side looks like. The code below has a function to create a new instance of the client, and another function to establish the connection to the GRPC server.
...ANSWER
Answered 2021-Oct-20 at 18:15Headers are sent at the beginning of an RPC, and cannot be updated during the RPC. If you need to send data during the life of a stream, it needs to be part of the request message in your proto definition.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install logrus
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page