You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Initialize ring buffers with a capacity of 128 (must be a power of two)
19
+
infoBuffer, _:=ringbuffer.NewRingBuffer
20
+
warnBuffer, _:=ringbuffer.NewRingBuffer
21
+
errorBuffer, _:=ringbuffer.NewRingBuffer
22
+
fatalBuffer, _:=ringbuffer.NewRingBuffer
23
+
floatBuffer, _:=ringbuffer.NewRingBuffer
24
+
18
25
return&App{
19
-
//initialize the ring buffers with a length of 100
20
-
Info: easyringbuffer.NewStringRingBuffer(100),
21
-
Warn: easyringbuffer.NewStringRingBuffer(100),
22
-
Error: easyringbuffer.NewStringRingBuffer(100),
23
-
Fatal: easyringbuffer.NewStringRingBuffer(100),
24
-
Floats: easyringbuffer.NewFloat64RingBuffer(100),
26
+
Info: infoBuffer,
27
+
Warn: warnBuffer,
28
+
Error: errorBuffer,
29
+
Fatal: fatalBuffer,
30
+
Floats: floatBuffer,
25
31
}
26
32
}
27
33
28
34
funcmain() {
29
-
// simulate INFO, WARN, ERROR, FATAL log messages
30
-
infoText:="INFO: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
35
+
// Simulate INFO, WARN, ERROR, FATAL log messages
36
+
infoText:="INFO: Lorem ipsum dolor sit amet..."
31
37
warnText:="WARN: Application has bad references"
32
38
errorText:="ERROR: Line count not found"
33
39
fatalText:="FATAL: Application failed to compile"
34
-
pi:=3.145926
40
+
pi:=3.1415926
35
41
36
-
// initialize the string ring buffer
42
+
// Initialize the app with ring buffers
37
43
app:=NewApp()
38
44
39
-
// add the log messages to the string ring buffer
40
-
app.Info.Add(infoText)
41
-
app.Warn.Add(warnText)
42
-
app.Error.Add(errorText)
43
-
app.Fatal.Add(fatalText)
45
+
// Add the log messages to the ring buffers
46
+
app.Info.Enqueue(infoText)
47
+
app.Warn.Enqueue(warnText)
48
+
app.Error.Enqueue(errorText)
49
+
app.Fatal.Enqueue(fatalText)
44
50
45
-
// add the floats onto the float64 ring buffer
46
-
fori:=0; i<=300; i+=1 {
47
-
app.Floats.Add(float64(i) +pi)
51
+
// Add float values to the float64 ring buffer
52
+
fori:=0; i<=300; i++ {
53
+
app.Floats.Enqueue(float64(i) +pi)
48
54
}
49
55
50
-
// print out the last 10 string messages on the buffer
51
-
info:=fmt.Sprintf("Last 10 INFO Messages: %s", app.Info.Last(10))
0 commit comments