@ar.io/sdk
Version:
[](https://codecov.io/gh/ar-io/ar-io-sdk)
69 lines (68 loc) • 2.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WinstonLogger = void 0;
/**
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const version_js_1 = require("../../version.js");
class WinstonLogger {
logger;
winston;
constructor({ level = 'info', } = {}) {
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
this.winston = require('winston');
}
catch (error) {
throw new Error('Winston is not installed. Install it with: npm install winston');
}
this.logger = this.winston.createLogger({
level: level === 'none' ? 'error' : level,
silent: level === 'none',
defaultMeta: {
name: 'ar-io-sdk',
version: version_js_1.version,
},
format: this.winston.format.combine(this.winston.format.timestamp(), this.winston.format.json()),
transports: [
new this.winston.transports.Console({
format: this.winston.format.combine(this.winston.format.timestamp(), this.winston.format.json()),
}),
],
});
}
info(message, ...args) {
this.logger.info(message, ...args);
}
warn(message, ...args) {
this.logger.warn(message, ...args);
}
error(message, ...args) {
this.logger.error(message, ...args);
}
debug(message, ...args) {
this.logger.debug(message, ...args);
}
setLogLevel(level) {
if (level === 'none') {
this.logger.silent = true;
}
else {
this.logger.silent = false;
this.logger.level = level;
}
}
}
exports.WinstonLogger = WinstonLogger;