storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/logger/message/log/entry.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2018, 2020 MinIO, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package log
    18  
    19  import "strings"
    20  
    21  // Args - defines the arguments for the API.
    22  type Args struct {
    23  	Bucket   string            `json:"bucket,omitempty"`
    24  	Object   string            `json:"object,omitempty"`
    25  	Metadata map[string]string `json:"metadata,omitempty"`
    26  }
    27  
    28  // Trace - defines the trace.
    29  type Trace struct {
    30  	Message   string                 `json:"message,omitempty"`
    31  	Source    []string               `json:"source,omitempty"`
    32  	Variables map[string]interface{} `json:"variables,omitempty"`
    33  }
    34  
    35  // API - defines the api type and its args.
    36  type API struct {
    37  	Name string `json:"name,omitempty"`
    38  	Args *Args  `json:"args,omitempty"`
    39  }
    40  
    41  // Entry - defines fields and values of each log entry.
    42  type Entry struct {
    43  	DeploymentID string `json:"deploymentid,omitempty"`
    44  	Level        string `json:"level"`
    45  	LogKind      string `json:"errKind"`
    46  	Time         string `json:"time"`
    47  	API          *API   `json:"api,omitempty"`
    48  	RemoteHost   string `json:"remotehost,omitempty"`
    49  	Host         string `json:"host,omitempty"`
    50  	RequestID    string `json:"requestID,omitempty"`
    51  	UserAgent    string `json:"userAgent,omitempty"`
    52  	Message      string `json:"message,omitempty"`
    53  	Trace        *Trace `json:"error,omitempty"`
    54  }
    55  
    56  // Info holds console log messages
    57  type Info struct {
    58  	Entry
    59  	ConsoleMsg string
    60  	NodeName   string `json:"node"`
    61  	Err        error  `json:"-"`
    62  }
    63  
    64  // SendLog returns true if log pertains to node specified in args.
    65  func (l Info) SendLog(node, logKind string) bool {
    66  	nodeFltr := (node == "" || strings.EqualFold(node, l.NodeName))
    67  	typeFltr := strings.EqualFold(logKind, "all") || strings.EqualFold(l.LogKind, logKind)
    68  	return nodeFltr && typeFltr
    69  }