2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-07-04 06:59:43 -04:00
|
|
|
package qemu
|
|
|
|
|
|
|
|
import (
|
2022-08-02 10:25:47 -04:00
|
|
|
"context"
|
2022-07-04 06:59:43 -04:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Logger is a Cloud Logger for QEMU.
|
|
|
|
type Logger struct{}
|
|
|
|
|
|
|
|
// NewLogger creates a new Cloud Logger for QEMU.
|
|
|
|
func NewLogger() *Logger {
|
|
|
|
return &Logger{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disclose writes log information to QEMU's cloud log.
|
|
|
|
// This is done by sending a POST request to the QEMU's metadata endpoint.
|
|
|
|
func (l *Logger) Disclose(msg string) {
|
|
|
|
url := &url.URL{
|
|
|
|
Scheme: "http",
|
|
|
|
Host: qemuMetadataEndpoint,
|
|
|
|
Path: "/log",
|
|
|
|
}
|
|
|
|
|
2022-08-02 10:25:47 -04:00
|
|
|
req, _ := http.NewRequestWithContext(context.Background(), http.MethodPost, url.String(), strings.NewReader(msg))
|
|
|
|
req.Header.Set("Content-Type", "application/json")
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
|
|
if err == nil {
|
|
|
|
defer resp.Body.Close()
|
|
|
|
}
|
2022-07-04 06:59:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Close is a no-op.
|
|
|
|
func (l *Logger) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|