Lorenz Brun | 52f7f29 | 2020-06-24 16:42:02 +0200 | [diff] [blame] | 1 | // Copyright 2020 The Monogon Project Authors. |
| 2 | // |
| 3 | // SPDX-License-Identifier: Apache-2.0 |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | |
| 17 | package main |
| 18 | |
| 19 | import ( |
Serge Bazanski | 686444e | 2020-12-21 14:21:14 +0100 | [diff] [blame] | 20 | "fmt" |
| 21 | "io" |
Lorenz Brun | 52f7f29 | 2020-06-24 16:42:02 +0200 | [diff] [blame] | 22 | "log" |
| 23 | "os" |
Lorenz Brun | 52f7f29 | 2020-06-24 16:42:02 +0200 | [diff] [blame] | 24 | |
Serge Bazanski | 31370b0 | 2021-01-07 16:31:14 +0100 | [diff] [blame] | 25 | "source.monogon.dev/metropolis/pkg/logbuffer" |
Lorenz Brun | 52f7f29 | 2020-06-24 16:42:02 +0200 | [diff] [blame] | 26 | ) |
| 27 | |
Serge Bazanski | 686444e | 2020-12-21 14:21:14 +0100 | [diff] [blame] | 28 | // prefixedStdout is a os.Stdout proxy that prefixes every line with a constant |
| 29 | // prefix. This is used to show logs from two Metropolis nodes without getting |
| 30 | // them confused. |
| 31 | // TODO(q3k): move to logging API instead of relying on qemu stdout, and remove |
| 32 | // this function. |
| 33 | func prefixedStdout(prefix string) io.ReadWriter { |
| 34 | lb := logbuffer.NewLineBuffer(2048, func(l *logbuffer.Line) { |
| 35 | fmt.Fprintf(os.Stdout, "%s%s\n", prefix, l.Data) |
| 36 | }) |
| 37 | // Make a ReaderWriter from LineBuffer (a Reader), by combining into an |
| 38 | // anonymous struct with a io.MultiReader() (which will always return EOF |
| 39 | // on every Read if given no underlying readers). |
| 40 | return struct { |
| 41 | io.Reader |
| 42 | io.Writer |
| 43 | }{ |
| 44 | Reader: io.MultiReader(), |
| 45 | Writer: lb, |
| 46 | } |
| 47 | } |
| 48 | |
Lorenz Brun | 52f7f29 | 2020-06-24 16:42:02 +0200 | [diff] [blame] | 49 | func main() { |
Serge Bazanski | 0ed2f96 | 2021-03-15 16:39:30 +0100 | [diff] [blame] | 50 | log.Fatal("unimplemented") |
Lorenz Brun | 52f7f29 | 2020-06-24 16:42:02 +0200 | [diff] [blame] | 51 | } |