Skip to content

Commit 171f73b

Browse files
authored
Enable level config for console logger (#1324)
* enable level config for console logger * move logger to shared dir
1 parent 64dc2df commit 171f73b

File tree

18 files changed

+56
-70
lines changed

18 files changed

+56
-70
lines changed

src/browser/core.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Client from '../rollbar.js';
22
import * as _ from '../utility.js';
33
import API from '../api.js';
4-
import logger from './logger.js';
4+
import logger from '../logger.js';
55
import * as globals from './globalSetup.js';
66

77
import Transport from './transport.js';
@@ -17,6 +17,7 @@ import tracingDefaults from '../tracing/defaults.js';
1717
import ReplayManager from './replay/replayManager.js';
1818

1919
function Rollbar(options, client) {
20+
logger.init({ logLevel: options.logLevel || 'error' });
2021
this.options = _.handleOptions(defaultOptions, options, null, logger);
2122
this.options._configuredOptions = options;
2223
const Telemeter = this.components.telemeter;
@@ -121,6 +122,9 @@ Rollbar.global = function (options) {
121122
};
122123

123124
Rollbar.prototype.configure = function (options, payloadData) {
125+
if (options.logLevel) {
126+
logger.init({ logLevel: options.logLevel });
127+
}
124128
var oldOptions = this.options;
125129
var payload = {};
126130
if (payloadData) {

src/browser/logger.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/browser/replay/recorder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { record as rrwebRecordFn } from '@rrweb/record';
22
import { EventType } from '@rrweb/types';
33

44
import hrtime from '../../tracing/hrtime.js';
5-
import logger from '../logger.js';
5+
import logger from '../../logger.js';
66

77
export default class Recorder {
88
_options;

src/browser/replay/replayManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import id from '../../tracing/id.js';
2-
import logger from '../logger.js';
2+
import logger from '../../logger.js';
33

44
/**
55
* ReplayManager - Manages the mapping between error occurrences and their associated

src/browser/transforms.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as _ from '../utility.js';
22
import errorParser from '../errorParser.js';
3-
import logger from './logger.js';
3+
import logger from '../logger.js';
44

55
function handleDomException(item, options, callback) {
66
if (item.err && errorParser.Stack(item.err).name === 'DOMException') {

src/browser/transport/fetch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import logger from '../logger.js';
1+
import logger from '../../logger.js';
22
import * as _ from '../../utility.js';
33

44
function makeFetchRequest({accessToken, url, method, payload, headers, callback, timeout}) {

src/browser/transport/xhr.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*global XDomainRequest*/
22

33
import * as _ from '../../utility.js';
4-
import logger from '../logger.js';
4+
import logger from '../../logger.js';
55

66
function makeXhrRequest({
77
accessToken,

src/logger.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
let log = () => {};
2+
3+
const levels = {
4+
debug: 0,
5+
info: 1,
6+
warn: 2,
7+
error: 3,
8+
disable: 4,
9+
};
10+
11+
const logger = {
12+
error: (...args) => log('error', args),
13+
warn: (...args) => log('warn', args),
14+
info: (...args) => log('info', args),
15+
debug: (...args) => log('debug', args),
16+
log: (...args) => log('info', args),
17+
init: ({ logLevel }) => {
18+
log = function(level, args) {
19+
if (levels[level] < levels[logLevel]) return;
20+
21+
args.unshift('Rollbar:');
22+
23+
/* eslint-disable no-console */
24+
console[level].apply(console, args);
25+
}
26+
}
27+
};
28+
29+
export default logger;

src/react-native/logger.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/react-native/rollbar.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Client from '../rollbar.js';
22
import * as _ from '../utility.js';
33
import API from '../api.js';
4-
import logger from './logger.js';
4+
import logger from '../logger.js';
55
import * as rnDefaults from './defaults.js';
66
import { version, reportLevel } from '../defaults.js';
77

@@ -20,6 +20,7 @@ function Rollbar(options, client) {
2020
options = {};
2121
options.accessToken = accessToken;
2222
}
23+
logger.init({ logLevel: options.logLevel || 'error' });
2324
this.options = _.handleOptions(Rollbar.defaultOptions, options, null, logger);
2425
this.options._configuredOptions = options;
2526
// This makes no sense in a long running app
@@ -74,6 +75,9 @@ Rollbar.global = function (options) {
7475
};
7576

7677
Rollbar.prototype.configure = function (options, payloadData) {
78+
if (options.logLevel) {
79+
logger.init({ logLevel: options.logLevel });
80+
}
7781
var oldOptions = this.options;
7882
var payload = {};
7983
if (payloadData) {

0 commit comments

Comments
 (0)