public abstract class Logger
Base class for Spanner diagnostic loggers.
Namespace
Google.Cloud.Spanner.V1.Internal.LoggingAssembly
Google.Cloud.Spanner.V1.dll
Remarks
This is an internal class intended for diagnostic purposes, and should not be used by general application code. Please read the user guide page on logging for more details.
Properties
DefaultLogger
public static Logger DefaultLogger { get; }
Retrieves the default logger.
Property Value | |
---|---|
Type | Description |
Logger |
EnableSensitiveDataLogging
public virtual bool EnableSensitiveDataLogging { get; set; }
Whether or not potentially sensitive information (such as SQL queries) is recorded. This affects the behavior of the SensitiveInfo(Func<String>) method.
Property Value | |
---|---|
Type | Description |
Boolean |
LogLevel
public LogLevel LogLevel { get; set; }
The level of logging this logger should perform. For example, if this is set to Info then messages for Debug will be ignored, but messages for Info, Warn and Error will be logged. This property defaults to None, so no messages are logged.
Property Value | |
---|---|
Type | Description |
LogLevel |
LogPerformanceTraces
public bool LogPerformanceTraces { get; set; }
Whether or not performance logging is enabled. This affects the LogPerformanceCounter(String, Double) methods, as well as LogPerformanceData(). This defaults to false, and should only be set to true for the purposes of benchmarks and diagnosing performance issues.
Property Value | |
---|---|
Type | Description |
Boolean |
Methods
Debug(Func<String>)
public void Debug(Func<string> messageFunc)
Logs a message at a level of Debug.
Parameter | |
---|---|
Name | Description |
messageFunc | Func<String> A function that provides the message to log. This function is only called after checking LogLevel, in order to avoid unnecessary formatting. This may be null and may return null, but in either of these cases, the call is a no-op. |
Debug(String)
public void Debug(string message)
Logs a message at a level of Debug.
Parameter | |
---|---|
Name | Description |
message | String The message to log. May be null, in which case this method is a no-op. |
Error(Func<String>, Exception)
public void Error(Func<string> messageFunc, Exception exception = null)
Logs a message at a level of Error.
Parameters | |
---|---|
Name | Description |
messageFunc | Func<String> A function that provides the message to log. This function is only called after checking LogLevel, in order to avoid unnecessary formatting. This may be null and may return null, but in either of these cases, the call is a no-op. |
exception | Exception The exception to log, if the logged event was caused by an exception. This may be null. |
Error(String, Exception)
public void Error(string message, Exception exception = null)
Logs a message at a level of Error.
Parameters | |
---|---|
Name | Description |
message | String The message to log. May be null, in which case this method is a no-op. |
exception | Exception The exception to log, if the logged event was caused by an exception. This may be null. |
ForILogger(ILogger)
public static Logger ForILogger(ILogger logger)
Creates a Logger instance that delegates all logging requests to
logger
.
Parameter | |
---|---|
Name | Description |
logger | ILogger The logger to delegate to. Must not be null. |
Returns | |
---|---|
Type | Description |
Logger | A Spanner logger that delegates to |
Info(Func<String>)
public void Info(Func<string> messageFunc)
Logs a message at a level of Info.
Parameter | |
---|---|
Name | Description |
messageFunc | Func<String> A function that provides the message to log. This function is only called after checking LogLevel, in order to avoid unnecessary formatting. This may be null and may return null, but in either of these cases, the call is a no-op. |
Info(String)
public void Info(string message)
Logs a message at a level of Info.
Parameter | |
---|---|
Name | Description |
message | String The message to log. May be null, in which case this method is a no-op. |
Log(LogLevel, Func<String>, Exception)
public void Log(LogLevel level, Func<string> messageFunc, Exception exception)
Logs the result of calling the given message provider function if the specified level equals or exceeds LogLevel.
Parameters | |
---|---|
Name | Description |
level | LogLevel The log level of the message to log. |
messageFunc | Func<String> A function that provides the message to log. This function is only called
if |
exception | Exception The exception to log, if the logged event was caused by an exception. This may be null. |
Log(LogLevel, String, Exception)
public void Log(LogLevel level, string message, Exception exception)
Logs the given message if the specified level equals or exceeds LogLevel.
Parameters | |
---|---|
Name | Description |
level | LogLevel The log level of the message to log. |
message | String The message to log. This may be null, in which case this call is a no-op. |
exception | Exception The exception to log, if the logged event was caused by an exception. This may be null. |
LogCommitStats(CommitRequest, CommitResponse)
public virtual void LogCommitStats(CommitRequest request, CommitResponse response)
This method is called when a transaction that requested CommitStats is committed. The default implementation logs the commit stats at log level Info. Derived classes can override this method to log the statistics at a different level, or to a different destination.
Parameters | |
---|---|
Name | Description |
request | CommitRequest The commit request that requested commit statistics |
response | CommitResponse The response with commit statistics |
LogImpl(LogLevel, String, Exception)
protected abstract void LogImpl(LogLevel level, string message, Exception exception)
Core method to implement logging in derived classes. This method is only called if the given log level exceeds LogLevel, so implementations do not need to perform that check again.
Parameters | |
---|---|
Name | Description |
level | LogLevel The log level of the message to log. |
message | String The message to log. This is never null. |
exception | Exception The exception to log, if the logged event was caused by an exception. This may be null. |
LogPerformanceCounter(String, Double)
public void LogPerformanceCounter(string name, double value)
Logs a performance counter value.
Parameters | |
---|---|
Name | Description |
name | String The name of the performance counter to log. May be null, in which case this call is a no-op. |
value | Double The latest value of the performance counter. |
LogPerformanceCounter(String, Func<Double, Double>)
public void LogPerformanceCounter(string name, Func<double, double> valueFunc)
Logs a computed performance counter value.
Parameters | |
---|---|
Name | Description |
name | String The name of the performance counter to log. May be null, in which case this call is a no-op. |
valueFunc | Func<Double, Double> A function to compute the latest value of the performance counter based on the current value. May be null, in which case this call is a no-op. |
LogPerformanceCounter(String, Func<Double>)
public void LogPerformanceCounter(string name, Func<double> valueFunc)
Logs a computed performance counter value.
Parameters | |
---|---|
Name | Description |
name | String The name of the performance counter to log. May be null, in which case this call is a no-op. |
valueFunc | Func<Double> A function to compute the latest value of the performance counter. May be null, in which case this call is a no-op. |
LogPerformanceData()
public void LogPerformanceData()
Logs any recorded performance data, if LogPerformanceTraces is enabled.
LogPerformanceEntries(IEnumerable<String>)
protected abstract void LogPerformanceEntries(IEnumerable<string> entries)
This method is called by LogPerformanceData() when LogPerformanceTraces is enabled, and should be implemented in derived classes to record performance data.
Parameter | |
---|---|
Name | Description |
entries | IEnumerable<String> The entries to log. This is never null, and never empty. |
ResetPerformanceData()
public void ResetPerformanceData()
Resets all performance data previously recorded by the LogPerformanceCounter(String, Double) methods.
SensitiveInfo(Func<String>)
public void SensitiveInfo(Func<string> messageFunc)
Logs a message at a level of Info, but only if EnableSensitiveDataLogging is enabled.
Parameter | |
---|---|
Name | Description |
messageFunc | Func<String> A function that provides the message to log. This function is only called after checking LogLevel, in order to avoid unnecessary formatting. This may be null and may return null, but in either of these cases, the call is a no-op. |
SetDefaultLogger(Logger)
public static void SetDefaultLogger(Logger instance)
Sets the default logger to be returned by future calls to DefaultLogger. (Any loggers retrieved by that property before are not affected by this method.)
Parameter | |
---|---|
Name | Description |
instance | Logger The new default logger. Must not be null. |
Warn(Func<String>, Exception)
public void Warn(Func<string> messageFunc, Exception exception = null)
Logs a message at a level of Warn.
Parameters | |
---|---|
Name | Description |
messageFunc | Func<String> A function that provides the message to log. This function is only called after checking LogLevel, in order to avoid unnecessary formatting. This may be null and may return null, but in either of these cases, the call is a no-op. |
exception | Exception The exception to log, if the logged event was caused by an exception. This may be null. |
Warn(String, Exception)
public void Warn(string message, Exception exception = null)
Logs a message at a level of Warn.
Parameters | |
---|---|
Name | Description |
message | String The message to log. May be null, in which case this method is a no-op. |
exception | Exception The exception to log, if the logged event was caused by an exception. This may be null. |