Skip to content

Expose a way to flush log appender explicitly #58

@clementdenis

Description

@clementdenis

Is your feature request related to a problem? Please describe.
When using com.google.cloud.logging.logback.LoggingAppender, there's currently no way to flush logs explicitly (by calling getLogging().flush()), for example at the end of an HTTP request.

Describe the solution you'd like
Either increase visibility of the getLogging() method to protected, so we can extend LoggingAppender to add a flush() method, or add it directly to LoggingAppender.

Describe alternatives you've considered
A workaround is to set the flushLevel to the lowest, so every log entry is flushed immediately, but this is very inefficient.

Additional context
Here is how I would use this is a ServletFilter (Kotlin code):

	override fun doFilter(request: ServletRequest, response: ServletResponse, chain: FilterChain) {
        try {
            chain.doFilter(request, response)
        } finally {
            (LoggerFactory.getILoggerFactory() as LoggerContext).loggerList
                    .map { it.iteratorForAppenders() }
                    .forEach {
                        while (it.hasNext()) {
                            val appender = it.next()
                            when (appender.name) {
                                "CLOUD" -> (appender as LoggingAppender).flush()
                            }
                        }
                    }
        }
    }

Metadata

Metadata

Assignees

Labels

api: loggingIssues related to the googleapis/java-logging-logback API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions