Browse Source

Merge branch 'feature/add-logging' into 'develop'

Feature/add logging

See merge request ecentrics/concordia!18
develop
Apostolos Fanakis 4 years ago
parent
commit
19dbbb4f0c
  1. 12
      docker/Makefile
  2. 1
      docker/env/contracts-provider.env
  3. 1
      docker/env/pinner.env
  4. 4
      packages/concordia-app/.eslintrc.js
  5. 2
      packages/concordia-app/src/components/ClearDatabasesModal/index.jsx
  6. 2
      packages/concordia-app/src/components/PostCreate/index.jsx
  7. 2
      packages/concordia-app/src/views/Profile/GeneralTab/EditInformationModal/index.jsx
  8. 2
      packages/concordia-app/src/views/Register/PersonalInformationStep/index.jsx
  9. 2
      packages/concordia-app/src/views/Topic/TopicCreate/index.jsx
  10. 1
      packages/concordia-contracts-provider/.gitignore
  11. 4
      packages/concordia-contracts-provider/package.json
  12. 2
      packages/concordia-contracts-provider/src/constants.js
  13. 7
      packages/concordia-contracts-provider/src/controllers/download.js
  14. 13
      packages/concordia-contracts-provider/src/controllers/upload.js
  15. 12
      packages/concordia-contracts-provider/src/index.js
  16. 9
      packages/concordia-contracts-provider/src/utils/logger.js
  17. 1
      packages/concordia-pinner/.gitignore
  18. 2
      packages/concordia-pinner/package.json
  19. 18
      packages/concordia-pinner/src/app.js
  20. 5
      packages/concordia-pinner/src/constants.js
  21. 15
      packages/concordia-pinner/src/index.js
  22. 5
      packages/concordia-pinner/src/options/ipfsOptions.js
  23. 17
      packages/concordia-pinner/src/utils/drizzleUtils.js
  24. 3
      packages/concordia-pinner/src/utils/ipfsUtils.js
  25. 9
      packages/concordia-pinner/src/utils/logger.js
  26. 7
      packages/concordia-pinner/src/utils/orbitUtils.js
  27. 48
      packages/concordia-shared/src/logging/node/winstonLogUtils.js
  28. 1765
      yarn.lock

12
docker/Makefile

@ -72,21 +72,21 @@ run-app-host-chain:
build-contracts-provider:
@docker build ../ -f ./concordia-contracts-provider/Dockerfile -t ecentrics/concordia-contracts-provider --build-arg TZ=Europe/Athens
run-contracts-provider-staging:
@docker run -d -v ${CONTRACTS_PROVIDER_VOLUMES}/contracts:/mnt/concordia/contracts --env-file=./env/contracts-provider.env -p 8400:8400 --name concordia-contracts-provider --net=concordia_concordia_network ecentrics/concordia-contracts-provider:latest
@docker run -d -v ${CONTRACTS_PROVIDER_VOLUMES}/contracts:/mnt/concordia/contracts -v ${CONTRACTS_PROVIDER_VOLUMES}/contracts:/mnt/concordia/logs --env-file=./env/contracts-provider.env -p 8400:8400 --name concordia-contracts-provider --net=concordia_concordia_network ecentrics/concordia-contracts-provider:latest
run-contracts-provider:
@docker run -d -v ${CONTRACTS_PROVIDER_VOLUMES}/contracts:/mnt/concordia/contracts --env-file=./env/contracts-provider.env -e NODE_ENV=production -p 8400:8400 --name concordia-contracts-provider --net=concordia_concordia_network ecentrics/concordia-contracts-provider:latest
@docker run -d -v ${CONTRACTS_PROVIDER_VOLUMES}/contracts:/mnt/concordia/contracts -v ${CONTRACTS_PROVIDER_VOLUMES}/contracts:/mnt/concordia/logs --env-file=./env/contracts-provider.env -e NODE_ENV=production -p 8400:8400 --name concordia-contracts-provider --net=concordia_concordia_network ecentrics/concordia-contracts-provider:latest
# Pinner targets
build-pinner:
@docker build ../ -f ./concordia-pinner/Dockerfile -t ecentrics/concordia-pinner --build-arg TZ=Europe/Athens
run-pinner-staging:
@docker run -d -v ${PINNER_VOLUMES}/orbitdb:/mnt/concordia/orbitdb --env-file=./env/pinner.env -p 4444:4444 --name concordia-pinner --net=concordia_concordia_network ecentrics/concordia-pinner:latest
@docker run -d -v ${PINNER_VOLUMES}/orbitdb:/mnt/concordia/orbitdb -v ${PINNER_VOLUMES}:/mnt/concordia/logs --env-file=./env/pinner.env -p 4444:4444 --name concordia-pinner --net=concordia_concordia_network ecentrics/concordia-pinner:latest
run-pinner:
@docker run -d -v ${PINNER_VOLUMES}/orbitdb:/mnt/concordia/orbitdb --env-file=./env/pinner.env -e NODE_ENV=production -p 4444:4444 --name concordia-pinner --net=concordia_concordia_network ecentrics/concordia-pinner:latest
@docker run -d -v ${PINNER_VOLUMES}/orbitdb:/mnt/concordia/orbitdb -v ${PINNER_VOLUMES}:/mnt/concordia/logs --env-file=./env/pinner.env -e NODE_ENV=production -p 4444:4444 --name concordia-pinner --net=concordia_concordia_network ecentrics/concordia-pinner:latest
run-pinner-staging-host:
@docker run -d -v ${PINNER_VOLUMES}/orbitdb:/mnt/concordia/orbitdb --env-file=./env/pinner.env --net=host --name concordia-pinner ecentrics/concordia-pinner:latest
@docker run -d -v ${PINNER_VOLUMES}/orbitdb:/mnt/concordia/orbitdb -v ${PINNER_VOLUMES}:/mnt/concordia/logs --env-file=./env/pinner.env --net=host --name concordia-pinner ecentrics/concordia-pinner:latest
run-pinner-host:
@docker run -d -v ${PINNER_VOLUMES}/orbitdb:/mnt/concordia/orbitdb --env-file=./env/pinner.env -e NODE_ENV=production --net=host --name concordia-pinner ecentrics/concordia-pinner:latest
@docker run -d -v ${PINNER_VOLUMES}/orbitdb:/mnt/concordia/orbitdb -v ${PINNER_VOLUMES}:/mnt/concordia/logs --env-file=./env/pinner.env -e NODE_ENV=production --net=host --name concordia-pinner ecentrics/concordia-pinner:latest
# Other
clean-images:

1
docker/env/contracts-provider.env

@ -1 +1,2 @@
UPLOAD_CONTRACTS_DIRECTORY=/mnt/concordia/contracts/
LOGS_PATH=/mnt/concordia/logs/

1
docker/env/pinner.env

@ -1,5 +1,6 @@
USE_EXTERNAL_CONTRACTS_PROVIDER=true
ORBIT_DIRECTORY=/mnt/concordia/orbitdb
LOGS_PATH=/mnt/concordia/logs/
CONTRACTS_PROVIDER_HOST=concordia-contracts-provider
CONTRACTS_PROVIDER_PORT=8400

4
packages/concordia-app/.eslintrc.js

@ -41,10 +41,10 @@ module.exports = {
'react-hooks/exhaustive-deps': 'error',
'max-len': ['warn', {'code': 120, 'tabWidth': 4}],
'no-unused-vars': 'warn',
'no-console': 'warn',
'no-console': ['warn', {allow: ['warn', 'error']}],
'no-shadow': 'warn',
"no-multi-str": "warn",
"jsx-a11y/label-has-associated-control": [ 2, {
"jsx-a11y/label-has-associated-control": [2, {
"labelAttributes": ["label"],
"controlComponents": ["Input"],
"depth": 3,

2
packages/concordia-app/src/components/ClearDatabasesModal/index.jsx

@ -36,7 +36,7 @@ const ClearDatabasesModal = (props) => {
purgeIndexedDBs()
.then(() => {
onDatabasesCleared();
}).catch((reason) => console.log(reason));
}).catch((reason) => console.error(reason));
}, [onDatabasesCleared]);
const onCancelTry = useCallback(() => {

2
packages/concordia-app/src/components/PostCreate/index.jsx

@ -95,7 +95,7 @@ const PostCreate = (props) => {
setCreatePostCacheSendStackId('');
})
.catch((reason) => {
console.log(reason);
console.error(reason);
});
setStoringPost(true);

2
packages/concordia-app/src/views/Profile/GeneralTab/EditInformationModal/index.jsx

@ -124,7 +124,7 @@ const EditInformationModal = (props) => {
// TODO: display a message
})
.catch((reason) => {
console.log(reason);
console.error(reason);
});
if (usernameInput !== initialUsername) {

2
packages/concordia-app/src/views/Register/PersonalInformationStep/index.jsx

@ -94,7 +94,7 @@ const PersonalInformationStep = (props) => {
Promise.resolve())
.then(() => pushNextStep())
.catch((reason) => {
console.log(reason);
console.error(reason);
});
}
}, [error, locationInput, profilePictureInput, pushNextStep]);

2
packages/concordia-app/src/views/Topic/TopicCreate/index.jsx

@ -80,7 +80,7 @@ const TopicCreate = (props) => {
history.push(`/topics/${topicId}`);
})
.catch((reason) => {
console.log(reason);
console.error(reason);
});
}
}

1
packages/concordia-contracts-provider/.gitignore

@ -11,6 +11,7 @@
# Logs
/log
/logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*

4
packages/concordia-contracts-provider/package.json

@ -17,8 +17,10 @@
"express-async-handler": "^1.1.4",
"helmet": "^4.4.1",
"lodash": "^4.17.20",
"morgan": "^1.10.0",
"multer": "^1.4.2",
"multiparty": "^4.2.2"
"multiparty": "^4.2.2",
"winston": "^3.3.3"
},
"devDependencies": {
"eslint": "^7.19.0",

2
packages/concordia-contracts-provider/src/constants.js

@ -2,8 +2,10 @@ import path from 'path';
const UPLOAD_CONTRACTS_DIRECTORY = path.join(__dirname, '..', 'contracts-uploads');
const CORS_ALLOWED_ORIGINS = ['http://127.0.0.1:7000', 'http://localhost:7000'];
const LOGS_PATH = path.join(__dirname, '..', 'logs');
export default {
uploadsDirectory: UPLOAD_CONTRACTS_DIRECTORY,
corsAllowedOrigins: CORS_ALLOWED_ORIGINS,
logsPath: LOGS_PATH,
};

7
packages/concordia-contracts-provider/src/controllers/download.js

@ -1,6 +1,7 @@
import { promises as fs, constants } from 'fs';
import path from 'path';
import { getStorageLocation, getTagsDirectory } from '../utils/storageUtils';
import { logger } from '../utils/logger';
const readContractFilesToArray = (contractsDirectoryPath) => fs
.readdir(contractsDirectoryPath)
@ -8,7 +9,11 @@ const readContractFilesToArray = (contractsDirectoryPath) => fs
.map((contractFilename) => fs
.readFile(path.join(`${contractsDirectoryPath}/${contractFilename}`), 'utf-8')
.then((rawContractData) => JSON.parse(rawContractData))))
.then((contractObjectPromises) => Promise.all([...contractObjectPromises]));
.then((contractObjectPromises) => Promise.all([...contractObjectPromises]))
.then((contracts) => {
logger.info(`Successfully read ${contracts.length} contract(s) from dir: ${contractsDirectoryPath}`);
return contracts;
});
const downloadContracts = async (req, res) => {
const { params: { hash: identifier } } = req;

13
packages/concordia-contracts-provider/src/controllers/upload.js

@ -2,6 +2,7 @@ import path from 'path';
import { constants, promises as fs } from 'fs';
import uploadFilesUsingMiddleware from '../middleware/upload';
import { getStorageLocation, getTagsDirectory } from '../utils/storageUtils';
import { logger } from '../utils/logger';
const provisionContractsDirectory = (req) => {
const { params: { hash } } = req;
@ -11,7 +12,11 @@ const provisionContractsDirectory = (req) => {
.access(contractsPath, constants.W_OK)
.then(() => fs.rmdir(contractsPath, { recursive: true }))
.catch(() => Promise.resolve())
.then(() => fs.mkdir(contractsPath, { recursive: true }));
.then(() => fs.mkdir(contractsPath, { recursive: true }))
.then((ignored) => {
logger.info(`Provisioned new contracts directory: ${contractsPath}`);
return ignored;
});
};
const addOrTransferTag = (tag, hash) => {
@ -20,7 +25,11 @@ const addOrTransferTag = (tag, hash) => {
return fs
.mkdir(tagsDirectory, { recursive: true })
.then(() => fs.writeFile(tagFilePath, hash, 'utf-8'));
.then(() => fs.writeFile(tagFilePath, hash, 'utf-8'))
.then((ignored) => {
logger.info(`Tag modified: ${tag} -> ${hash}`);
return ignored;
});
};
const uploadContracts = async (req, res) => provisionContractsDirectory(req)

12
packages/concordia-contracts-provider/src/index.js

@ -1,14 +1,23 @@
import express from 'express';
import morgan from 'morgan';
import cors from 'cors';
import helmet from 'helmet';
import { contractsProviderPort } from 'concordia-shared/src/environment/interpolated/contractsProvider';
import fs from 'fs';
import path from 'path';
import initRoutes from './routes/web';
import constants from './constants';
import { logger, logsDirectoryPath } from './utils/logger';
const accessLogStream = fs.createWriteStream(path.join(logsDirectoryPath, 'access.log'), { flags: 'a' });
logger.info('Service setting up.');
const ALLOWED_ORIGINS = process.env.CORS_ALLOWED_ORIGINS
? process.env.CORS_ALLOWED_ORIGINS.split(';')
: constants.corsAllowedOrigins;
logger.info(`Allowed origins: ${ALLOWED_ORIGINS.join(', ')}`);
const app = express();
const corsOptions = {
@ -19,9 +28,10 @@ const corsOptions = {
app.use(express.urlencoded({ extended: true }));
app.use(cors(corsOptions));
app.use(helmet());
app.use(morgan('combined', { stream: accessLogStream }));
initRoutes(app);
app.listen(contractsProviderPort, () => {
console.log(`Contracts provider listening at http://127.0.0.1:${contractsProviderPort}`);
logger.info(`Contracts provider listening at http://127.0.0.1:${contractsProviderPort}`);
});

9
packages/concordia-contracts-provider/src/utils/logger.js

@ -0,0 +1,9 @@
import winston from 'winston';
import fs from 'fs';
import getLogger from 'concordia-shared/src/logging/node/winstonLogUtils';
import constants from '../constants';
export const logsDirectoryPath = process.env.LOGS_PATH || constants.logsPath;
fs.mkdirSync(logsDirectoryPath, { recursive: true });
export const logger = getLogger(winston, logsDirectoryPath, 'concordia-contracts-provider');

1
packages/concordia-pinner/.gitignore

@ -15,6 +15,7 @@ packages/concordia-contracts/build
# Logs
/log
/logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*

2
packages/concordia-pinner/package.json

@ -29,12 +29,14 @@
"libp2p-tcp": "~0.15.1",
"libp2p-webrtc-star": "~0.21.1",
"lodash": "^4.17.20",
"morgan": "^1.10.0",
"orbit-db": "~0.26.0",
"orbit-db-identity-provider": "~0.3.1",
"rimraf": "~3.0.2",
"unirest": "^0.6.0",
"web3": "~1.3.0",
"web3-eth-contract": "^1.3.1",
"winston": "^3.3.3",
"wrtc": "~0.4.6"
}
}

18
packages/concordia-pinner/src/app.js

@ -1,11 +1,17 @@
import express from 'express';
import morgan from 'morgan';
import _ from 'lodash';
import fs from 'fs';
import path from 'path';
import isReachable from 'is-reachable';
import { pinnerApiPort } from 'concordia-shared/src/environment/interpolated/pinner';
import getWeb3ProviderUrl from 'concordia-shared/src/utils/web3';
import { getResolvedRendezvousUrl } from './utils/ipfsUtils';
import { logger, logsDirectoryPath } from './utils/logger';
const POLLING_INTERVAL = 1000;
const accessLogStream = fs.createWriteStream(path.join(logsDirectoryPath, 'access.log'), { flags: 'a' });
logger.info('Service setting up.');
const responseBody = {
ipfs: {
@ -18,11 +24,12 @@ const responseBody = {
};
getResolvedRendezvousUrl().then(({ address }) => {
logger.info(`Resolved rendezvous URL to: ${address}`);
responseBody.rendezvous.url = address;
});
const getStats = async (orbit) => {
const { address: resolvedRendezvousUrl } = await getResolvedRendezvousUrl();
logger.info('Gathering stats.');
try {
const ipfs = orbit._ipfs;
@ -34,7 +41,7 @@ const getStats = async (orbit) => {
const orbitIdentity = orbit.identity;
const databases = Object.keys(orbit.stores);
const isWeb3Reachable = await isReachable(getWeb3ProviderUrl());
const isRendezvousReachable = await isReachable(resolvedRendezvousUrl.address);
const isRendezvousReachable = responseBody.rendezvous.url ? await isReachable(responseBody.rendezvous.url) : false;
const timestamp = +new Date();
responseBody.ipfs.id = id;
@ -48,18 +55,21 @@ const getStats = async (orbit) => {
responseBody.rendezvous.reachable = isRendezvousReachable;
responseBody.timestamp = timestamp;
} catch (err) {
console.error('Error while getting stats:', err);
logger.error('Error while getting stats:', err);
}
};
const startAPI = (orbit) => {
const app = express();
app.use(morgan('combined', { stream: accessLogStream }));
app.get('/', async (req, res) => {
res.send(responseBody);
});
app.listen(pinnerApiPort, () => {
console.log(`Pinner API at http://localhost:${pinnerApiPort}!`);
logger.info(`Pinner API at http://localhost:${pinnerApiPort}!`);
});
setInterval(getStats, POLLING_INTERVAL, orbit);

5
packages/concordia-pinner/src/constants.js

@ -1,5 +1,4 @@
import path from 'path';
const ORBIT_DIRECTORY_DEFAULT = path.join(__dirname, '..', 'orbitdb');
export default ORBIT_DIRECTORY_DEFAULT;
export const ORBIT_DIRECTORY_DEFAULT = path.join(__dirname, '..', 'orbitdb');
export const LOGS_PATH = path.join(__dirname, '..', 'logs');

15
packages/concordia-pinner/src/index.js

@ -8,16 +8,17 @@ import { createOrbitInstance, getPeerDatabases, openKVDBs } from './utils/orbitU
import startAPI from './app';
import downloadContractArtifacts from './utils/drizzleUtils';
import getIpfsOptions from './options/ipfsOptions';
import { logger } from './utils/logger';
process.on('unhandledRejection', (error) => {
// This happens when attempting to initialize without any available Swarm addresses (e.g. Rendezvous)
if (error.code === 'ERR_NO_VALID_ADDRESSES') {
console.error('unhandledRejection', error.message);
logger.error(`unhandledRejection: ${error.message}`);
process.exit(1);
}
// Don't swallow other errors
console.error(error);
logger.error(error);
throw error;
});
@ -25,7 +26,6 @@ const getDeployedContract = async (web3) => {
let forumContractPromise;
if (process.env.USE_EXTERNAL_CONTRACTS_PROVIDER) {
console.log('Downloading contracts.');
forumContractPromise = downloadContractArtifacts()
.then((remoteContracts) => remoteContracts
.find((remoteContract) => remoteContract.contractName === FORUM_CONTRACT));
@ -57,14 +57,15 @@ const handleWeb3LogEvent = (web3, eventJsonInterface, orbit) => (error, result)
result.topics.slice(1),
);
const userAddress = eventObj[1];
console.log('User signed up:', userAddress);
logger.info(`User signed up: ${userAddress}`);
getPeerDatabases(orbit, [userAddress])
.then((peerDBs) => openKVDBs(orbit, peerDBs));
}
};
const main = async () => {
console.log('Initializing...');
logger.info('Initializing IPFS and orbitDb.');
const web3 = new Web3(new Web3.providers.WebsocketProvider(getWeb3ProviderUrl()));
getDeployedContract(web3)
@ -87,11 +88,11 @@ const main = async () => {
orbit._ipfs.libp2p.connectionManager.on(
'peer:connect',
(peerInfo) => console.log('Peer connected: ', peerInfo.remotePeer.toB58String()),
(peerInfo) => logger.info(`Peer connected: ${peerInfo.remotePeer.toB58String()}`),
);
orbit._ipfs.libp2p.connectionManager.on(
'peer:disconnect',
(peerInfo) => console.log('Peer disconnected: ', peerInfo.remotePeer.toB58String()),
(peerInfo) => logger.info(`Peer disconnected: ${peerInfo.remotePeer.toB58String()}`),
);
startAPI(orbit);
})));

5
packages/concordia-pinner/src/options/ipfsOptions.js

@ -1,7 +1,12 @@
import getLibp2pBundle from './libp2pBundle';
import { getSwarmAddresses } from '../utils/ipfsUtils';
import { logger } from '../utils/logger';
const getIpfsOptions = async () => getSwarmAddresses()
.then((swarmAddresses) => {
logger.info(`Swarm addresses used: ${swarmAddresses.join(', ')}`);
return swarmAddresses;
})
.then((swarmAddresses) => ({
repo: 'ipfs',
config: {

17
packages/concordia-pinner/src/utils/drizzleUtils.js

@ -6,29 +6,42 @@ import {
} from 'concordia-shared/src/environment/interpolated/contractsProvider';
import { pinnerApiHost, pinnerApiPort } from 'concordia-shared/src/environment/interpolated/pinner';
import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames';
import { logger } from './logger';
function getContractsDownloadRequest() {
const HOST = pinnerApiHost;
const PORT = pinnerApiPort;
const contractsProviderAddress = `http://${contractsProviderHost}:${contractsProviderPort}/contracts/\
${contractsVersionHash}`;
const selfAddress = `${HOST}:${PORT}`;
logger.info(`Trying contracts provider address: ${contractsProviderAddress}`);
logger.info(`Sending with CORS address: ${selfAddress}`);
return unirest(
'GET',
`http://${contractsProviderHost}:${contractsProviderPort}/contracts/${contractsVersionHash}`,
contractsProviderAddress,
).headers({
'Access-Control-Allow-Origin': `${HOST}:${PORT}`,
'Access-Control-Allow-Origin': selfAddress,
'Access-Control-Allow-Credentials': 'true',
});
}
const validateRemoteContracts = (remoteContracts) => {
logger.info('Validating remote contracts.');
if (!remoteContracts
.map((remoteContract) => remoteContract.contractName)
.includes(FORUM_CONTRACT)) {
throw new Error('Forum contract is missing from artifacts.');
}
logger.info('Remote contracts valid.');
};
const downloadContractArtifacts = () => {
logger.info('Downloading contracts.');
const request = getContractsDownloadRequest();
return new Promise((resolve, reject) => request

3
packages/concordia-pinner/src/utils/ipfsUtils.js

@ -1,11 +1,12 @@
import dns from 'dns';
import util from 'util';
import { rendezvousHost, rendezvousPort } from 'concordia-shared/src/environment/interpolated/rendezvous';
import { logger } from './logger';
const dnsLookup = util.promisify(dns.lookup);
export const getResolvedRendezvousUrl = async () => dnsLookup(rendezvousHost, { family: 4 })
.catch((error) => console.error(new Error(`DNS lookup of ${rendezvousHost} failed.\n${error}`)));
.catch((error) => logger.error(new Error(`DNS lookup of ${rendezvousHost} failed.\n${error}`)));
export const getSwarmAddresses = async () => getResolvedRendezvousUrl()
.then((resolvedRendezvousUrl) => [`/ip4/${resolvedRendezvousUrl.address}/tcp/${rendezvousPort}/wss/p2p-webrtc-star`]);

9
packages/concordia-pinner/src/utils/logger.js

@ -0,0 +1,9 @@
import winston from 'winston';
import fs from 'fs';
import getLogger from 'concordia-shared/src/logging/node/winstonLogUtils';
import { LOGS_PATH } from '../constants';
export const logsDirectoryPath = process.env.LOGS_PATH || LOGS_PATH;
fs.mkdirSync(logsDirectoryPath, { recursive: true });
export const logger = getLogger(winston, logsDirectoryPath, 'concordia-pinner');

7
packages/concordia-pinner/src/utils/orbitUtils.js

@ -2,7 +2,8 @@ import OrbitDB from 'orbit-db';
import Identities from 'orbit-db-identity-provider';
import { EthereumContractIdentityProvider } from '@ezerous/eth-identity-provider';
import Web3 from 'web3';
import ORBIT_DIRECTORY_DEFAULT from '../constants';
import { ORBIT_DIRECTORY_DEFAULT } from '../constants';
import { logger } from './logger';
// TODO: share code below with frontend (?)
const determineDBAddress = async ({
@ -40,7 +41,7 @@ export const openKVDBs = async (orbit, databases) => {
.forEach((database) => {
orbit
.keyvalue(database)
.then((store) => store.events.on('replicated', (address) => console.log(`Replicated ${address}`)));
console.log(`Opened ${database}`);
.then((store) => store.events.on('replicated', (address) => logger.info(`Replicated ${address}`)));
logger.info(`Opened ${database}`);
});
};

48
packages/concordia-shared/src/logging/node/winstonLogUtils.js

@ -0,0 +1,48 @@
const path = require('path');
const getLogger = (winston, logsDirectory, serviceName) => {
const transports = [
new winston.transports.File({
filename: path.join(logsDirectory, 'error.log'),
level: 'error',
}),
new winston.transports.File({
filename: path.join(logsDirectory, 'combined.log'),
}),
];
const exceptionHandlers = [
new winston.transports.File({ filename: path.join(logsDirectory, 'exceptions.log') }),
];
if (process.env.NODE_ENV !== 'production') {
transports.push(new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.timestamp(),
winston.format.simple(),
),
}));
exceptionHandlers.push(new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.timestamp(),
winston.format.simple(),
),
}));
}
return winston.createLogger({
level: process.env.NODE_ENV === 'production' ? 'info' : 'silly',
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json(),
),
defaultMeta: { service: serviceName },
transports,
exceptionHandlers,
});
};
module.exports = getLogger;

1765
yarn.lock

File diff suppressed because it is too large
Loading…
Cancel
Save