You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
full logging which outputs to stdout/stderr as we do now (and better!)
ability to provide an adapter in future, to customise the destination/output of the logging system
error levels
application levels
delete logic in errors/index.js
reasons why we have to change things
we need a consistent way to a log into a file/stdout --> right now we use morgan to log requests and a custom logging (chalk and console.log) for errors
we want to log more then just a single line GET URL StatusCode for requests (especially in development mode)
what we want to achieve is printing all logs (request/response/errors) in the same format (which i think can be JSON)
we need to tidy up (or remove) /errors/index.js, because it's doing more then it needs to do, is way to complicated in my opinion (we export ~15functions) and we want to differ the errors from a logging unit
we want to create a real logging adapter (which can be replaced)
this adapter can/should be used in each Ghost microservice
we want to handle and tidy up context/help for errors
we don't have proper levels (application levels, error levels, error codes)
log into file has the background: if we log stdout into the process, the process will grow over time. if we log into a file, we can rotate on that log file an delete after x days (this is helpful for each blog running in production)
As already discussed, debug is a nice npm tool to get debug logs per file with auto-includes milliseconds between each debug log.
But our big goal is creating a logging unit, which can do more then just printing debug logs.
I've used winston in the past and we've switched to bunyan, because the bunyan API is easier to use, easier to read and it has the advantage of nice JSON prints. That's why i would go with bunyan.
create a default logging adapter
server/logging/default.js
Developers should easily add custom loggers, if they prefer a different logger.
It should provide functions like info, error, warn, and debug.
info
with info you can just log a single line like "ghost server is starting"
with info you can also log complex json objects like request/response
error
accepts an error object and optional request/response object
warn
accepts only a string
debug
accepts a single JSON object
accepts a single string
var logging = require('/logging');
logging.error({ err: err, req: req, res: res });
logging.info('server starts now...');
logging.info({ req: req, res: res });
output
Right now our server print looks like (only stdout):
GET / 200 140.121 ms - -
GET /assets/js/jquery.fitvids.js?v=4d853bd599 200 17.077 ms - -
GET /assets/js/index.js?v=4d853bd599 200 16.385 ms - -
GET /assets/css/screen.css?v=4d853bd599 200 19.621 ms - -
This print is managed by morgan, which is configured in middlewares/index.js. We will delete this.
Instead we will auto log requests/responses/errors.
Logging
goals
errors/index.jsreasons why we have to change things
morganto log requests and a custom logging (chalk and console.log) for errorsGET URL StatusCodefor requests (especially in development mode)JSON)/errors/index.js, because it's doing more then it needs to do, is way to complicated in my opinion (we export ~15functions) and we want to differ the errors from a logging unitloggerfrom migrationsbunyan vs. winston vs. debug
As already discussed,
debugis a nice npm tool to get debug logs per file with auto-includes milliseconds between each debug log.But our big goal is creating a logging unit, which can do more then just printing debug logs.
I've used
winstonin the past and we've switched tobunyan, because thebunyanAPI is easier to use, easier to read and it has the advantage of nice JSON prints. That's why i would go withbunyan.create a default logging adapter
server/logging/default.jsDevelopers should easily add custom loggers, if they prefer a different logger.
It should provide functions like
info,error,warn, anddebug.info
error
warn
debug
output
Right now our server print looks like (only stdout):
This print is managed by
morgan, which is configured inmiddlewares/index.js. We will delete this.Instead we will auto log requests/responses/errors.
Which can look like (transport: stdout)




Which can look like (transport: file)

We could extend our upcoming Ghost CLI to offer:
ghost-cli log(which will prettify the.logfile)log into file
We should be able to configure the transport (file, stdout)
We can start defining the transport per env.
production
file only
staging
file only
development
stdout only
application levels
Every env is by default in level info.
You can either force starting it different mode (debug) by changing the config or using
NODE_LEVEL.error levels
Each error will be default in level "normal".
We can define an error as critical, which get's treated differently in Ghost(Pro).
time diffs
We can add time diffs between logs, like the npm module
debugis offering. Not high prio.ensure we don't log credentials
Filter attributes.
bring help/context into errors
Right now we pass context and help as different parameters.
We want to achieve having context and help as part of an error.
show debug logs in testing mode
NODE_LEVEL=debug grunt testorgrunt test -d (--debug)Should show print outs like errors.
TODO
debuginstead oflogging.debug- one true way for now