Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let filePath = logPath + '/' + filename;
// create string
let str = '' + new Date().valueOf() + ' - ' + new Date() + " -";
for (let i = 0; i < arguments.length; i++) {
if (typeof arguments[i] === 'object' || Array.isArray(arguments[i])) {
str += " " + JSON.stringify(arguments[i])
}
else {
str += " " + arguments[i]
}
}
str += " \n";
// write the file
RNFS.appendFile(filePath, str, 'utf8')
.then((success) => {})
.catch((err) => {})
}
try {
this.showMessage('Creating combined log...')
const gethLogsSrc = this.getGethLogFilePath()
const rnLogsSrc = this.getReactNativeLogsFilePath()
// The RN library we are using only supports one file attachment. In the longer run, we should
// either find a new library or write a new one. For now, we will put the logs in one file.
// Longer run, we will go for a multi-attachment route. The other problem with our current approach
// is that we have to write this log file into a world-readable directory. Android has a concept of
// one time file access permissions which we cannot use here since the library we are using it
// does not understand that.
const combinedLogsPath = this.getCombinedLogsFilePath()
await RNFS.writeFile(combinedLogsPath, '========React Native Logs========\n')
if (await RNFS.exists(rnLogsSrc)) {
await RNFS.appendFile(combinedLogsPath, await RNFS.readFile(rnLogsSrc))
}
await RNFS.appendFile(combinedLogsPath, '\n\n========Geth Logs========\n')
if (await RNFS.exists(gethLogsSrc)) {
await RNFS.appendFile(combinedLogsPath, await RNFS.readFile(gethLogsSrc))
}
return combinedLogsPath
} catch (e) {
this.showError('Failed to copy files: ' + e)
return false
}
}
}).then(() => {
return RNFS.appendFile(f2, 'baz 𝌆 bar © foo', 'utf8');
}).then(() => {
return RNFS.readFile(f1, 'utf8').then(contents => {
}).then(() => {
return RNFS.appendFile(f1, 'baz 𝌆 bar © foo', 'utf8');
}).then(() => {
return RNFS.appendFile(f2, 'baz 𝌆 bar © foo', 'utf8');
async function writeLog (content) {
try {
const exists = await RNFS.exists(path)
if (exists) {
numWrites++
if (numWrites > NUM_WRITES_BEFORE_ROTATE_CHECK) {
if (await isLogFileLimitExceeded(path)) {
await rotateLogs()
numWrites = 0
}
}
return await RNFS.appendFile(path, '\n' + content)
} else {
return await RNFS.writeFile(path, content)
}
} catch (e) {
global.clog((e && e.message) || e)
}
}
const writeLog = (level: string, message: string) => {
const timestamp = new Date().toISOString()
RNFS.appendFile(logFilePath, `${level} [${timestamp}] ${message}\n`, 'utf8').catch(
(error) => {
oldDebug(`Failed to write to ${logFilePath}`, error)
}
)
}
appendFile(path, string, encoding = 'base64') {
return RNFS.appendFile(path, string, encoding);
}
export const perfLogger = (store: Store) => (next: Next) => (action: Action) => {
const start = Date.now()
const result = next(action)
const end = Date.now()
RNFS.appendFile(perfLoggerCSV, `${action.type},${start},${end}\n`)
return result
}