Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
postgres-operator
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
zalando
postgres-operator
Commits
4ee28e38
Commit
4ee28e38
authored
Aug 15, 2017
by
Murat Kabilov
Browse files
Options
Downloads
Patches
Plain Diff
add ringlog
parent
9c7492f3
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
pkg/util/ringlog/ringlog.go
+59
-0
59 additions, 0 deletions
pkg/util/ringlog/ringlog.go
with
59 additions
and
0 deletions
pkg/util/ringlog/ringlog.go
0 → 100644
+
59
−
0
View file @
4ee28e38
package
ringlog
import
(
"container/list"
"sync"
)
// RingLogger describes ring logger methods
type
RingLogger
interface
{
Insert
(
interface
{})
Walk
()
[]
interface
{}
}
// RingLog is a capped logger with fixed size
type
RingLog
struct
{
sync
.
RWMutex
size
int
list
*
list
.
List
}
// New creates new Ring logger
func
New
(
size
int
)
*
RingLog
{
r
:=
RingLog
{
list
:
list
.
New
(),
size
:
size
,
}
return
&
r
}
// Insert inserts new LogEntry into the ring logger
func
(
r
*
RingLog
)
Insert
(
obj
interface
{})
{
r
.
Lock
()
defer
r
.
Unlock
()
r
.
list
.
PushBack
(
obj
)
if
r
.
list
.
Len
()
>
r
.
size
{
r
.
list
.
Remove
(
r
.
list
.
Front
())
}
}
// Walk dumps all the LogEntries from the Ring logger
func
(
r
*
RingLog
)
Walk
()
[]
interface
{}
{
res
:=
make
([]
interface
{},
0
)
r
.
RLock
()
defer
r
.
RUnlock
()
st
:=
r
.
list
.
Front
()
for
i
:=
0
;
i
<
r
.
size
;
i
++
{
if
st
==
nil
{
return
res
}
res
=
append
(
res
,
st
.
Value
)
st
=
st
.
Next
()
}
return
res
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment