Skip to content

Commit

Permalink
fix: remove local storage from logger to allow meerkat to run in an e…
Browse files Browse the repository at this point in the history
…nvironment without local storage
  • Loading branch information
fabianbormann committed Mar 24, 2023
1 parent c408ac5 commit d10bccc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
13 changes: 5 additions & 8 deletions logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { LogLevel } from './types';
export default class Logger {
logLevel: LogLevel = 'info';
private scope: string;
private enabled: boolean = true;

constructor({
scope,
Expand All @@ -19,20 +20,16 @@ export default class Logger {
}

if (typeof enabled === 'boolean') {
if (enabled) {
localStorage.setItem('Meerkat-Logging', 'true');
} else {
localStorage.setItem('Meerkat-Logging', 'false');
}
this.enabled = enabled;
}
}

disable() {
localStorage.setItem('Meerkat-Logging', 'false');
this.enabled = false;
}

enable() {
localStorage.setItem('Meerkat-Logging', 'true');
this.enabled = true;
}

private formatMessage(logLevel: LogLevel, message: string): string {
Expand Down Expand Up @@ -94,7 +91,7 @@ export default class Logger {
font-weight: bold';
`;

if (localStorage.getItem('Meerkat-Logging') === 'true') {
if (this.enabled) {
if (logLevel === 'debug' || logLevel === 'info') {
console.log(
this.formatMessage(logLevel, message),
Expand Down
7 changes: 1 addition & 6 deletions meerkat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,7 @@ export default class Meerkat extends EventEmitter {
connections() {
if (this.torrent.wires.length != this.lastwirecount) {
this.lastwirecount = this.torrent.wires.length;
this.emit(
'connections',
this.torrent.wires.map(
(wire: any) => wire.extendedHandshake?.identifier
)
);
this.emit('connections', this.torrent.wires.length);
}
return this.lastwirecount;
}
Expand Down

0 comments on commit d10bccc

Please sign in to comment.