mirror of
https://github.com/containers/podman.git
synced 2025-07-15 03:02:52 +08:00
Implement podman logs with log-driver journald
Add a journald reader that translates the journald entry to a k8s-file formatted line, to be added as a log line Note: --follow with journald hasn't been implemented. It's going to be a larger undertaking that can wait. Signed-off-by: Peter Hunt <pehunt@redhat.com>
This commit is contained in:
@ -19,6 +19,16 @@ const (
|
||||
// zeroes are not trimmed, taken from
|
||||
// https://github.com/golang/go/issues/19635
|
||||
logTimeFormat = "2006-01-02T15:04:05.000000000Z07:00"
|
||||
|
||||
// readLogTimeFormat is the format the log lines will be read in
|
||||
readLogTimeFormat = time.RFC3339Nano
|
||||
|
||||
// partialLogType signifies a log line that exceeded the buffer
|
||||
// length and needed to spill into a new line
|
||||
partialLogType = "P"
|
||||
|
||||
// fullLogType signifies a log line is full
|
||||
fullLogType = "F"
|
||||
)
|
||||
|
||||
// LogOptions is the options you can use for logs
|
||||
@ -55,9 +65,16 @@ func (r *Runtime) Log(containers []*Container, options *LogOptions, logChannel c
|
||||
func (c *Container) ReadLog(options *LogOptions, logChannel chan *LogLine) error {
|
||||
// TODO Skip sending logs until journald logs can be read
|
||||
// TODO make this not a magic string
|
||||
if c.LogDriver() == "journald" {
|
||||
return ErrNotImplemented
|
||||
if c.LogDriver() == JournaldLogging {
|
||||
if options.Follow {
|
||||
return errors.Errorf("The follow option with journald logging is not currently supported")
|
||||
}
|
||||
return c.readFromJournal(options, logChannel)
|
||||
}
|
||||
return c.readFromLogFile(options, logChannel)
|
||||
}
|
||||
|
||||
func (c *Container) readFromLogFile(options *LogOptions, logChannel chan *LogLine) error {
|
||||
t, tailLog, err := getLogFile(c.LogPath(), options)
|
||||
if err != nil {
|
||||
// If the log file does not exist, this is not fatal.
|
||||
@ -196,7 +213,7 @@ func newLogLine(line string) (*LogLine, error) {
|
||||
if len(splitLine) < 4 {
|
||||
return nil, errors.Errorf("'%s' is not a valid container log line", line)
|
||||
}
|
||||
logTime, err := time.Parse(time.RFC3339Nano, splitLine[0])
|
||||
logTime, err := time.Parse(readLogTimeFormat, splitLine[0])
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to convert time %s from container log", splitLine[0])
|
||||
}
|
||||
@ -211,7 +228,7 @@ func newLogLine(line string) (*LogLine, error) {
|
||||
|
||||
// Partial returns a bool if the log line is a partial log type
|
||||
func (l *LogLine) Partial() bool {
|
||||
if l.ParseLogType == "P" {
|
||||
if l.ParseLogType == partialLogType {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
Reference in New Issue
Block a user