github.com/polarismesh/polaris@v1.17.8/plugin/history/logger/history_logger.go (about) 1 /** 2 * Tencent is pleased to support the open source community by making Polaris available. 3 * 4 * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 5 * 6 * Licensed under the BSD 3-Clause License (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * https://opensource.org/licenses/BSD-3-Clause 11 * 12 * Unless required by applicable law or agreed to in writing, software distributed 13 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 14 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 15 * specific language governing permissions and limitations under the License. 16 */ 17 18 package logger 19 20 import ( 21 commonLog "github.com/polarismesh/polaris/common/log" 22 "github.com/polarismesh/polaris/common/model" 23 "github.com/polarismesh/polaris/common/utils" 24 "github.com/polarismesh/polaris/plugin" 25 ) 26 27 // 把操作记录记录到日志文件中 28 const ( 29 // PluginName plugin name 30 PluginName = "HistoryLogger" 31 ) 32 33 var log = commonLog.RegisterScope(PluginName, "", 0) 34 35 // init 初始化注册函数 36 func init() { 37 plugin.RegisterPlugin(PluginName, &HistoryLogger{}) 38 } 39 40 // HistoryLogger 历史记录logger 41 type HistoryLogger struct { 42 } 43 44 // Name 返回插件名字 45 func (h *HistoryLogger) Name() string { 46 return PluginName 47 } 48 49 // Destroy 销毁插件 50 func (h *HistoryLogger) Destroy() error { 51 return log.Sync() 52 } 53 54 // Initialize 插件初始化 55 func (h *HistoryLogger) Initialize(c *plugin.ConfigEntry) error { 56 return nil 57 } 58 59 // Record 记录操作记录到日志中 60 func (h *HistoryLogger) Record(entry *model.RecordEntry) { 61 entry.Server = utils.LocalHost 62 log.Info(entry.String()) 63 }