Comments (2)
What really Post method is doing here????
You can read the code anytime. https://github.com/fluent/fluent-logger-golang/blob/master/fluent/fluent.go
We are always welcome to bug reports, but please report bugs with the exact code (not pseudo code) and the steps how to reproduce it.
from fluent-logger-golang.
package main
import (
"fmt"
"encoding/json"
syslog_fmt "gopkg.in/mcuadros/go-syslog.v2/format"
"github.com/fluent/fluent-logger-golang/fluent"
"io/ioutil"
"io"
"os"
syslog "gopkg.in/mcuadros/go-syslog.v2"
"flag"
)
var (
fileObject *os.File
bufferfileSize = flag.Int64("bytesize", 0, "Track the file size")
)
func forwardToAggregator(logParts syslog_fmt.LogParts){
tag := "datacollector"
data := make(map[string]interface{})
data["content"] = logParts["content"].(string)
data["hostname"] = logParts["hostname"].(string)
data["severity"] = logParts["severity"].(int)
data["facility"] = logParts["facility"].(int)
data["priority"] = logParts["priority"].(int)
fileObject, _ = os.OpenFile("test.json", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666)
logger, err := fluent.New(fluent.Config{FluentPort: X.X.X.X, FluentHost: XXXX})
if err != nil {
# Machine is not reachable/ Network failure, so saving logs to file
file, _ := json.Marshal(data)
route_messages_tofile(string(file))
} else {
sending_to_aggregator(logger, data, tag)
fi,_ := fileObject.Stat()
*bufferfileSize = fi.Size()
if *bufferfileSize != 0 {
send_logs_fromfile(logger, tag)
}
}
defer logger.Close()
}
func route_messages_tofile(content string){
n, err := io.WriteString(fileObject, string(content)+",")
if err != nil {
fmt.Println(n, err)
}
}
func sending_to_aggregator(logger *fluent.Fluent, data map[string]interface{}, tag string){
fmt.Println("Posting logs to aggregator")
error := logger.Post(tag, data)
fmt.Println("Error", error)
if error != nil {
file, _ := json.Marshal(data)
route_messages_tofile(string(file))
}
}
func send_logs_fromfile(logger fluent.Fluent, tag string){
fmt.Println("Aggregator came back to normal state")
fmt.Println("Going to sent the logs from File content")
fmt.Println("***********************************")
content, _ := ioutil.ReadFile("/home/mani/logmonitor/test.json")
err := os.Truncate("/home/mani/logmonitor/test.json", 0)
if err != nil {
panic(err)
}
file_content := string(content)
processed_content := file_content[:len(file_content)-1]
processed_content = "["+string(processed_content)+"]"
var result []map[string]interface{}
fmt.Println("Content of the file", processed_content)
fmt.Println("*************************************")
json.Unmarshal([]byte(processed_content), &result)
for value := range result{
sending_to_aggregator(logger, result[value], tag)
fmt.Println("Value", result[value])
}
}
func main() {
channel := make(syslog.LogPartsChannel)
handler := syslog.NewChannelHandler(channel)
server := syslog.NewServer()
server.SetFormat(syslog.Automatic)
server.SetHandler(handler)
server.ListenTCP("0.0.0.0:514")
server.Boot()
go func(channel syslog.LogPartsChannel) {
for logParts := range channel {
forwardToAggregator(logParts)
}
}(channel)
server.Wait()
}
Scenario1 : if syslog message is received , it will got forwardToAggregator(logParts) -->formating messages and assume that Aggregator Machine is up, so it will sent the message to sending_to_aggregator(), here logger.Post() directly sending that syslog msg, and I checked in aggregator side.
Scenario2: Aggregator is up and scenario1 steps will get executed, but one point
aggregator becomes down, so the follow will be like
forwardToAggregator(logParts) --> route_messages_tofile(data),
After 5 minutes, again the machine is up, now message is coming and scenario1 steps will get executed,
after that it will check the buffer file and it is not zero, so now data is there and
send_logs_fromfile(logger, tag) method starts execution, it leads to hit the
sending_to_aggregator() function, here logger.Post(tag, data) should return ERROR,
but it is not.
Any idea???
from fluent-logger-golang.
Related Issues (20)
- tagomoris will step down from the maintainer HOT 4
- Disordered Ack messages will be missed HOT 3
- Calls to Write() after calling Close() in sync mode reopen the connection HOT 5
- Migrate testing to Go's testing package HOT 1
- Release v1.8.0 HOT 5
- Feature: periodically reconnect to fluentd-address HOT 1
- Add a new option TLSCertPath
- Option to skip loggertag and timestamp
- Support for fluentd `shared_key` and `user_auth`
- Panic if TLS fluentd server cannot be connected
- Support to take TLS certificate in case of tls enabled
- Fluent-bit Supported
- RequestAck usage
- Sent payloads not valid JSON, wrapped in function call
- Send JSON encoded payloads without re-marshalling them?
- Add a separate `BufferLimitBytes` option to limit memory usage
- Unknown writing error: MaxRetry shows zero HOT 3
- Update README to describe Config parameters clearly HOT 1
- How to forward output plugin records HOT 3
- Passing struct pointers to `Post` method HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluent-logger-golang.