You've already forked joplin
							
							
				mirror of
				https://github.com/laurent22/joplin.git
				synced 2025-10-31 00:07:48 +02:00 
			
		
		
		
	Chore: Trying to fix logger (#8610)
This commit is contained in:
		| @@ -541,6 +541,7 @@ packages/lib/htmlUtils2.test.js | ||||
| packages/lib/import-enex-md-gen.test.js | ||||
| packages/lib/import-enex-md-gen.js | ||||
| packages/lib/import-enex.js | ||||
| packages/lib/initLib.js | ||||
| packages/lib/locale.test.js | ||||
| packages/lib/locale.js | ||||
| packages/lib/markdownUtils.test.js | ||||
|   | ||||
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -526,6 +526,7 @@ packages/lib/htmlUtils2.test.js | ||||
| packages/lib/import-enex-md-gen.test.js | ||||
| packages/lib/import-enex-md-gen.js | ||||
| packages/lib/import-enex.js | ||||
| packages/lib/initLib.js | ||||
| packages/lib/locale.test.js | ||||
| packages/lib/locale.js | ||||
| packages/lib/markdownUtils.test.js | ||||
|   | ||||
| @@ -64,7 +64,7 @@ | ||||
|     } | ||||
|   }, | ||||
|   "devDependencies": { | ||||
|     "@joplin/utils": "~2.11", | ||||
|     "@joplin/utils": "~2.12", | ||||
|     "@seiyab/eslint-plugin-react-hooks": "4.5.1-beta.0", | ||||
|     "@typescript-eslint/eslint-plugin": "5.60.0", | ||||
|     "@typescript-eslint/parser": "5.60.0", | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
|  | ||||
| const { default: Logger, TargetType } = require('@joplin/utils/Logger'); | ||||
| const initLib = require('@joplin/lib/initLib').default; | ||||
|  | ||||
| // TODO: Some libraries required by test-utils.js seem to fail to import with the | ||||
| // jsdom environment. | ||||
| @@ -11,9 +12,16 @@ const logger = new Logger(); | ||||
| logger.addTarget(TargetType.Console); | ||||
| logger.setLevel(Logger.LEVEL_WARN); | ||||
| Logger.initializeGlobalLogger(logger); | ||||
| initLib(logger); | ||||
|  | ||||
|  | ||||
| // @electron/remote requires electron to be running. Mock it. | ||||
| jest.mock('@electron/remote', () => { | ||||
| 	return { require }; | ||||
| 	return { | ||||
| 		require: () => { | ||||
| 			return { | ||||
| 				default: {}, | ||||
| 			}; | ||||
| 		}, | ||||
| 	}; | ||||
| }); | ||||
|   | ||||
| @@ -29,6 +29,7 @@ const EncryptionService = require('@joplin/lib/services/e2ee/EncryptionService') | ||||
| const { FileApiDriverLocal } = require('@joplin/lib/file-api-driver-local'); | ||||
| const React = require('react'); | ||||
| const nodeSqlite = require('sqlite3'); | ||||
| const initLib = require('@joplin/lib/initLib').default; | ||||
|  | ||||
| // Security: If we attempt to navigate away from the root HTML page, it's likely because | ||||
| // of an improperly sanitized link. Prevent this by closing the window before we can | ||||
| @@ -132,6 +133,10 @@ document.addEventListener('click', (event) => { | ||||
| 	event.preventDefault(); | ||||
| }); | ||||
|  | ||||
| const logger = new Logger(); | ||||
| Logger.initializeGlobalLogger(logger); | ||||
| initLib(logger); | ||||
|  | ||||
| app().start(bridge().processArgv()).then((result) => { | ||||
| 	if (!result || !result.action) { | ||||
| 		require('./gui/Root'); | ||||
|   | ||||
| @@ -85,6 +85,7 @@ const SyncTargetWebDAV = require('@joplin/lib/SyncTargetWebDAV.js'); | ||||
| const SyncTargetDropbox = require('@joplin/lib/SyncTargetDropbox.js'); | ||||
| const SyncTargetAmazonS3 = require('@joplin/lib/SyncTargetAmazonS3.js'); | ||||
| import BiometricPopup from './components/biometrics/BiometricPopup'; | ||||
| import initLib from '@joplin/lib/initLib'; | ||||
|  | ||||
| SyncTargetRegistry.addClass(SyncTargetNone); | ||||
| SyncTargetRegistry.addClass(SyncTargetOneDrive); | ||||
| @@ -474,6 +475,7 @@ async function initialize(dispatch: Function) { | ||||
| 	} | ||||
|  | ||||
| 	Logger.initializeGlobalLogger(mainLogger); | ||||
| 	initLib(mainLogger); | ||||
|  | ||||
| 	reg.setLogger(mainLogger); | ||||
| 	reg.setShowErrorMessageBoxHandler((message: string) => { alert(message); }); | ||||
|   | ||||
| @@ -59,7 +59,6 @@ import Resource from './models/Resource'; | ||||
| import { ProfileConfig } from './services/profileConfig/types'; | ||||
| import initProfile from './services/profileConfig/initProfile'; | ||||
| import { parseShareCache } from './services/share/reducer'; | ||||
|  | ||||
| import RotatingLogs from './RotatingLogs'; | ||||
|  | ||||
| const appLogger: LoggerWrapper = Logger.create('App'); | ||||
| @@ -69,6 +68,7 @@ const appLogger: LoggerWrapper = Logger.create('App'); | ||||
|  | ||||
| interface StartOptions { | ||||
| 	keychainEnabled?: boolean; | ||||
| 	setupGlobalLogger?: boolean; | ||||
| } | ||||
|  | ||||
| export default class BaseApplication { | ||||
| @@ -738,6 +738,7 @@ export default class BaseApplication { | ||||
| 	public async start(argv: string[], options: StartOptions = null): Promise<any> { | ||||
| 		options = { | ||||
| 			keychainEnabled: true, | ||||
| 			setupGlobalLogger: true, | ||||
| 			...options, | ||||
| 		}; | ||||
|  | ||||
| @@ -800,18 +801,15 @@ export default class BaseApplication { | ||||
| 		const extraFlags = await this.readFlagsFromFile(`${profileDir}/flags.txt`); | ||||
| 		initArgs = { ...initArgs, ...extraFlags }; | ||||
|  | ||||
| 		const globalLogger = Logger.globalLogger; | ||||
|  | ||||
|  | ||||
|  | ||||
| 		const globalLogger = new Logger(); | ||||
| 		globalLogger.addTarget(TargetType.File, { path: `${profileDir}/log.txt` }); | ||||
| 		if (Setting.value('appType') === 'desktop') { | ||||
| 			globalLogger.addTarget(TargetType.Console); | ||||
| 		if (options.setupGlobalLogger) { | ||||
| 			globalLogger.addTarget(TargetType.File, { path: `${profileDir}/log.txt` }); | ||||
| 			if (Setting.value('appType') === 'desktop') { | ||||
| 				globalLogger.addTarget(TargetType.Console); | ||||
| 			} | ||||
| 			globalLogger.setLevel(initArgs.logLevel); | ||||
| 		} | ||||
| 		globalLogger.setLevel(initArgs.logLevel); | ||||
| 		Logger.initializeGlobalLogger(globalLogger); | ||||
|  | ||||
|  | ||||
|  | ||||
| 		reg.setLogger(Logger.create('') as Logger); | ||||
| 		// reg.dispatch = () => {}; | ||||
|   | ||||
							
								
								
									
										9
									
								
								packages/lib/initLib.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								packages/lib/initLib.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| import Logger from '@joplin/utils/Logger'; | ||||
|  | ||||
| // @joplin/lib has its own copy of the Logger class, however we want it to be | ||||
| // initialised with the same logger instance as the calling application, so that | ||||
| // the lib and app share the same log. This initLib() function is used for this | ||||
| // and must be called by any "app" package that makes use of the lib package. | ||||
| export default (globalLogger: Logger) => { | ||||
| 	Logger.initializeGlobalLogger(globalLogger); | ||||
| }; | ||||
| @@ -63,6 +63,7 @@ const { S3Client } = require('@aws-sdk/client-s3'); | ||||
| const { Dirnames } = require('../services/synchronizer/utils/types'); | ||||
| import RSA from '../services/e2ee/RSA.node'; | ||||
| import { State as ShareState } from '../services/share/reducer'; | ||||
| import initLib from '../initLib'; | ||||
|  | ||||
| // Each suite has its own separate data and temp directory so that multiple | ||||
| // suites can be run at the same time. suiteName is what is used to | ||||
| @@ -173,6 +174,7 @@ logger.addTarget(TargetType.Console); | ||||
| logger.setLevel(LogLevel.Warn); // Set to DEBUG to display sync process in console | ||||
|  | ||||
| Logger.initializeGlobalLogger(logger); | ||||
| initLib(logger); | ||||
|  | ||||
| BaseItem.loadClass('Note', Note); | ||||
| BaseItem.loadClass('Folder', Folder); | ||||
| @@ -916,7 +918,7 @@ class TestApp extends BaseApplication { | ||||
| 		if (!argv.includes('--profile')) { | ||||
| 			argv = argv.concat(['--profile', `tests-build/profile/${uuid.create()}`]); | ||||
| 		} | ||||
| 		argv = await super.start(['', ''].concat(argv)); | ||||
| 		argv = await super.start(['', ''].concat(argv), { setupGlobalLogger: false }); | ||||
|  | ||||
| 		// For now, disable sync and encryption to avoid spurious intermittent failures | ||||
| 		// caused by them interupting processing and causing delays. | ||||
|   | ||||
| @@ -24,6 +24,7 @@ import { RouteResponseFormat, routeResponseFormat } from './utils/routeUtils'; | ||||
| import { parseEnv } from './env'; | ||||
| import storageConnectionCheck from './utils/storageConnectionCheck'; | ||||
| import { setLocale } from '@joplin/lib/locale'; | ||||
| import initLib from '@joplin/lib/initLib'; | ||||
| import checkAdminHandler from './middleware/checkAdminHandler'; | ||||
|  | ||||
| interface Argv { | ||||
| @@ -215,6 +216,7 @@ async function main() { | ||||
| 		formatInfo: `%(date_time)s: ${instancePrefix}%(prefix)s: %(message)s`, | ||||
| 	}); | ||||
| 	Logger.initializeGlobalLogger(globalLogger); | ||||
| 	initLib(globalLogger); | ||||
|  | ||||
| 	if (envFilePath) appLogger().info(`Env variables were loaded from: ${envFilePath}`); | ||||
|  | ||||
|   | ||||
| @@ -25,6 +25,7 @@ import { createCsrfToken } from '../csrf'; | ||||
| import { cookieSet } from '../cookies'; | ||||
| import { parseEnv } from '../../env'; | ||||
| import { URL } from 'url'; | ||||
| import initLib from '@joplin/lib/initLib'; | ||||
|  | ||||
| // Takes into account the fact that this file will be inside the /dist directory | ||||
| // when it runs. | ||||
| @@ -64,6 +65,7 @@ export async function makeTempFileWithContent(content: string | Buffer): Promise | ||||
| function initGlobalLogger() { | ||||
| 	const globalLogger = new Logger(); | ||||
| 	Logger.initializeGlobalLogger(globalLogger); | ||||
| 	initLib(globalLogger); | ||||
| } | ||||
|  | ||||
| let createdDbPath_: string = null; | ||||
|   | ||||
							
								
								
									
										13
									
								
								yarn.lock
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								yarn.lock
									
									
									
									
									
								
							| @@ -5007,17 +5007,6 @@ __metadata: | ||||
|   languageName: unknown | ||||
|   linkType: soft | ||||
| 
 | ||||
| "@joplin/utils@npm:~2.11": | ||||
|   version: 2.11.2 | ||||
|   resolution: "@joplin/utils@npm:2.11.2" | ||||
|   dependencies: | ||||
|     execa: 5.1.1 | ||||
|     fs-extra: 11.1.1 | ||||
|     node-fetch: 2.6.7 | ||||
|   checksum: 95ba577e6e5f7fb2c10e6bdb2694fdaaef31d6f650b5917b70ec35cb720b1357e182458cce894395f7109298847c21ad78932df6d3394fdbc315ecb5fde28630 | ||||
|   languageName: node | ||||
|   linkType: hard | ||||
| 
 | ||||
| "@joplin/utils@workspace:packages/utils, @joplin/utils@~2.12": | ||||
|   version: 0.0.0-use.local | ||||
|   resolution: "@joplin/utils@workspace:packages/utils" | ||||
| @@ -29455,7 +29444,7 @@ __metadata: | ||||
|   version: 0.0.0-use.local | ||||
|   resolution: "root@workspace:." | ||||
|   dependencies: | ||||
|     "@joplin/utils": ~2.11 | ||||
|     "@joplin/utils": ~2.12 | ||||
|     "@seiyab/eslint-plugin-react-hooks": 4.5.1-beta.0 | ||||
|     "@types/fs-extra": 11.0.1 | ||||
|     "@typescript-eslint/eslint-plugin": 5.60.0 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user