Google Cloud Spanner v1 API - Class Logger (4.3.0)

public abstract class Logger

Reference documentation and code samples for the Google Cloud Spanner v1 API class Logger.

Base class for Spanner diagnostic loggers.

Inheritance

object > Logger

Namespace

GoogleGoogle.CloudGoogle.Cloud.SpannerV1InternalLogging

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
bool

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
bool

Methods

Debug(Func<string>)

public void Debug(Func<string> messageFunc)

Logs a message at a level of Debug.

Parameter
NameDescription
messageFuncFuncstring

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
messageFuncFuncstring

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.

ForILogger(ILogger)

public static Logger ForILogger(ILogger logger)

Creates a Logger instance that delegates all logging requests to logger.

Parameter
NameDescription
loggerILogger

The logger to delegate to. Must not be null.

Returns
TypeDescription
Logger

A Spanner logger that delegates to logger.

Info(Func<string>)

public void Info(Func<string> messageFunc)

Logs a message at a level of Info.

Parameter
NameDescription
messageFuncFuncstring

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.

messageFuncFuncstring

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.

valueFuncFuncdoubledouble

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.

valueFuncFuncdouble

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
entriesIEnumerablestring

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
messageFuncFuncstring

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
messageFuncFuncstring

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.