-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Write debug-level log to local file in Sandbox (#1846)
Writes all debug logs, regardless of `LOG_LEVEL` or `DEBUG`, to a local file in `./log` when running the Sandbox. If run within Docker, the log folder is mounted locally so the user can access the logs without having to manually connect to the container. Logs are outputted using `winston`'s [daily-rotate-file](https://www.npmjs.com/package/winston-daily-rotate-file) to prevent logs from growing out of control, and formatted as ndjson, including level, namespace, and timestamp. Note that the winston dependency is only added to the `sandbox` package, all other packages still use foundation's plain log. Example log: ``` $ head -n10 log/aztec-sandbox.debug.log {"level":"info","message":"Setting up Aztec Sandbox, please stand by...","namespace":"aztec:sandbox","timestamp":"2023-08-28T18:49:51.961Z"} {"level":"info","message":"Deploying rollup contracts to L1...","namespace":"aztec:sandbox","timestamp":"2023-08-28T18:49:51.962Z"} {"level":"debug","message":"Deploying contracts...","namespace":"aztec:sandbox","timestamp":"2023-08-28T18:49:51.981Z"} {"level":"debug","message":"Deployed Registry at 0x5fbdb2315678afecb367f032d93f642f64180aa3","namespace":"aztec:sandbox","timestamp":"2023-08-28T18:49:52.003Z"} {"level":"debug","message":"Deployed Inbox at 0xe7f1725e7734ce288f8367e1bb143e90bb3f0512","namespace":"aztec:sandbox","timestamp":"2023-08-28T18:49:52.020Z"} {"level":"debug","message":"Deployed Outbox at 0x9fe46736679d2d9a65f0992f2272de9f3c7fa6e0","namespace":"aztec:sandbox","timestamp":"2023-08-28T18:49:52.033Z"} {"level":"debug","message":"Deployed Rollup at 0xcf7ed3acca5a467e9e704c703e8d87f634fb0fc9","namespace":"aztec:sandbox","timestamp":"2023-08-28T18:49:52.048Z"} {"level":"debug","message":"Deployed contract deployment emitter at 0x5fc8d32690cc91d4c39d9d3abcbd16989f875707","namespace":"aztec:sandbox","timestamp":"2023-08-28T18:49:52.060Z"} {"level":"debug","message":"Performing initial chain sync...","namespace":"aztec:archiver","timestamp":"2023-08-28T18:49:52.061Z"} {"level":"debug","message":"Adding pending l1 to l2 messages to store","namespace":"aztec:archiver","timestamp":"2023-08-28T18:49:52.081Z"} ``` Fixes #1605
- Loading branch information
1 parent
7279730
commit 0317e93
Showing
8 changed files
with
308 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { onLog } from '@aztec/foundation/log'; | ||
|
||
import * as path from 'path'; | ||
import * as process from 'process'; | ||
import * as util from 'util'; | ||
import * as winston from 'winston'; | ||
import DailyRotateFile from 'winston-daily-rotate-file'; | ||
|
||
const { format } = winston; | ||
const CURRENT_LOG_FILE_NAME = 'aztec-sandbox.debug.log'; | ||
const LOG_DIR = 'log'; | ||
|
||
/** Creates a winston logger that logs everyting to a local rotating file */ | ||
function createWinstonLogger() { | ||
// See https://www.npmjs.com/package/winston-daily-rotate-file#user-content-options | ||
const transport: DailyRotateFile = new DailyRotateFile({ | ||
filename: 'aztec-sandbox-%DATE%.debug.log', | ||
dirname: LOG_DIR, | ||
datePattern: 'YYYY-MM-DD', | ||
zippedArchive: true, | ||
maxSize: '30m', | ||
maxFiles: '5', | ||
createSymlink: true, | ||
symlinkName: CURRENT_LOG_FILE_NAME, | ||
}); | ||
|
||
return winston.createLogger({ | ||
level: 'debug', | ||
transports: [transport], | ||
format: format.combine(format.timestamp(), format.json()), | ||
}); | ||
} | ||
|
||
/** | ||
* Hooks to all log statements and outputs them to a local rotating file. | ||
* @returns Output log name. | ||
*/ | ||
export function setupFileDebugLog() { | ||
const logger = createWinstonLogger(); | ||
onLog((level, namespace, args) => { | ||
logger.log({ level, namespace, message: util.format(...args) }); | ||
}); | ||
const workdir = process.env.HOST_WORKDIR ?? process.cwd(); | ||
return path.join(workdir, LOG_DIR, CURRENT_LOG_FILE_NAME); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.