Alternatively read and write in memory buffer

Hi can anyone tell me how can we read and write logs into the two buffer but single at a time.Means when I am writing the logs in one buffer then simultaneously logs should read from another buffer and vise versa.

Thanks in advance.

Hey @Nirmal_Singh,

If I get what you are asking, you can just use a pipe reader and writer.

Example:

package main

import (
	"io"
	"log"
	"os"
)

func main() {
	pr, pw := io.Pipe()

	go func() {
		pw.Write([]byte("Hello, World!"))
		if err := pw.Close(); err != nil {
			log.Fatalln(err)
		}
	}()

	io.Copy(os.Stdout, pr)

	if err := pr.Close(); err != nil {
		log.Fatalln(err)
	}
}

I probably have some other examples here: https://github.com/radovskyb/go-packages/tree/master/io/readers/pipereader.

There’s also os.Pipe instead of io.Pipe for connecting a pair of files and here’s some examples of that: https://github.com/radovskyb/go-packages/tree/master/os/file/pipe.

Can I use buffer instead of io.pipe as previously I was using single buffer for reading and writing Logs?

I’m not too sure what you mean by that. Care to share to the code you are trying to use currently?

Please check my code on following link:

https://play.golang.org/p/8xboPHUyNO

As currently I am using single buffer for reading and writing the logs with logrus.

Can I use two buffer instead of one.One for read and other for write or if one buffer limit exceeds then logs should start writing to second one.

Hey @Nirmal_Singh,

Sorry, I’m really not familiar with using logrus and I’m not exactly sure what you are trying to accomplish so it’s kind of hard for me to help here, but I would definitely recommend finding someone else that knows more about logrus than I do to be able to give you good advice :slight_smile:

thanks

@Nirmal_Singh,

Please explain what you are trying to accomplish.

Some of our difficultly helping you may be that the questions you ask us are too deep in the problem stack. It seems that you need to do Y and then think that maybe X is a method or the first step in getting Y done, but you don’t know how to do X, so you ask us how to do X.

The following posts from you seem to be related:

Your Y might have been mentioned in https://forum.golangbridge.org/t/write-logs-to-memory/4521/3. That is that you need to write logs to mysql because heroku only supports read-only filesystems. If so, then my answer to your question would work. Since you keep asking related questions, I guess that you have a different Y.

Please tell us what Y is. Give us some code that motivates Y, but has no attempts to solve Y in it. Describe what the ideal situation after Y is solved would be like.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.