-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add comments and update readme.
Signed-off-by: J.J. Martzki <mars14850@gmail.com>
- Loading branch information
Showing
2 changed files
with
68 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,47 @@ | ||
# dmesg | ||
Golang package to get message from Linux kernel ring buffer. | ||
This package gets message by reading from `/dev/kmsg` like cmd util `dmesg`. | ||
|
||
# types | ||
## Msg | ||
```go | ||
type Msg struct { | ||
Level uint64 // SYSLOG lvel | ||
Facility uint64 // SYSLOG facility | ||
Seq uint64 // Message sequence number | ||
TsUsec int64 // Timestamp in microsecond | ||
Caller string // Message caller | ||
IsFragment bool // This message is a fragment of an early message which is not a fragment | ||
Text string // Log text | ||
DeviceInfo map[string]string // Device info | ||
} | ||
``` | ||
`Msg` is a serialized message structure by parsing native message. It returned by `Dmesg` or `DmesgWithBufSize`. | ||
|
||
# functions | ||
## Dmesg | ||
```go | ||
func Dmesg() ([]Msg, error) | ||
``` | ||
Dmesg gets all messages from kernel ring buffer with default buf size 16KB for each message. | ||
It returns serialized message structure and the error while getting messages. | ||
The error `syscall.EINVAL` means the buf size is not enough, consider to use `DmesgWithBufSize` instead. | ||
## RawDmesg | ||
```go | ||
func RawDmesg() ([][]byte, error) | ||
``` | ||
RawDmesg gets all messages from kernel ring buffer with default buf size 16KB for each message. | ||
It returns native message from kernel without parsing and the error while getting messages. | ||
The error `syscall.EINVAL` means the buf size is not enough, consider to use `RawDmesgWithBufSize` instead. | ||
## DmesgWithBufSize | ||
```go | ||
func DmesgWithBufSize(bufSize uint32) ([]Msg, error) | ||
``` | ||
DmesgWithBufSize gets all messages from kernel ring buffer with specific buf size for each message. | ||
It returns serialized message structure and the error while getting messages. | ||
## RawDmesgWithBufSize | ||
```go | ||
func RawDmesgWithBufSize(bufSize uint32) ([][]byte, error) | ||
``` | ||
RawDmesgWithBufSize gets all messages from kernel ring buffer with specific buf size for each message. | ||
It returns native message from kernel without parsing and the error while getting messages. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters