mirror of https://gitlab.com/ecentrics/concordia
Apostolos Fanakis
4 years ago
25 changed files with 1601 additions and 346 deletions
@ -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,5 +1,4 @@ |
|||||
import path from 'path'; |
import path from 'path'; |
||||
|
|
||||
const ORBIT_DIRECTORY_DEFAULT = path.join(__dirname, '..', 'orbitdb'); |
export const ORBIT_DIRECTORY_DEFAULT = path.join(__dirname, '..', 'orbitdb'); |
||||
|
export const LOGS_PATH = path.join(__dirname, '..', 'logs'); |
||||
export default ORBIT_DIRECTORY_DEFAULT; |
|
||||
|
@ -1,11 +1,12 @@ |
|||||
import dns from 'dns'; |
import dns from 'dns'; |
||||
import util from 'util'; |
import util from 'util'; |
||||
import { rendezvousHost, rendezvousPort } from 'concordia-shared/src/environment/interpolated/rendezvous'; |
import { rendezvousHost, rendezvousPort } from 'concordia-shared/src/environment/interpolated/rendezvous'; |
||||
|
import { logger } from './logger'; |
||||
|
|
||||
const dnsLookup = util.promisify(dns.lookup); |
const dnsLookup = util.promisify(dns.lookup); |
||||
|
|
||||
export const getResolvedRendezvousUrl = async () => dnsLookup(rendezvousHost, { family: 4 }) |
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() |
export const getSwarmAddresses = async () => getResolvedRendezvousUrl() |
||||
.then((resolvedRendezvousUrl) => [`/ip4/${resolvedRendezvousUrl.address}/tcp/${rendezvousPort}/wss/p2p-webrtc-star`]); |
.then((resolvedRendezvousUrl) => [`/ip4/${resolvedRendezvousUrl.address}/tcp/${rendezvousPort}/wss/p2p-webrtc-star`]); |
||||
|
@ -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'); |
@ -0,0 +1,38 @@ |
|||||
|
const path = require('path'); |
||||
|
|
||||
|
const getLogger = (winston, logsDirectory, serviceName) => { |
||||
|
const logger = winston.createLogger({ |
||||
|
level: process.env.NODE_ENV === 'production' ? 'info' : 'silly', |
||||
|
format: winston.format.combine( |
||||
|
winston.format.timestamp(), |
||||
|
winston.format.json(), |
||||
|
), |
||||
|
defaultMeta: { service: serviceName }, |
||||
|
transports: [ |
||||
|
new winston.transports.File({ |
||||
|
filename: path.join(logsDirectory, 'error.log'), |
||||
|
level: 'error', |
||||
|
}), |
||||
|
new winston.transports.File({ |
||||
|
filename: path.join(logsDirectory, 'combined.log'), |
||||
|
}), |
||||
|
], |
||||
|
exceptionHandlers: [ |
||||
|
new winston.transports.File({ filename: path.join(logsDirectory, 'exceptions.log') }), |
||||
|
], |
||||
|
}); |
||||
|
|
||||
|
if (process.env.NODE_ENV !== 'production') { |
||||
|
logger.add(new winston.transports.Console({ |
||||
|
format: winston.format.combine( |
||||
|
winston.format.colorize(), |
||||
|
winston.format.timestamp(), |
||||
|
winston.format.simple(), |
||||
|
), |
||||
|
})); |
||||
|
} |
||||
|
|
||||
|
return logger; |
||||
|
}; |
||||
|
|
||||
|
module.exports = getLogger; |
File diff suppressed because it is too large
Loading…
Reference in new issue