Google Cloud Spanner v1 API - Class Logger (5.0.0-beta03)

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

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
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
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
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
bool

Methods

Debug(Func<string>)

public void Debug(Func<string> messageFunc)

Logs a message at a level of Debug.

Parameter
Name Description
messageFunc Funcstring

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 Funcstring

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 logger.

Info(Func<string>)

public void Info(Func<string> messageFunc)

Logs a message at a level of Info.

Parameter
Name Description
messageFunc Funcstring

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 Funcstring

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.

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 Funcdoubledouble

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 Funcdouble

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 IEnumerablestring

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 Funcstring

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 Funcstring

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.