1 // pubsubplus-go-client 2 // 3 // Copyright 2021-2025 Solace Corporation. 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 logging allows for configuration of the API's logging levels. 18 package logging 19 20 import ( 21 "io" 22 23 "solace.dev/go/messaging/internal/impl/core" 24 "solace.dev/go/messaging/internal/impl/logging" 25 ) 26 27 // LogLevel is used to configure the logging-level of the API. The different levels can 28 // include these type logs: 29 // 30 // - Critical/Error - These log levels indicates internal errors and should be a cause for investigation. 31 // Contact Solace for log events at this level. 32 // 33 // - Warning - Indicates an application error (for example, invalid parameters passed in or unsupported use of the APIs). 34 // 35 // - Info - Typically for unusual or informational occurrences that do not indicate an error, but might 36 // be unexpected or provide information useful for indicating a state. 37 // 38 // - Debug - Typically indicates state changes at a high-level, for example, connections/disconnections/reconnections 39 // These logs can indicate unusual occurrences that do not indicate any error, but they are unexpected 40 // and might need further investigation. 41 type LogLevel byte 42 43 const ( 44 // LogLevelCritical allows only critical logs. 45 // Critical logs are only output if a catastrophic unrecoverable error occurs. 46 LogLevelCritical LogLevel = LogLevel(logging.Critical) 47 // LogLevelError allows Error and Critical logs. 48 // Error logs are only output if unexpected behaviour is detected. 49 LogLevelError LogLevel = LogLevel(logging.Error) 50 // LogLevelWarning allows Warning, Error, and Critical logs. 51 // Warning logs are output if an issue is encountered due to application behavior. 52 LogLevelWarning LogLevel = LogLevel(logging.Warning) 53 // LogLevelInfo allows Info, Warning, Error, and Critical logs. 54 // Info logs are output when general API activities occur. 55 LogLevelInfo LogLevel = LogLevel(logging.Info) 56 // LogLevelDebug allows Debug, Info, Warning, Error, and Critical logs. 57 // Debug logs are output when any API activity occurs. Note that 58 // enabling Debug logs impacts the performance of the API. 59 LogLevelDebug LogLevel = LogLevel(logging.Debug) 60 ) 61 62 // SetLogLevel sets the global logging-level used for API logging. 63 func SetLogLevel(level LogLevel) { 64 core.SetLogLevel(logging.LogLevel(level)) 65 } 66 67 // SetLogOutput sets the global logging output redirection for API logging. 68 // The specified writer should be safe for concurrent writes. 69 func SetLogOutput(writer io.Writer) { 70 logging.Default.SetOutput(writer) 71 } 72