Winston not creating any output when running in a Docker container
See original GitHub issuePlease tell us about your environment:
winston
version?-
winston@2
-
winston@3
-
node -v
outputs: v14.5.0- Operating System? (Windows, macOS, or Linux) macOS + Alpine Linux
- Language? (all | TypeScript X.X | ES6/7 | ES5 | Dart) ES6/7
What is the problem?
Winston does not print any log output when running inside a Docker container, either to the Console or to a file (it does create the file, just doesn’t put any output there.)
Here is my Winston config.
import winston from 'winston'
import config from '../config'
const transports = []
transports.push(
new winston.transports.Console(),
new winston.transports.File({
filename: 'test.log'
})
)
const LoggerInstance = winston.createLogger({
level: config.logs.level,
levels: winston.config.npm.levels,
format: winston.format.combine(
winston.format.timestamp({
format: 'YYYY-MM-DD HH:mm:ss'
}),
winston.format.errors({ stack: true }),
winston.format.splat(),
winston.format.json()
),
transports
})
export default LoggerInstance
This is my Dockerfile
FROM node:current-alpine
WORKDIR /usr/src
RUN apk --no-cache add --virtual builds-deps build-base python
COPY package.json package.json
COPY package-lock.json package-lock.json
RUN npm install
COPY . .
ENV NODE_ENV production
CMD ["npm", "run", "start"]
Here is where I’m logging
import expressLoader from './express'
import databaseLoader from './database'
import dependencyLoader from './dependencies'
import modelLoader from './models'
import Logger from './logger'
export default async ({ expressApp }) => {
const conn = databaseLoader
Logger.info('✅️ Database loaded')
try {
await conn.authenticate()
Logger.info('🔌 ️Database connected')
} catch (e) {
Logger.error('🔥 Error connecting to database: %o', e)
process.exit(1)
}
Logger.info('➕ Injecting dependencies')
dependencyLoader()
Logger.info('✅️ Dependencies injected')
Logger.info('➕ Injecting models')
modelLoader()
Logger.info('✅️ Models injected')
expressLoader({ app: expressApp })
Logger.info('✅️ Express loaded')
}
I get the following output when running locally
And when I run from my Docker container, I get the following
If I change all of the Logger.info
to console.log
, I get output.
The log level (and all other config) is the same, and is currently set to silly
.
Any ideas?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:14 (2 by maintainers)
Top Results From Across the Web
Log files not created in container or host with Winston logger
This behavior is actually discussed at Winston not creating any output when running in a Docker container. The work around mentioned ...
Read more >node.js - Where is the winston log files when using docker
It's inside the container, in a directory space that's not usually directly accessible from the host. You've also configured Winston to use ...
Read more >A Complete Guide to Winston Logging in Node.js - Better Stack
Learn how to start logging with Winston in Node.js and go from basics to best practices in no time.
Read more >How To Use Winston to Log Node.js Applications on Ubuntu ...
By default, applications created with express-generator run on port 3000 , so you need to ensure that the firewall does not block the...
Read more >Node.js Logging with Winston - Reflectoring
Hence the logger will only output debug and higher levels ( info , warn and error ). Any level lower than debug would...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Can you please help me how to write logs into winston file transports using docker container.
using docker able to create logs file and console logs printing in server using docker image.
But the logs are not saved into log files.
So can you please suggest how to write logs into winston file transports using docker image.
still winston file transport not able to save logs into files. In local environment without docker image it’s working as expected.
Please suggest me how to write & save logs into files using docker image.
Might be related to #2175 and/or #981/#982