Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { buildJs, BuildJsCompilationError } from "./commands/buildJs";
import { buildSoy, BuildSoyConfig } from "./commands/buildSoy";
import { cleanDeps } from "./commands/cleanDeps";
import { cleanSoy, CleanSoyConfig } from "./commands/cleanSoy";
import { serve } from "./commands/serve";
import { DuckConfig, loadConfig } from "./duckconfig";
import { setGlobalLogger } from "./logger";
import { ErrorReason, reportTestResults } from "./report";
assertNodeVersionGte(process.version, 10);
/**
* Transform ndjson (Newline Delimited JSON) stream to JSON object stream.
*/
const logStream = split(JSON.parse);
const logger = pino(logStream);
setGlobalLogger(logger);
/**
* Task wrapper that conbines the log stream with the promise to make an
* observable that does not "complete" until the promise is resolved,
* because listr can accept only one of Promise, Stream and Observable.
*/
function wrap(task: () => Promise): () => Observable {
return () => {
// Run the task in the next tick to register the observable to listr before the first logging.
const await = Promise.resolve().then(task);
return streamToObservable(logStream, { await, endEvent: false }).pipe(
map(obj => {
if (obj.msg) {
return String(obj.msg);
} else {
import pino from "pino";
import url from "url";
import { Application } from "./application";
import { requestTwilioTurnServer } from "./turn";
import { Win } from "./win";
// we'll export this and use it for testing
// it won't impact the runtime as the runtime ignores it
let runtimeIgnoredExportSuccess: () => void;
let runtimeIgnoredExportFailure: (err: Error) => void;
const runtimeIgnoredExportValue: Promise = new Promise((resolve, reject) => {
runtimeIgnoredExportSuccess = resolve;
runtimeIgnoredExportFailure = reject;
});
const logger = pino();
/**
* Configure dotenv - Supported values:
* + SERVICE_URL (string) - the web service address (to render)
* + TURN_URL (string) - a turn address
* + TURN_USERNAME (string) - a turn username
* + TURN_PASSWORD (string) - a turn password credential
* + POLL_URL (string) - a signaling server base address
* + POLL_INTERVAL (number) - a signaling poll interval in ms
* + HEIGHT (number) - the window height
* + WIDTH (number) - the window width
* + EXP_HIDE_STREAMER (boolean) - experiment flag for hiding the streamer window
* + TWILIO_ACCOUNT_SID (string) - a Twilio AccountSid required to get a Network Traversal Service Token
* + TWILIO_AUTH_TOKEN (string) - a Twilio AuthToken required to get a Network Traversal Service Token
*/
const dotenv = config();
/**
* Simple logging with bunyan
* @ignore
*/
import pino from 'pino'
import { createWriteStream } from 'fs-extra'
import { PassThrough } from 'stream'
import { stdout } from 'process'
import { electronVersion, isDev, LOG_FILE } from './consts'
const logThrough = new PassThrough()
const logger = pino( {
prettyPrint: isDev && { colorize: true, ignore: 'hostname,pid', translateTime: 'HH:MM:ss.l' },
}, logThrough )
// Only write to file in electron production builds
if ( electronVersion && !isDev ) logThrough.pipe( createWriteStream( LOG_FILE, { flags: 'a' } ) )
// Pipe all log output to stdout in dev only
if ( isDev ) logThrough.pipe( stdout )
export default logger
type: 'string',
}).argv
// instantiate logger
const loggerConfig = {
level: args.logLevel,
prettyPrint: args.prettyLogs,
}
// If the stdout is used for a data output, save all logs to a log file.
// pino writes logs to stdout by default
let logDestination
if (args.output === process.stdout)
logDestination = fs.createWriteStream(args.logFile)
const logger = pino(loggerConfig, logDestination)
// print errors to stderr if we use stdout for data output
// if we save data to output file errors are already logged by pino
const logError = error => {
const errorFormatter = new PrettyError()
if (args.logLevel === 'debug')
process.stderr.write(`ERR: ${errorFormatter.render(error)}`)
else process.stderr.write(`ERR: ${error.message || error}`)
}
const errorHandler = errors => {
if (Array.isArray(errors)) errors.forEach(logError)
else logError(errors)
process.exitCode = 1
type: 'string',
}).argv
// instantiate logger
const loggerConfig = {
level: args.logLevel,
prettyPrint: args.prettyLogs,
}
// If the stdout is used for a data output, save all logs to a log file.
// pino writes logs to stdout by default
let logDestination
if (args.output === process.stdout)
logDestination = fs.createWriteStream(args.logFile)
const logger = pino(loggerConfig, logDestination)
// print errors to stderr if we use stdout for data output
// if we save data to output file errors are already logged by pino
const logError = error => {
const errorFormatter = new PrettyError()
if (args.logLevel === 'debug')
process.stderr.write(`ERR: ${errorFormatter.render(error)}`)
else process.stderr.write(`ERR: ${error.message || error}`)
}
const errorHandler = errors => {
if (Array.isArray(errors)) errors.forEach(logError)
else logError(errors)
process.exitCode = 1
};
export const boxContents = (...texts: string[]) => {
const getLines = (text: string) => text.split("\n").map((line) => line.length);
const splitTexts = chain(getLines);
const maxLength = Math.max(...splitTexts(texts));
const [head, ...tail] = texts;
const spacer = "-".repeat(maxLength);
return tail.reduce((all, text) => [...all, text, spacer], [spacer, head, spacer]).join("\n");
};
export const countMembers = (client: AkairoClient) =>
client.guilds.reduce((all, guild) => guild.memberCount + all, 0);
export const logger = pino({
prettyPrint: process.env.NODE_ENV !== "production",
level: "debug"
});
interface CreateCommand extends CommandOptions {
/**
* The exec function can be called in 3 different ways, however,
* Typescript doesn't seem to be able to support explicit `this`
* coming from external types, union types or overloads. In order to
* specify the `this` type the signature MUST be directly assigned
* in the interface
* @param message
* @param args
* @param edited
*/
exec: (this: Command, message: Message, args: any, edited: boolean) => any;
#!/usr/bin/env node
import { app } from 'app'
import Pino from 'pino'
const logger: Pino.Logger = Pino()
process.on('unhandledRejection', (e) => {
logger.fatal('unhandledRejection', e)
process.exit()
})
process.on('uncaughtException', (e) => {
logger.fatal('uncaughtException', e)
process.exit()
})
app()
.then(server => process.on('SIGINT', () => server.stop()))
.catch(exception => logger.fatal({ exception }, 'server was unable to start'))
export const createModuleLogger = (configuration: LoggingConfiguration) => (dirname: string): Pino.Logger => {
return childWithModuleName(Pino(loggingConfigurationToPinoConfiguration(configuration)), dirname)
}
export function createLogger(_process = process) {
const level = _process.env.LOG_LEVEL || 'fatal';
return pino({ name: 'Dispensary', level }, _process.stdout);
}
import 'Extensions/Array'
import 'Extensions/Error'
import 'Extensions/Promise'
import Pino from 'pino'
import { catchStartupError } from 'Helpers/moduleStartStopCatch'
import { loadConfigurationWithDefaults } from 'LoadConfiguration'
import { EthereumRegistryWriter } from './EthereumRegistryWriter'
const configuration = loadConfigurationWithDefaults()
const logger: Pino.Logger = Pino({
level: configuration.loggingLevel,
prettyPrint: configuration.loggingPretty,
})
EthereumRegistryWriter({
loggingLevel: configuration.loggingLevel,
loggingPretty: configuration.loggingPretty,
apiPort: configuration.ethereumRegistryWriterApiPort,
mongodbUrl: configuration.mongodbUrl,
rabbitmqUrl: configuration.rabbitmqUrl,
ipfs: {
url: configuration.ipfsUrl,
},
exchanges: {
claimIpfsHash: configuration.exchangeClaimIpfsHash,
batchCreated: configuration.exchangeBatchWriterCreateNextBatchSuccess,