Skip to content

Commit

Permalink
Merge pull request #1102 from dm3-org/removeWinstonFromBackend
Browse files Browse the repository at this point in the history
remove winston from backend
  • Loading branch information
malteish authored Jul 16, 2024
2 parents f602d75 + 8f39907 commit edb1a7e
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 34 deletions.
12 changes: 0 additions & 12 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'dotenv/config';
import express from 'express';
import http from 'http';
import path from 'path';
import winston from 'winston';
import { getDatabase } from './persistence/getDatabase';
import Profile from './profile';
import Storage from './storage';
Expand All @@ -28,17 +27,6 @@ const server = http.createServer(app);
app.use(cors());
app.use(bodyParser.json());

declare global {
var logger: winston.Logger;
}

global.logger = winston.createLogger({
level: process.env.LOG_LEVEL ?? 'info',
transports: [new winston.transports.Console()],
});

winston.loggers.add('default', global.logger);

(async () => {
const db = await getDatabase();
const web3Provider = await getCachedWebProvider(process.env);
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/src/persistence/getDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ export async function getRedisClient() {
);

client.on('error', (err) => {
global.logger.error('Redis error: ' + (err as Error).message);
console.error('Redis error: ' + (err as Error).message);
});

client.on('reconnecting', () => global.logger.info('Redis reconnection'));
client.on('ready', () => global.logger.info('Redis ready'));
client.on('reconnecting', () => console.info('Redis reconnection'));
client.on('ready', () => console.info('Redis ready'));

await client.connect();

Expand Down
5 changes: 0 additions & 5 deletions packages/backend/src/persistence/session/setAccount.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { Redis, IDatabase, getRedisClient, getDatabase } from '../getDatabase';
import { UserProfile } from '@dm3-org/dm3-lib-profile';
import { Session } from '@dm3-org/dm3-lib-delivery';
import winston from 'winston';

const USER_ADDRESS = '0x25A643B6e52864d0eD816F1E43c0CF49C83B8292';

global.logger = winston.createLogger({
transports: [new winston.transports.Console()],
});

describe('Set Session', () => {
let redisClient: Redis;
let db: IDatabase;
Expand Down
5 changes: 0 additions & 5 deletions packages/backend/src/profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@ import { ethers } from 'ethers';
import express from 'express';
import http from 'http';
import request from 'supertest';
import winston from 'winston';
import { IDatabase } from './persistence/getDatabase';
import profile from './profile';
import storage from './storage';

global.logger = winston.createLogger({
transports: [new winston.transports.Console()],
});

const web3ProviderMock: ethers.providers.JsonRpcProvider =
new ethers.providers.JsonRpcProvider();

Expand Down
8 changes: 4 additions & 4 deletions packages/backend/src/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ export default (
);

if (!schemaIsValid) {
global.logger.error({ message: 'invalid schema' });
console.error({ message: 'invalid schema' });
return res.status(400).send({ error: 'invalid schema' });
}
const ensName = normalizeEnsName(req.params.ensName);
global.logger.debug({
console.debug({
method: 'POST',
url: req.url,
ensName,
Expand All @@ -60,15 +60,15 @@ export default (
req.body,
serverSecret,
);
global.logger.debug({
console.debug({
message: 'POST profile',
ensName,
data,
});

res.json(data);
} catch (e) {
global.logger.warn({
console.warn({
message: 'POST profile',
error: JSON.stringify(e),
});
Expand Down
5 changes: 0 additions & 5 deletions packages/backend/src/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import bodyParser from 'body-parser';
import { ethers } from 'ethers';
import express from 'express';
import request from 'supertest';
import winston from 'winston';
import {
IDatabase,
Redis,
Expand Down Expand Up @@ -45,10 +44,6 @@ const keysA = {

const serverSecret = 'veryImportantSecretToGenerateAndValidateJSONWebTokens';

global.logger = winston.createLogger({
transports: [new winston.transports.Console()],
});

describe('Storage', () => {
let app;
let token = generateAuthJWT('bob.eth', serverSecret);
Expand Down

0 comments on commit edb1a7e

Please sign in to comment.