github.com/openimsdk/tools@v0.0.49/log/logger.go (about) 1 // Copyright © 2023 OpenIM. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package log 16 17 import "context" 18 19 type Logger interface { 20 // Debug logs a message at the debug level including any supplementary key-value pairs. 21 // Useful for detailed output for debugging purposes. 22 Debug(ctx context.Context, msg string, keysAndValues ...any) 23 24 // Info logs a message at the info level along with any supplementary key-value pairs. 25 // Ideal for general operational messages that inform about the system's state. 26 Info(ctx context.Context, msg string, keysAndValues ...any) 27 28 // Warn logs a message at the warning level, indicating potential issues in the system. 29 // It includes an error object and any supplementary key-value pairs. 30 Warn(ctx context.Context, msg string, err error, keysAndValues ...any) 31 32 // Error logs a message at the error level, indicating serious problems that need attention. 33 // It includes an error object and any supplementary key-value pairs. 34 Error(ctx context.Context, msg string, err error, keysAndValues ...any) 35 36 // WithValues returns a new Logger instance that will include the specified key-value pairs 37 // in all subsequent log messages. Useful for adding consistent context to a series of logs. 38 WithValues(keysAndValues ...any) Logger 39 40 // WithName returns a new Logger instance prefixed with the specified name. 41 // This is helpful for distinguishing logs generated from different sources or components. 42 WithName(name string) Logger 43 44 // WithCallDepth returns a new Logger instance that adjusts the call depth for identifying 45 // the source of log messages. Useful in wrapper or middleware layers to maintain accurate log source information. 46 WithCallDepth(depth int) Logger 47 }