![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@opendoor/optimizely-js-sdk-logging
Advanced tools
Provides a centralized LogManager and errorHandler for Javascript SDK packages.
npm install @opendoor/optimizely-js-sdk-logging
ConsoleLogHandler
or NoopLogHandler
LogManager.getLogger(name)
import { getLogger } from '@opendoor/optimizely-js-sdk-logging'
const logger = getLogger('myModule')
logger.log('warn', 'this is a warning')
logger.debug('string interpolation is easy and %s', 'lazily evaluated')
logger.info('info logging')
logger.warn('this is a warning')
logger.error('this is an error')
// `info` `warn` `debug` and `error` all support passing an Error as the last argument
// this will call the registered errorHandler
logger.error('an error occurred: %s', ex.message)
// also Error passes to errorHandler.handleError(ex)
logger.error('an error occurred: %s', ex.message, ex)
// if no message is passed will log `ex.message`
logger.error(ex)
import { LogLevel, setLogLevel } from '@opendoor/optimizely-js-sdk-logging'
// can use enum
setLogLevel(LogLevel.ERROR)
// can also use a string (lowercase or uppercase)
setLogLevel('debug')
setLogLevel('info')
setLogLevel('warn')
setLogLevel('error')
import { setLogHandler, ConsoleLogHandler } from '@opendoor/optimizely-js-sdk-logging'
const handler = new ConsoleLogHandler({
logLevel: 'error',
prefix: '[My custom prefix]', // defaults to "[OPTIMIZELY]"
})
setLogHandler(handler)
Perhaps you want to integrate Optimizely with your own logging system or use an existing library.
A valid LogHandler
is anything that implements this interface
interface LogHandler {
log(level: LogLevel, message: string): void
}
Example: integrating with Winston
import winston from 'winston'
import { setLogHandler, LogLevel } from '@opendoor/optimizely-js-sdk-logging'
const winstonLogger = winston.createLogger({
level: 'info',
format: winston.format.json(),
defaultMeta: { service: 'optimizely' },
transports: [
new winston.transports.File({ filename: 'combined.log' }),
],
})
/**
* Convert from optimizely log levels to winston
*/
function convertLogLevels(level) {
switch(level) {
case LogLevel.DEBUG:
return 'debug'
case LogLevel.INFO:
return 'info'
case LogLevel.WARNING:
return 'warning'
case LogLevel.ERROR:
return 'error'
default:
return 'silly'
}
}
setLogHandler({
log(level, message) {
winstoLogger.log({
level: convertLogLevels(level),
message,
})
}
})
interface LoggerFacade {
log(level: LogLevel | string, message: string): void
info(message: string | Error, ...splat: any[]): void
debug(message: string | Error, ...splat: any[]): void
warn(message: string | Error, ...splat: any[]): void
error(message: string | Error, ...splat: any[]): void
}
interface LogManager {
getLogger(name?: string): LoggerFacade
}
interface LogHandler {
log(level: LogLevel, message: string): void
}
0.1.1
FAQs
Optimizely Full Stack Core Logging
The npm package @opendoor/optimizely-js-sdk-logging receives a total of 2 weekly downloads. As such, @opendoor/optimizely-js-sdk-logging popularity was classified as not popular.
We found that @opendoor/optimizely-js-sdk-logging demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 73 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.