fix: app log not being printed (#1790)
Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai>
This commit is contained in:
parent
7ed523e183
commit
b2ff76ce80
@ -2,38 +2,36 @@ import fs from 'fs'
|
|||||||
import util from 'util'
|
import util from 'util'
|
||||||
import { getAppLogPath, getServerLogPath } from './utils'
|
import { getAppLogPath, getServerLogPath } from './utils'
|
||||||
|
|
||||||
export const log = function (message: string) {
|
export const log = (message: string) => {
|
||||||
const appLogPath = getAppLogPath()
|
const path = getAppLogPath()
|
||||||
if (!message.startsWith('[')) {
|
if (!message.startsWith('[')) {
|
||||||
message = `[APP]::${message}`
|
message = `[APP]::${message}`
|
||||||
}
|
}
|
||||||
|
|
||||||
message = `${new Date().toISOString()} ${message}`
|
message = `${new Date().toISOString()} ${message}`
|
||||||
|
|
||||||
if (fs.existsSync(appLogPath)) {
|
writeLog(message, path)
|
||||||
var log_file = fs.createWriteStream(appLogPath, {
|
|
||||||
flags: 'a',
|
|
||||||
})
|
|
||||||
log_file.write(util.format(message) + '\n')
|
|
||||||
log_file.close()
|
|
||||||
console.debug(message)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const logServer = function (message: string) {
|
export const logServer = (message: string) => {
|
||||||
const serverLogPath = getServerLogPath()
|
const path = getServerLogPath()
|
||||||
if (!message.startsWith('[')) {
|
if (!message.startsWith('[')) {
|
||||||
message = `[SERVER]::${message}`
|
message = `[SERVER]::${message}`
|
||||||
}
|
}
|
||||||
|
|
||||||
message = `${new Date().toISOString()} ${message}`
|
message = `${new Date().toISOString()} ${message}`
|
||||||
|
writeLog(message, path)
|
||||||
|
}
|
||||||
|
|
||||||
if (fs.existsSync(serverLogPath)) {
|
const writeLog = (message: string, logPath: string) => {
|
||||||
var log_file = fs.createWriteStream(serverLogPath, {
|
if (!fs.existsSync(logPath)) {
|
||||||
|
fs.writeFileSync(logPath, message)
|
||||||
|
} else {
|
||||||
|
const logFile = fs.createWriteStream(logPath, {
|
||||||
flags: 'a',
|
flags: 'a',
|
||||||
})
|
})
|
||||||
log_file.write(util.format(message) + '\n')
|
logFile.write(util.format(message) + '\n')
|
||||||
log_file.close()
|
logFile.close()
|
||||||
console.debug(message)
|
console.debug(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,32 +1,15 @@
|
|||||||
import { useEffect } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
|
|
||||||
import { fs, AppConfiguration } from '@janhq/core'
|
import { fs, AppConfiguration } from '@janhq/core'
|
||||||
|
|
||||||
import { atom, useAtom } from 'jotai'
|
|
||||||
|
|
||||||
import { useMainViewState } from './useMainViewState'
|
|
||||||
|
|
||||||
const isSameDirectoryAtom = atom(false)
|
|
||||||
const isDirectoryConfirmAtom = atom(false)
|
|
||||||
const isErrorSetNewDestAtom = atom(false)
|
|
||||||
const currentPathAtom = atom('')
|
|
||||||
const newDestinationPathAtom = atom('')
|
|
||||||
|
|
||||||
export const SUCCESS_SET_NEW_DESTINATION = 'successSetNewDestination'
|
export const SUCCESS_SET_NEW_DESTINATION = 'successSetNewDestination'
|
||||||
|
|
||||||
export function useVaultDirectory() {
|
export function useVaultDirectory() {
|
||||||
const [isSameDirectory, setIsSameDirectory] = useAtom(isSameDirectoryAtom)
|
const [isSameDirectory, setIsSameDirectory] = useState(false)
|
||||||
const { setMainViewState } = useMainViewState()
|
const [isDirectoryConfirm, setIsDirectoryConfirm] = useState(false)
|
||||||
const [isDirectoryConfirm, setIsDirectoryConfirm] = useAtom(
|
const [isErrorSetNewDest, setIsErrorSetNewDest] = useState(false)
|
||||||
isDirectoryConfirmAtom
|
const [currentPath, setCurrentPath] = useState('')
|
||||||
)
|
const [newDestinationPath, setNewDestinationPath] = useState('')
|
||||||
const [isErrorSetNewDest, setIsErrorSetNewDest] = useAtom(
|
|
||||||
isErrorSetNewDestAtom
|
|
||||||
)
|
|
||||||
const [currentPath, setCurrentPath] = useAtom(currentPathAtom)
|
|
||||||
const [newDestinationPath, setNewDestinationPath] = useAtom(
|
|
||||||
newDestinationPathAtom
|
|
||||||
)
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
window.core?.api
|
window.core?.api
|
||||||
@ -34,7 +17,6 @@ export function useVaultDirectory() {
|
|||||||
?.then((appConfig: AppConfiguration) => {
|
?.then((appConfig: AppConfiguration) => {
|
||||||
setCurrentPath(appConfig.data_folder)
|
setCurrentPath(appConfig.data_folder)
|
||||||
})
|
})
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const setNewDestination = async () => {
|
const setNewDestination = async () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user