mirror of https://github.com/waku-org/js-waku.git
Segregate logs files in single directory
This commit is contained in:
parent
548c50668a
commit
a6cbdf3117
|
@ -0,0 +1,22 @@
|
|||
import fs, { promises as asyncFs } from 'fs';
|
||||
import { promisify } from 'util';
|
||||
|
||||
import { delay } from './delay';
|
||||
export const existsAsync = (filepath: string) =>
|
||||
asyncFs.access(filepath, fs.constants.F_OK);
|
||||
|
||||
export const openAsync = promisify(fs.open);
|
||||
|
||||
export const mkdirAsync = asyncFs.mkdir;
|
||||
|
||||
export async function waitForFile(path: string) {
|
||||
let found = false;
|
||||
do {
|
||||
try {
|
||||
await existsAsync(path);
|
||||
found = true;
|
||||
} catch (e) {
|
||||
await delay(500);
|
||||
}
|
||||
} while (!found);
|
||||
}
|
|
@ -1,24 +1,7 @@
|
|||
import fs, { promises as asyncFs } from 'fs';
|
||||
|
||||
import pTimeout from 'p-timeout';
|
||||
import { Tail } from 'tail';
|
||||
|
||||
import { delay } from './delay';
|
||||
|
||||
const existsAsync = (filepath: string) =>
|
||||
asyncFs.access(filepath, fs.constants.F_OK);
|
||||
|
||||
async function waitForFile(path: string) {
|
||||
let found = false;
|
||||
do {
|
||||
try {
|
||||
await existsAsync(path);
|
||||
found = true;
|
||||
} catch (e) {
|
||||
await delay(500);
|
||||
}
|
||||
} while (!found);
|
||||
}
|
||||
import { waitForFile } from './async_fs';
|
||||
|
||||
export default async function waitForLine(filepath: string, logLine: string) {
|
||||
await pTimeout(waitForFile(filepath), 2000);
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import { ChildProcess, spawn } from 'child_process';
|
||||
import { randomInt } from 'crypto';
|
||||
import * as fs from 'fs';
|
||||
import { promisify } from 'util';
|
||||
|
||||
import axios from 'axios';
|
||||
import Multiaddr from 'multiaddr';
|
||||
|
@ -11,14 +9,15 @@ import PeerId from 'peer-id';
|
|||
import { Message } from '../lib/waku_message';
|
||||
import { TOPIC } from '../lib/waku_relay';
|
||||
|
||||
import { existsAsync, mkdirAsync, openAsync } from './async_fs';
|
||||
import waitForLine from './log_file';
|
||||
|
||||
const openAsync = promisify(fs.open);
|
||||
|
||||
const NIM_WAKU_DEFAULT_P2P_PORT = 60000;
|
||||
const NIM_WAKU_DEFAULT_RPC_PORT = 8545;
|
||||
const NIM_WAKU_BIN = '/home/froyer/src/status-im/nim-waku/build/wakunode2';
|
||||
|
||||
const LOG_DIR = './log';
|
||||
|
||||
export interface Args {
|
||||
staticnode?: string;
|
||||
nat?: 'none';
|
||||
|
@ -41,10 +40,21 @@ export class NimWaku {
|
|||
|
||||
const logFilePrefix = testName.replace(/ /g, '_').replace(/[':()]/g, '');
|
||||
|
||||
this.logPath = `./${logFilePrefix}-nim-waku.log`;
|
||||
this.logPath = `${LOG_DIR}/${logFilePrefix}-nim-waku.log`;
|
||||
}
|
||||
|
||||
async start(args: Args) {
|
||||
try {
|
||||
await existsAsync(LOG_DIR);
|
||||
} catch (e) {
|
||||
try {
|
||||
await mkdirAsync(LOG_DIR);
|
||||
} catch (e) {
|
||||
// Looks like 2 tests tried to create the director at the same time,
|
||||
// it can be ignored
|
||||
}
|
||||
}
|
||||
|
||||
const logFile = await openAsync(this.logPath, 'w');
|
||||
|
||||
const mergedArgs = defaultArgs();
|
||||
|
|
Loading…
Reference in New Issue