Skip to content

chore(2771): Logging to files#2772

Merged
islathehut merged 17 commits into4.0.3from
chore/2771-log-to-file
Mar 13, 2025
Merged

chore(2771): Logging to files#2772
islathehut merged 17 commits into4.0.3from
chore/2771-log-to-file

Conversation

@islathehut
Copy link
Copy Markdown
Collaborator

@islathehut islathehut commented Mar 12, 2025

Pull Request Checklist

  • I have linked this PR to a related GitHub issue.
  • I have added a description of the change (and Github issue number, if any) to the root CHANGELOG.md.

(Optional) Mobile checklist

Please ensure you completed the following checks if you did any changes to the mobile package:

  • I have run e2e tests for mobile
  • I have updated base screenshots for visual regression tests

@islathehut islathehut linked an issue Mar 12, 2025 that may be closed by this pull request
@islathehut islathehut marked this pull request as ready for review March 12, 2025 03:58
@islathehut islathehut changed the base branch from develop to 4.0.3 March 12, 2025 06:08
islathehut and others added 3 commits March 12, 2025 02:10
@islathehut islathehut requested a review from adrastaea March 12, 2025 10:47
@@ -0,0 +1,79 @@
// @ts-ignore
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of dumb but I had to do it because we can't use anything that uses the fs package in ios or android. We have to split it up amongst the desktop/node environments and mobile.

@@ -0,0 +1,17 @@
--- node_modules/react-native-file-logger/android/src/main/AndroidManifest.xml 2025-03-11 23:02:55
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two patches implement functionality that it's in review on react-native-file-logger but haven't been released yet.

Comment on lines +153 to +164
const char *logs = "/logs";
jstring logs_js = env->NewStringUTF(logs);
jclass cls_StringBuilder = env->FindClass("java/lang/StringBuilder");
jmethodID ctr_StringBuilder = env->GetMethodID(cls_StringBuilder, "<init>", "(I)V");
jobject stringBuilder = env->NewObject(cls_StringBuilder, ctr_StringBuilder, 100);
jmethodID mid_StringBuilder_append = env->GetMethodID(cls_StringBuilder, "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;");
for (auto str: { dataPath, logs_js }) {
env->CallObjectMethod(stringBuilder, mid_StringBuilder_append, str);
}
jmethodID mid_StringBuilder_toString = env->GetMethodID(cls_StringBuilder, "toString", "()Ljava/lang/String;");
auto js_log_path = (jstring) env->CallObjectMethod(stringBuilder, mid_StringBuilder_toString);
const char* log_path = env->GetStringUTFChars(js_log_path, nullptr);
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned before I'm not great with C++, this is what came up when I searched how to concatenate two jstring variables. I have to imagine there's a simpler way but this works.


// @ts-ignore
nodeConsoleLogger[printLevel](...formattedLogStrings)
this.internalLogMethod(level, formattedLogStrings.join(' '))
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows us to easily swap in different log mechanisms depending on the envrionment.

import { createQuietLogger, DEFAULT_INTERNAL_LOG_METHOD, __nodeConsoleLogger } from '@quiet/logger'

export const createLogger = createQuietLogger('identity')
export const createLogger = (() => {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everywhere that I'm doing this funky try/catch is meant to avoid the fs import errors on mobile. The only place we load this package is in desktop environments and the backend so any of these common packages won't break in a react native environment.

let splash: BrowserWindow | null
let invitationUrl: string | null

if (isDev || process.env.DATA_DIR) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic just got moved to loadMainEnvs so we could ensure the log env variables are set as early as possible.

@islathehut islathehut merged commit 50dd43f into 4.0.3 Mar 13, 2025
21 of 28 checks passed
islathehut added a commit that referenced this pull request Mar 18, 2025
* Publish

 - @quiet/desktop@4.0.3-alpha.0
 - @quiet/mobile@4.0.3-alpha.0

* Update packages CHANGELOG.md

* Update CHANGELOG.md

* chore(2771): Logging to files (#2772)

* Log to files alongside console via winston

* Add flag for skipping to log to file

* Update index.ts

* Update CHANGELOG.md

* Add support for mobile

* Fix dependency issues

* Fix CI bootstrap

* Test fixes

* Fix mocks

* Remove debug logs

* Publish

 - @quiet/desktop@4.0.3-alpha.1
 - @quiet/mobile@4.0.3-alpha.1

* Update packages CHANGELOG.md

* Fix falsy check

* Another bad boolean check

* Publish

 - @quiet/desktop@4.0.3-alpha.2
 - @quiet/mobile@4.0.3-alpha.2

* Update packages CHANGELOG.md

* fix(2770): Avoid continuous redials, better queued redials, libp2p uses QuietLogger (#2773)

* Use QuietLogger in libp2p and better redials/reconnects

* Update snapshots

* Bump up some timeouts for tests and tweak redial settings

* More tweaks

* Update snapshots

* Publish

 - @quiet/desktop@4.0.3-alpha.3
 - @quiet/mobile@4.0.3-alpha.3

* Update packages CHANGELOG.md

* Update READMEs and comments

* Update package.json

* Update package version and fix parallel logs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Log to file

1 participant