1.5.18 • Published 6 years ago
@fontanus/logger v1.5.18
Usage
The logger implements the loglevel API
logger.info(msg: string, data?: any)logger.debug(msg: string, data?: any)logger.warn(msg: string, data?: any)logger.error(msg: string, data?: any)logger.trace(msg: string, data?: any)logger.setLevel(msg: string, data?: any)logger.getLoggers(msg: string, data?: any)logger.getLogger(msg: string, data?: any)
Logger adds the following features:
- using a the URL search string
lrswitches on remote logging, saved in the SessionStorage - using the URL search string
ll=LOGLEVELsets all log levels toLOGLEVEL - using the URL search string
lcpasses an initial context, mostly used in iframes - creates
window.logger=loglevel logger.setupLogger: The remote log url can be set by callinglogger.setupLogger(url, defaultLogger="default", logContextGetter=false)logger.getSetupString: returns a query string to be passed on into iframes
Extra API methods
logger.setupLogger
setupLogger(url, defaultLogger="default", logContextGetter=false) is used set up remote logging.
defaultLogger- string, specifies theloggerNamefor the default logger ofloglevel. e.g:com-webapp. You can start new loggers usinglogget.getLogger("mylogger"). A recommended logger naming convention is to usedefaultLogger.myLoggerfor custom loggers.logContextGetter- function or false, takes a function that returns extra data to be passed as context for the log message. By default no context is passed with the log message. Ifloglevel.<method>is called with a second data attribute that has acontextkey, then thelogContextGetteris ignored anddata.contextis passed on as the log context.
logger.getSetupString
logger.getSetupString() is used to retrieve the current logger settings as a search query url.
The primary usecase of getSetupString is to pass it to an iframe to retain the same remote logging and loglevel settings that the main frame has.
Example
import * as log from "@nagyv/logger"
log.setupLogger('https://www.example.com', 'example-logs', () => ({hello: 'world'}))
log.warn('A warning')
/*
posts the following to https://www.example.com when remote logging is enabled:
{
'message': 'A warning',
'loggerName': 'example-logs',
'context': {
'hello': 'world'
}
}
*/
log.warn('A warning', {context: 'mycontext'})
/*
posts the following to https://www.example.com when remote logging is enabled:
{
'message': 'A warning',
'loggerName': 'example-logs',
'context': 'mycontext',
'data': {'context': 'mycontext'}
}
*/
const otherLog = log.getLogger('otherLog')
log.warn('A warning')
/*
posts the following to https://www.example.com when remote logging is enabled:
{
'message': 'A warning',
'loggerName': 'otherLog',
'context': {
'hello': 'world'
}
}
*/1.5.18
6 years ago
1.5.17
6 years ago
1.5.15
6 years ago
1.4.11
6 years ago
1.4.10
6 years ago
1.4.9
6 years ago
1.4.6
6 years ago
1.4.8
6 years ago
1.3.6
6 years ago
1.3.5
6 years ago
1.3.4
6 years ago
1.3.3
6 years ago
1.3.2
6 years ago
1.2.2
6 years ago
1.1.2
6 years ago
1.1.1
6 years ago
1.1.0
6 years ago
1.0.9
6 years ago
1.0.10
6 years ago
1.0.8
6 years ago
1.0.7
6 years ago
1.0.6
6 years ago
1.0.5
6 years ago
1.0.4
6 years ago
1.0.2
6 years ago
1.0.3
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago