Class Logger (3.12.0)

public abstract class Logger

Base class for Spanner diagnostic loggers.

Inheritance

Object > Logger

Namespace

Google.Cloud.Spanner.V1.Internal.Logging

Assembly

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
TypeDescription
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
TypeDescription
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
TypeDescription
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
TypeDescription
Boolean

Methods

Debug(Func<String>)

public void Debug(Func<string> messageFunc)

Logs a message at a level of Debug.

Parameter
NameDescription
messageFuncFunc<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
NameDescription
messageString

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
NameDescription
messageFuncFunc<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.

exceptionException

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
NameDescription
messageString

The message to log. May be null, in which case this method is a no-op.

exceptionException

The exception to log, if the logged event was caused by an exception. This may be null.

Info(Func<String>)

public void Info(Func<string> messageFunc)

Logs a message at a level of Info.

Parameter
NameDescription
messageFuncFunc<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
NameDescription
messageString

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
NameDescription
levelLogLevel

The log level of the message to log.

messageFuncFunc<String>

A function that provides the message to log. This function is only called if level equals or exceeds 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.

exceptionException

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
NameDescription
levelLogLevel

The log level of the message to log.

messageString

The message to log. This may be null, in which case this call is a no-op.

exceptionException

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
NameDescription
requestCommitRequest

The commit request that requested commit statistics

responseCommitResponse

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
NameDescription
levelLogLevel

The log level of the message to log.

messageString

The message to log. This is never null.

exceptionException

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
NameDescription
nameString

The name of the performance counter to log. May be null, in which case this call is a no-op.

valueDouble

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
NameDescription
nameString

The name of the performance counter to log. May be null, in which case this call is a no-op.

valueFuncFunc<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
NameDescription
nameString

The name of the performance counter to log. May be null, in which case this call is a no-op.

valueFuncFunc<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
NameDescription
entriesIEnumerable<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
NameDescription
messageFuncFunc<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
NameDescription
instanceLogger

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
NameDescription
messageFuncFunc<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.

exceptionException

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
NameDescription
messageString

The message to log. May be null, in which case this method is a no-op.

exceptionException

The exception to log, if the logged event was caused by an exception. This may be null.