Giter VIP home page Giter VIP logo

Comments (4)

vietmobilefolk avatar vietmobilefolk commented on May 27, 2024 1

Two options to customize file and folder are: fileName and filePath
not loggerPath

from react-native-logs.

alessandro-bottamedi avatar alessandro-bottamedi commented on May 27, 2024

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.

creambyemute avatar creambyemute commented on May 27, 2024

@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.

alessandro-bottamedi avatar alessandro-bottamedi commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.