@nextcloud/logger

@nextcloud/logger

Build Status Code coverage npm Documentation

Generic JavaScript logging interface for Nextcloud apps and libraries

Usage

See also API documentation.

import { getLoggerBuilder } from '@nextcloud/logger'

const logger = getLoggerBuilder()
.setApp('mail')
.detectUser()
.build()

logger.debug('hello')
logger.error('this should not have happened', { someContext: 13 })
logger.warn('it\'s just a warning, carry on')

Right now the package uses window.console as log appender and produces the following output

[DEBUG] mail: hello { app: 'mail', uid: 'christoph' }
[ERROR] mail: this should not have happened { app: 'mail', uid: 'christoph', someContext: 13 }
[WARN] mail: it's just a warning, carry on { app: 'mail', uid: 'christoph' }

The logger tries to detect the server configured logging level by default, which can be configured using the loglevel_frontend option in the config.php. In case no logging level was configured or detection failed, the logger will fallback to the warning level.

If the server is set to the debug mode the configured logging level will be set to the debug level.

Any message with a lower level than the configured will not be printed on the console.

You can override the logging level in both cases by setting it manually using the setLogLevel function when building the logger.

Contributing

This repository is maintained using conventional commit messages.