Skip to content

The same log will be written multiple times #86

@zrina1314

Description

@zrina1314

I found that during the development stage, every time I reload RN, the same log would be written to the file multiple times.

This issue only exists on iOS; it's normal on Android

I call the FileLogger.configure function in the App.tsx entry file, so every time I reload, I call the native configure function of ios

The following is part of my log file

025-07-02 20:32:06 791 [INFO]  __zyf__ dy7bh7o5kze
2025-07-02 20:32:06 791 [INFO]  __zyf__ dy7bh7o5kze
2025-07-02 20:32:06 791 [INFO]  __zyf__ dy7bh7o5kze
2025-07-02 20:32:06 791 [INFO]  __zyf__ dy7bh7o5kze
2025-07-02 20:32:06 791 [INFO]  {"time":"2025-07-02 20:32:06 790","id":"#58802C","operationType":"add","status":"fileUp","bigData":{"key_0":"value_0_ykfarpfsc3n","key_1":"value_1_xty0d6cqhff","key_2":"value_2_utn24nlvwp","key_3":"value_3_xu57bhxcuv","key_4":"value_4_0dsn7geb4kl5"}}
2025-07-02 20:32:06 791 [INFO]  {"time":"2025-07-02 20:32:06 790","id":"#58802C","operationType":"add","status":"fileUp","bigData":{"key_0":"value_0_ykfarpfsc3n","key_1":"value_1_xty0d6cqhff","key_2":"value_2_utn24nlvwp","key_3":"value_3_xu57bhxcuv","key_4":"value_4_0dsn7geb4kl5"}}
2025-07-02 20:32:06 791 [INFO]  {"time":"2025-07-02 20:32:06 790","id":"#58802C","operationType":"add","status":"fileUp","bigData":{"key_0":"value_0_ykfarpfsc3n","key_1":"value_1_xty0d6cqhff","key_2":"value_2_utn24nlvwp","key_3":"value_3_xu57bhxcuv","key_4":"value_4_0dsn7geb4kl5"}}
2025-07-02 20:32:06 791 [INFO]  {"time":"2025-07-02 20:32:06 790","id":"#58802C","operationType":"add","status":"fileUp","bigData":{"key_0":"value_0_ykfarpfsc3n","key_1":"value_1_xty0d6cqhff","key_2":"value_2_utn24nlvwp","key_3":"value_3_xu57bhxcuv","key_4":"value_4_0dsn7geb4kl5"}}
2025-07-02 20:32:12 756 [INFO]  __zyf__ f35lltqxt4l
2025-07-02 20:32:12 756 [INFO]  __zyf__ f35lltqxt4l
2025-07-02 20:32:12 756 [INFO]  __zyf__ f35lltqxt4l
2025-07-02 20:32:12 756 [INFO]  __zyf__ f35lltqxt4l

This is my business code. Each time the write method is called, an additional random number is printed to observe the number of times the same log is printed

  public info(msg: string) {
    FileLogger.info(`__zyf__ ${randomStr()}`);
    FileLogger.info(msg);
  }

The number of times the print is reprinted is the same as the number of times reload RN。

I analyzed the source code and found that the fileLogger object in filelogger.mm in the iOS source code is not a singleton

    if (self.fileLogger) {      // --->>>  Here, each reload is an empty value, resulting in a fileLogger instance. This is the reason why the log is written multiple times
        [DDLog removeLogger:self.fileLogger];
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions