Replies: 2 comments
-
|
Not an exact answer to your question but I am using pm2 and that takes care of saving the logs along with some other neat features. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
You could create your own Logger class, e.g. import { Log, LoggerText, type LogLevel } from "crawlee";
import fs from "fs";
import path from "path";
import stripAnsi from "strip-ansi";
const LOG_BASE_DIR = "./storage/custom-logs";
class TeeLogger extends LoggerText {
private file: fs.WriteStream;
constructor(
fileName: string,
options?: ConstructorParameters<typeof LoggerText>[0],
) {
super(options);
this.file = fs.createWriteStream(fileName, {
flags: "a",
});
}
override _outputWithConsole(level: LogLevel, line: string): void {
super._outputWithConsole(level, line);
this.file.write(`${stripAnsi(line)}\n`);
}
close() {
this.file.end();
}
}
fs.mkdirSync(LOG_BASE_DIR, { recursive: true });
const customLog = new Log({
logger: new TeeLogger(path.join(LOG_BASE_DIR, `${Date.now()}.log`), {
skipTime: false,
}),
});
export default customLog; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to log to file and as alternative I am using winston but its not perfect, because crawlee's internal logs are not being picked up by winston
Beta Was this translation helpful? Give feedback.
All reactions