Logs before configure
finishes are lost
#83
-
Similar to #12, I cannot use top level await (running in electron), but I do have a file sink. One workaround that I'm using right now is saving logs in an buffer array and once configure finishes flush those too and replace the buffered logger, but I would love a cleaner solution. Any thoughts? Perhaps logtape can work the same way, if you call the logs before it's configured it saves those into memory. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
You could use |
Beta Was this translation helpful? Give feedback.
-
I'm using |
Beta Was this translation helpful? Give feedback.
-
I understand your situation, and I'm sorry that there isn't a more straightforward solution for this specific case. Unfortunately, the Given the technical constraints, your current buffering approach is actually the most reasonable solution for combining Electron's limitations with non-blocking file I/O. However, if the complexity of maintaining that buffer becomes burdensome, you might consider switching to |
Beta Was this translation helpful? Give feedback.
-
Yup, that makes sense. Thank you for your response and for this great library! The reason I'm using // logger-memory.ts
import { configureSync, LogRecord } from "@logtape/logtape"
const inMemoryRecords: LogRecord[] = []
export function configureMemoryLogger() {
configureSync({
loggers: [
{
category: [],
lowestLevel: "debug",
sinks: ["inMemory"],
},
{
category: ["logtape", "meta"],
lowestLevel: "warning",
sinks: ["inMemory"],
},
],
reset: true,
sinks: {
inMemory: (record: LogRecord) => {
inMemoryRecords.push(record)
},
},
})
}
export function getInMemoryRecords() {
return inMemoryRecords
} // logger-cjs.ts
import { getLogger } from "@logtape/logtape"
import { configureLogger, getLatestLogFilename } from "@privatefolio/node-commons/build/cjs/logger"
import {
configureMemoryLogger,
getInMemoryRecords,
} from "@privatefolio/node-commons/build/cjs/logger-memory"
import { SERVER_LOGS_LOCATION } from "./settings"
configureMemoryLogger()
export const logger = getLogger(["electron"])
configureLogger(SERVER_LOGS_LOCATION, getLatestLogFilename()).then(() => {
// flush memory logger to file
for (const record of getInMemoryRecords()) {
logger[record.level](record.rawMessage as string, record.properties)
}
}) Note: |
Beta Was this translation helpful? Give feedback.
Yup, that makes sense. Thank you for your response and for this great library!
The reason I'm using
nonBlocking: true
is because read & writes happen through multiple threads.Here is the workaround that I'm using, in case someone else in interested: