github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/framework/logs/logmsg.go (about)

     1  // the package is exported from github.com/beego/beego/v2/core/logs
     2  
     3  // Copyright 2023. All Rights Reserved.
     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 logs
    18  
    19  import (
    20  	"fmt"
    21  	"path"
    22  	"time"
    23  )
    24  
    25  type LogMsg struct {
    26  	Level               int
    27  	Msg                 string
    28  	When                time.Time
    29  	FilePath            string
    30  	LineNumber          int
    31  	Args                []interface{}
    32  	Prefix              string
    33  	enableFullFilePath  bool
    34  	enableFuncCallDepth bool
    35  }
    36  
    37  // OldStyleFormat you should never invoke this
    38  func (lm *LogMsg) OldStyleFormat() string {
    39  	msg := lm.Msg
    40  
    41  	if len(lm.Args) > 0 {
    42  		msg = fmt.Sprintf(lm.Msg, lm.Args...)
    43  	}
    44  
    45  	msg = lm.Prefix + " " + msg
    46  
    47  	if lm.enableFuncCallDepth {
    48  		filePath := lm.FilePath
    49  		if !lm.enableFullFilePath {
    50  			_, filePath = path.Split(filePath)
    51  		}
    52  		msg = fmt.Sprintf("[%s:%d] %s", filePath, lm.LineNumber, msg)
    53  	}
    54  
    55  	msg = levelPrefix[lm.Level] + " " + msg
    56  	return msg
    57  }