MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / createMessage

Method createMessage

log/writer_syslog.go:69–100  ·  view source on GitHub ↗
(message message.Message)

Source from the content-addressed store, hash-verified

67}
68
69func (s *syslogWriter) createMessage(message message.Message) (line []byte, err error) {
70 switch s.format {
71 case config.LogFormatLJSON:
72 details := map[string]interface{}{}
73 for label, value := range message.Labels() {
74 details[string(label)] = value
75 }
76 line, err = json.Marshal(
77 syslogJsonLine{
78 Code: message.Code(),
79 Message: message.Explanation(),
80 Details: details,
81 },
82 )
83 if err != nil {
84 return nil, err
85 }
86 case config.LogFormatText:
87 msg := message.Explanation()
88 var labels []string
89 for labelName, labelValue := range message.Labels() {
90 labels = append(labels, fmt.Sprintf("%s=%s", labelName, labelValue))
91 }
92 if len(labels) > 0 {
93 msg += fmt.Sprintf(" (%s)", strings.Join(labels, " "))
94 }
95 line = []byte(msg)
96 default:
97 return nil, fmt.Errorf("log format not supported: %s", s.format)
98 }
99 return line, nil
100}
101
102type syslogJsonLine struct {
103 Code string `json:"code"`

Callers 1

WriteMethod · 0.95

Calls 5

LabelsTypeAlias · 0.92
MarshalMethod · 0.65
CodeMethod · 0.65
ExplanationMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected