Skip to content

Commit fe6c56a

Browse files
authored
Merge pull request #561 from FlowiseAI/bugfix/LogPath
Feature/JSONL Logs Cleanup
2 parents c4c1f0b + 745a422 commit fe6c56a

File tree

8 files changed

+75
-48
lines changed

8 files changed

+75
-48
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,16 @@ FLOWISE_PASSWORD=1234
128128
129129
## 🌱 Env Variables
130130
131-
Flowise support different environment variables to configure your instance. You can specify the following variables in the `.env` file inside `packages/server` folder.
131+
Flowise support different environment variables to configure your instance. You can specify the following variables in the `.env` file inside `packages/server` folder. Read [more](https://docs.flowiseai.com/environment-variables)
132132
133133
| Variable | Description | Type | Default |
134134
| ---------------- | ---------------------------------------------------------------- | ------------------------------------------------ | ----------------------------------- |
135135
| PORT | The HTTP port Flowise runs on | Number | 3000 |
136136
| FLOWISE_USERNAME | Username to login | String |
137137
| FLOWISE_PASSWORD | Password to login | String |
138-
| DEBUG | Print logs from components | Boolean |
138+
| DEBUG | Print logs onto terminal/console | Boolean |
139139
| LOG_PATH | Location where log files are stored | String | `your-path/Flowise/packages/server` |
140-
| LOG_LEVEL | Different levels of logs | Enum String: `error`, `info`, `verbose`, `debug` | `info` |
140+
| LOG_LEVEL | Different log levels for loggers to be saved | Enum String: `error`, `info`, `verbose`, `debug` | `info` |
141141
| DATABASE_PATH | Location where database is saved | String | `your-home-dir/.flowise` |
142142
| APIKEY_PATH | Location where api keys are saved | String | `your-path/Flowise/packages/server` |
143143
| EXECUTION_MODE | Whether predictions run in their own process or the main process | Enum String: `child`, `main` | `main` |

docker/.env.example

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
PORT=3000
2+
DATABASE_PATH=/root/.flowise
3+
APIKEY_PATH=/root/.flowise
4+
LOG_PATH=/root/.flowise/logs
25
# FLOWISE_USERNAME=user
36
# FLOWISE_PASSWORD=1234
47
# DEBUG=true
5-
# DATABASE_PATH=/your_database_path/.flowise
6-
# APIKEY_PATH=/your_api_key_path/.flowise
7-
# LOG_PATH=/your_log_path/logs
8+
# LOG_LEVEL=debug (error | warn | info | verbose | debug)
89
# EXECUTION_MODE=child or main

docker/README.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Starts Flowise from [DockerHub Image](https://hub.docker.com/repository/docker/f
99
3. Open [http://localhost:3000](http://localhost:3000)
1010
4. You can bring the containers down by `docker-compose stop`
1111

12-
## With Authrorization
12+
## 🔒 Authrorization
1313

1414
1. Create `.env` file and specify the `PORT`, `FLOWISE_USERNAME`, and `FLOWISE_PASSWORD` (refer to `.env.example`)
1515
2. Pass `FLOWISE_USERNAME` and `FLOWISE_PASSWORD` to the `docker-compose.yml` file:
@@ -22,3 +22,25 @@ Starts Flowise from [DockerHub Image](https://hub.docker.com/repository/docker/f
2222
3. `docker-compose up -d`
2323
4. Open [http://localhost:3000](http://localhost:3000)
2424
5. You can bring the containers down by `docker-compose stop`
25+
26+
## 🌱 Env Variables
27+
28+
If you like to persist your data (flows, logs, apikeys), set these variables in the `.env` file inside `docker` folder:
29+
30+
- DATABASE_PATH=/root/.flowise
31+
- APIKEY_PATH=/root/.flowise
32+
- LOG_PATH=/root/.flowise/logs
33+
34+
Flowise also support different environment variables to configure your instance. Read [more](https://docs.flowiseai.com/environment-variables)
35+
36+
| Variable | Description | Type | Default |
37+
| ---------------- | ---------------------------------------------------------------- | ------------------------------------------------ | ----------------------------------- |
38+
| PORT | The HTTP port Flowise runs on | Number | 3000 |
39+
| FLOWISE_USERNAME | Username to login | String |
40+
| FLOWISE_PASSWORD | Password to login | String |
41+
| DEBUG | Print logs onto terminal/console | Boolean |
42+
| LOG_PATH | Location where log files are stored | String | `your-path/Flowise/packages/server` |
43+
| LOG_LEVEL | Different log levels for loggers to be saved | Enum String: `error`, `info`, `verbose`, `debug` | `info` |
44+
| DATABASE_PATH | Location where database is saved | String | `your-home-dir/.flowise` |
45+
| APIKEY_PATH | Location where api keys are saved | String | `your-path/Flowise/packages/server` |
46+
| EXECUTION_MODE | Whether predictions run in their own process or the main process | Enum String: `child`, `main` | `main` |

docker/docker-compose.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ services:
88
- PORT=${PORT}
99
- FLOWISE_USERNAME=${FLOWISE_USERNAME}
1010
- FLOWISE_PASSWORD=${FLOWISE_PASSWORD}
11+
- DEBUG=${DEBUG}
1112
- DATABASE_PATH=${DATABASE_PATH}
1213
- APIKEY_PATH=${APIKEY_PATH}
1314
- LOG_PATH=${LOG_PATH}
15+
- LOG_LEVEL=${LOG_LEVEL}
1416
- EXECUTION_MODE=${EXECUTION_MODE}
15-
- DEBUG=${DEBUG}
1617
ports:
1718
- '${PORT}:${PORT}'
1819
volumes:

packages/server/.env.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ PORT=3000
44
# DEBUG=true
55
# DATABASE_PATH=/your_database_path/.flowise
66
# APIKEY_PATH=/your_api_key_path/.flowise
7-
# LOG_PATH=/your_log_path/logs
7+
# LOG_PATH=/your_log_path/.flowise/logs
88
# LOG_LEVEL=debug (error | warn | info | verbose | debug)
99
# EXECUTION_MODE=main (child | main)

packages/server/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ FLOWISE_PASSWORD=1234
3131
3232
## 🌱 Env Variables
3333
34-
Flowise support different environment variables to configure your instance. You can specify the following variables in the `.env` file inside `packages/server` folder.
34+
Flowise support different environment variables to configure your instance. You can specify the following variables in the `.env` file inside `packages/server` folder. Read [more](https://docs.flowiseai.com/environment-variables)
3535
3636
| Variable | Description | Type | Default |
3737
| ---------------- | ---------------------------------------------------------------- | ------------------------------------------------ | ----------------------------------- |
3838
| PORT | The HTTP port Flowise runs on | Number | 3000 |
3939
| FLOWISE_USERNAME | Username to login | String |
4040
| FLOWISE_PASSWORD | Password to login | String |
41-
| DEBUG | Print logs from components | Boolean |
41+
| DEBUG | Print logs onto terminal/console | Boolean |
4242
| LOG_PATH | Location where log files are stored | String | `your-path/Flowise/packages/server` |
43-
| LOG_LEVEL | Different levels of logs | Enum String: `error`, `info`, `verbose`, `debug` | `info` |
43+
| LOG_LEVEL | Different log levels for loggers to be saved | Enum String: `error`, `info`, `verbose`, `debug` | `info` |
4444
| DATABASE_PATH | Location where database is saved | String | `your-home-dir/.flowise` |
4545
| APIKEY_PATH | Location where api keys are saved | String | `your-path/Flowise/packages/server` |
4646
| EXECUTION_MODE | Whether predictions run in their own process or the main process | Enum String: `child`, `main` | `main` |

packages/server/src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ export class App {
6060

6161
constructor() {
6262
this.app = express()
63-
64-
// Add the expressRequestLogger middleware to log all requests
65-
this.app.use(expressRequestLogger)
6663
}
6764

6865
async initDatabase() {
@@ -93,6 +90,9 @@ export class App {
9390
// Allow access from *
9491
this.app.use(cors())
9592

93+
// Add the expressRequestLogger middleware to log all requests
94+
this.app.use(expressRequestLogger)
95+
9696
if (process.env.FLOWISE_USERNAME && process.env.FLOWISE_PASSWORD) {
9797
const username = process.env.FLOWISE_USERNAME
9898
const password = process.env.FLOWISE_PASSWORD

packages/server/src/utils/logger.ts

+36-33
Original file line numberDiff line numberDiff line change
@@ -57,43 +57,46 @@ const logger = createLogger({
5757
* this.app.use(expressRequestLogger)
5858
*/
5959
export function expressRequestLogger(req: Request, res: Response, next: NextFunction): void {
60-
const fileLogger = createLogger({
61-
format: combine(timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), format.json(), errors({ stack: true })),
62-
defaultMeta: {
63-
package: 'server',
64-
request: {
65-
method: req.method,
66-
url: req.url,
67-
body: req.body,
68-
query: req.query,
69-
params: req.params,
70-
headers: req.headers
60+
const unwantedLogURLs = ['/api/v1/node-icon/']
61+
if (req.url.includes('/api/v1/') && !unwantedLogURLs.some((url) => req.url.includes(url))) {
62+
const fileLogger = createLogger({
63+
format: combine(timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), format.json(), errors({ stack: true })),
64+
defaultMeta: {
65+
package: 'server',
66+
request: {
67+
method: req.method,
68+
url: req.url,
69+
body: req.body,
70+
query: req.query,
71+
params: req.params,
72+
headers: req.headers
73+
}
74+
},
75+
transports: [
76+
new transports.File({
77+
filename: path.join(logDir, config.logging.express.filename ?? 'server-requests.log.jsonl'),
78+
level: config.logging.express.level ?? 'debug'
79+
})
80+
]
81+
})
82+
83+
const getRequestEmoji = (method: string) => {
84+
const requetsEmojis: Record<string, string> = {
85+
GET: '⬇️',
86+
POST: '⬆️',
87+
PUT: '🖊',
88+
DELETE: '❌'
7189
}
72-
},
73-
transports: [
74-
new transports.File({
75-
filename: path.join(logDir, config.logging.express.filename ?? 'server-requests.log.jsonl'),
76-
level: config.logging.express.level ?? 'debug'
77-
})
78-
]
79-
})
8090

81-
const getRequestEmoji = (method: string) => {
82-
const requetsEmojis: Record<string, string> = {
83-
GET: '⬇️',
84-
POST: '⬆️',
85-
PUT: '🖊',
86-
DELETE: '❌'
91+
return requetsEmojis[method] || '?'
8792
}
8893

89-
return requetsEmojis[method] || '?'
90-
}
91-
92-
if (req.method !== 'GET') {
93-
fileLogger.info(`${getRequestEmoji(req.method)} ${req.method} ${req.url}`)
94-
logger.info(`${getRequestEmoji(req.method)} ${req.method} ${req.url}`)
95-
} else {
96-
fileLogger.http(`${getRequestEmoji(req.method)} ${req.method} ${req.url}`)
94+
if (req.method !== 'GET') {
95+
fileLogger.info(`${getRequestEmoji(req.method)} ${req.method} ${req.url}`)
96+
logger.info(`${getRequestEmoji(req.method)} ${req.method} ${req.url}`)
97+
} else {
98+
fileLogger.http(`${getRequestEmoji(req.method)} ${req.method} ${req.url}`)
99+
}
97100
}
98101

99102
next()

0 commit comments

Comments
 (0)