-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #218 from valory-xyz/feat/better-logging
Export Agent Logs & Better logging
- Loading branch information
Showing
9 changed files
with
376 additions
and
1,211 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,3 +44,6 @@ leak_report | |
*.dist | ||
*.build | ||
/electron/bins/ | ||
|
||
# logs | ||
*.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const os = require('os'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
const dotOperateDirectory = | ||
process.env.NODE_ENV === 'production' | ||
? path.join(os.homedir(), '.operate') | ||
: '.operate'; | ||
|
||
// Create operate directory if it doesn't exist | ||
if (!fs.existsSync(dotOperateDirectory)) { | ||
fs.mkdirSync(dotOperateDirectory); | ||
} | ||
|
||
const paths = { | ||
dotOperateDirectory, | ||
servicesDir: path.join(dotOperateDirectory, 'services'), | ||
venvDir: path.join(dotOperateDirectory, 'venv'), | ||
tempDir: path.join(dotOperateDirectory, 'temp'), | ||
versionFile: path.join(dotOperateDirectory, 'version.txt'), | ||
cliLogFile: path.join(dotOperateDirectory, 'cli.log'), | ||
electronLogFile: path.join(dotOperateDirectory, 'electron.log'), | ||
nextLogFile: path.join(dotOperateDirectory, 'next.log'), | ||
osPearlTempDir: path.join(os.tmpdir(), 'pearl'), | ||
}; | ||
|
||
module.exports = { paths }; |
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,73 @@ | ||
const winston = require('winston'); | ||
const { format } = require('logform'); | ||
const { paths } = require('./constants/paths'); | ||
|
||
const { combine, timestamp, printf } = format; | ||
|
||
const logFormat = printf(({ level, message, timestamp }) => { | ||
return `${timestamp} ${level}: ${message}`; | ||
}); | ||
|
||
const customLevels = { | ||
levels: { | ||
error: 0, | ||
warn: 1, | ||
info: 2, | ||
next: 3, | ||
cli: 4, | ||
electron: 5, | ||
}, | ||
colors: { | ||
error: 'red', | ||
warn: 'yellow', | ||
info: 'blue', | ||
cli: 'green bold underline', | ||
electron: 'magenta bold underline', | ||
next: 'cyan bold underline', | ||
}, | ||
}; | ||
|
||
// Custom filter for specific levels, otherwise higher levels will include lower levels | ||
const levelFilter = (level) => | ||
format((info, _opts) => { | ||
return info.level === level ? info : false; | ||
})(); | ||
|
||
const logger = winston.createLogger({ | ||
levels: customLevels.levels, | ||
transports: [ | ||
new winston.transports.Console({ | ||
level: 'electron', // Set to the highest level so it captures everything. | ||
format: combine(winston.format.colorize(), timestamp(), logFormat), | ||
}), | ||
new winston.transports.File({ | ||
filename: 'cli.log', | ||
dirname: paths.dotOperateDirectory, | ||
level: 'cli', | ||
format: combine(levelFilter('cli'), timestamp(), logFormat), | ||
maxFiles: 1, | ||
maxsize: 1024 * 1024 * 10, | ||
}), | ||
new winston.transports.File({ | ||
filename: 'electron.log', | ||
dirname: paths.dotOperateDirectory, | ||
level: 'electron', | ||
format: combine(levelFilter('electron'), timestamp(), logFormat), | ||
maxFiles: 1, | ||
maxsize: 1024 * 1024 * 10, | ||
}), | ||
new winston.transports.File({ | ||
filename: 'next.log', | ||
dirname: paths.dotOperateDirectory, | ||
level: 'next', | ||
format: combine(levelFilter('next'), timestamp(), logFormat), | ||
maxFiles: 1, | ||
maxsize: 1024 * 1024 * 10, | ||
}), | ||
], | ||
format: combine(timestamp(), logFormat), | ||
}); | ||
|
||
winston.addColors(customLevels.colors); | ||
|
||
module.exports = { logger }; |
Oops, something went wrong.