Comments (4)
Two options to customize file and folder are: fileName and filePath
not loggerPath
from react-native-logs.
Hi, i've just added the possibility to set transports options, as you can see in the docs now you can change the file name for the rnFsFileAsync (the transportOptions.loggerName property).
Abaout the path, in order to maintain the highest compatibility between android and ios for now I have left RNFS.DocumentDirectoryPath as I'm sure it works on all devices.
Did you have any advice to handle the path?
from react-native-logs.
@alessandro-bottamedi I'd say make the path optional, if provided use that path, otherwise default to RNFS.DocumentDirectoryPath?
For the meantime I created my own customFsLog function which is called by my customLogger
private customLogger: transportFunctionType = async (msg: any, level: any) => {
if (this.logLevel === "error") {
if (this.isString(msg)) {
Analytics.trackEvent(this.logTag, { msg: msg as string });
} else if (this.isErrorObject(msg)) {
Analytics.trackEvent(this.logTag, msg);
} else if (this.isObject(msg)) {
Analytics.trackEvent(this.logTag, msg);
}
}
const logMessage = `${this.logTag}: ${JSON.stringify(msg)}`;
this.fsLog(logMessage, level);
if (__DEV__) {
switch (this.logLevel) {
case "info":
console.log(logMessage);
break;
case "warn":
case "error":
console.warn(logMessage);
break;
default:
break;
}
}
};
private fsLog: transportFunctionType = async (msg: any, level: any) => {
const output = `${new Date().toLocaleString()} | ${level.text.toUpperCase()} | ${msg}\n`;
const filePath = LowDBAdapter.path
? `${stores.rootStore.authStore.userDirectoryPath}rnfslogs.txt`
: `${Constants.DatabaseDir}/rnfslogs.txt`;
RNFS.appendFile(filePath, output, "utf8")
.then(() => {})
.catch((err: any) => {
console.warn(err);
});
};
We're using DocumentDirectoryPath as well
const DatabaseDir = Platform.select({
ios: `${RNFS.DocumentDirectoryPath}`,
android: `${RNFS.DocumentDirectoryPath}/../databases`
});
const DownloadDir = Platform.select({
ios: `${RNFS.DocumentDirectoryPath}`,
android: `${RNFS.DownloadDirectoryPath}`
});
I'm fine if you don't add the path as it's pretty easy/straightforward to setup a custom fs log already as shown above.
I think this is even the better solution as like this, the library does not have to care about directory locations/permissions.
from react-native-logs.
I added the option to set the path for rnFsFileAsync.
To set the path and filename after "RNFS.DocumentDirectoryPath" we can use the fileName option.
if someone wants to change the path "RNFS.DocumentDirectoryPath", they can use the filePath option.
All TransportOptions are not required to keep the library easy to use.
from react-native-logs.
Related Issues (20)
- Any reason why logType isn't exported? HOT 1
- fileAsyncTransport() error HOT 4
- Suggested improvements to fileAsyncTransport. HOT 2
- Bug: function type log arguments are printed as `null` HOT 3
- Disable not working HOT 2
- Type errors with noUncheckedIndexedAccess HOT 2
- extensionColors not working on zsh macOS terminal HOT 1
- In transportOptions I'm Not able generate logs.txt file HOT 7
- I'm not able to generate and save(see) log in file manager (storage) of mobile device HOT 1
- how we can access log.txt file in iOS device HOT 5
- Queue? HOT 1
- Open to adding custom formatting support? HOT 2
- Sentry transporter seems to log always to error despite using info/debug.. HOT 2
- Is it possible to store file in Zip(compressed log.txt file) with in cache directory HOT 1
- NSMallocException - Expo device build fatal crash with FileAsyncTransport HOT 1
- Is there a way to pass types to transport function props? HOT 1
- today date formatting is incorrectly described in the docs HOT 1
- Logging to a log level with undefined transport causes app to crash HOT 2
- Using react-native-logs in a regular 'react' web app? HOT 2
- Date format with using {date-today} HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-logs.