public class LoggingHandler extends Handler
Logger
to Stackdriver Logging.
Java logging levels (see Level) are mapped to the following Google
Stackdriver Logging severities:
| Java Level | Stackdriver Logging Severity |
|---|---|
| SEVERE | ERROR |
| WARNING | WARNING |
| INFO | INFO |
| CONFIG | INFO |
| FINE | DEBUG |
| FINER | DEBUG |
| FINEST | DEBUG |
Original Java logging levels are added as labels (with levelName and
levelValue keys, respectively) to the corresponding Stackdriver Logging LogEntry.
You can read entry labels using LogEntry.labels(). To use logging levels that correspond
to Stackdriver Logging severities you can use LoggingLevel.
Configuration: By default each LoggingHandler is initialized using the
following LogManager configuration properties (that you can set in the
logging.properties file). If properties are not defined (or have invalid values) then the
specified default values are used.
com.google.cloud.logging.LoggingHandler.log the log name (defaults to
java.log).
com.google.cloud.logging.LoggingHandler.level specifies the default level for the
handler (defaults to Level.INFO).
com.google.cloud.logging.LoggingHandler.filter specifies the name of a Filter
class to use (defaults to no filter).
com.google.cloud.logging.LoggingHandler.formatter specifies the name of a
Formatter class to use (defaults to SimpleFormatter).
com.google.cloud.logging.LoggingHandler.flushSize specifies the maximum size of the
log buffer. Once reached, logs are transmitted to the Stackdriver Logging service (defaults
to 1).
com.google.cloud.logging.LoggingHandler.flushLevel specifies the flush log level.
When a log with this level is published, logs are transmitted to the Stackdriver Logging
service (defaults to LoggingLevel.ERROR).
To add a LoggingHandler to an existing Logger and be sure to avoid infinite
recursion when logging, use the addHandler(Logger, LoggingHandler) method. Alternatively
you can add the handler via logging.properties. For example using the following line:
com.example.mypackage.handlers=com.google.cloud.logging.LoggingHandler
| Constructor and Description |
|---|
LoggingHandler()
Creates an handler that publishes messages to Stackdriver Logging.
|
LoggingHandler(String log)
Creates a handler that publishes messages to Stackdriver Logging.
|
LoggingHandler(String log,
LoggingOptions options)
Creates a handler that publishes messages to Stackdriver Logging.
|
LoggingHandler(String log,
LoggingOptions options,
MonitoredResource monitoredResource)
Creates a handler that publishes messages to Stackdriver Logging.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
addHandler(Logger logger,
LoggingHandler handler)
Adds the provided
LoggingHandler to logger. |
void |
close()
Closes the handler and the associated
Logging object. |
void |
flush() |
void |
publish(LogRecord record) |
Level |
setFlushLevel(Level flushLevel)
Sets the flush log level.
|
long |
setFlushSize(long flushSize)
Sets the maximum size of the log buffer.
|
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevelpublic LoggingHandler()
public LoggingHandler(String log)
log - the name of the log to which log entries are writtenpublic LoggingHandler(String log, LoggingOptions options)
log - the name of the log to which log entries are writtenoptions - options for the Stackdriver Logging servicepublic LoggingHandler(String log, LoggingOptions options, MonitoredResource monitoredResource)
log - the name of the log to which log entries are writtenoptions - options for the Stackdriver Logging servicemonitoredResource - the monitored resource to which log entries referpublic void close()
throws SecurityException
Logging object.close in class HandlerSecurityExceptionpublic Level setFlushLevel(Level flushLevel)
LoggingLevel.ERROR is used.public long setFlushSize(long flushSize)
public static void addHandler(Logger logger, LoggingHandler handler)
LoggingHandler to logger. Use this method to register Cloud
Logging handlers instead of Logger.addHandler(Handler) to avoid infinite recursion
when logging.Copyright © 2016 Google. All rights reserved.