Logging
Overview
From time to time becomes necessary to monitor the status and progress of a deployed application, look at the current application activity, or debug an error.
code.store platform provides an interface for working with report logs. By default logs contain information about the exceptions that the deployed application produces, service bootstrap and other things that the developer considered necessary to add as logs.
On backstage, as a log storage code.store platform used elasticsearch database, which allows to organize a quick search through the logs.
Note: logs are stored on the platform for a month.
Service logs
To reach service logs navigate to your service directory and execute cs service:logs command, or specify service ID using -s
flag. Below is an example of listing demo_app service logs, where demo_app is an id of service.
Logs for private environment will be displayed, if environment is not specified manually.
By default, command display only 20 of the most recent log lines, to increase output lines count use -n
flag. Below is an example of listing demo_app service logs, where output lines count are set to 1000
Project and environment logs
Project logs
To access full project logs you should specify project ID using -p
flag.
To list your available project execute cs project:service:list command. Learn more on the Projects section.
After command execution logs from all deployed services on all (development, staging, production) environments will be displayed.
Environment logs
To filter environments just specify environment name using -e
flag. Below is an example of displaying logs of all deployed services on development environment of my_project project.
Also, you can display service logs from demo and private environment. To display these logs specify environment name using -e
and service id using -s
flag.
Logger
Overview
code.store platform read full stdout log and store, you may use any convenient logger. But, to make developers life easier - code.store platform provides a built-in logger, which can be imported from codestore-utils
.
Built-in logger provides default method for logging and map each log for future text search. Logger provides default logging methods, such as:
log
- informational logs that might make sense to system administrators, and highlight the progress of the applicationerror
- error logs of considerable importance that will prevent normal program execution, but might still allow the application to continue runningwarn
- potentially harmful situations of interest that indicate potential problems -debug
- information that is diagnostically helpful to people more than to system administratorsverbose
- verbose information about any thing which may be useful
Usage
By default, any log method consume three params: message
, context
and data
.
message
- is a message, which will be logged
context
(empty by default) - is a prefix of message, which usually indicated where method was executed (method, or constructor name for example...). This param are .
data
(optional) - is an optional object, which will be stringify and append to the message
Example of usage:
An exception to the rule is an error
method that has a slightly different signature:
This method usually used to log a handled exception. You can just pass an error object as first argument and logger will format a message to valid format. For example:
Last updated