LogoLogo
CS CONSOLECOMMUNITYDOCS
  • What is code.store?
  • Our vision
  • How it works?
  • Getting started
    • Quick Start
      • Core concepts
      • Quick Start with CLI
      • Quick Start with Web Interface
    • FUNDAMENTALS
      • Services
        • GraphQL
        • REST
        • Configuration
        • Environment Variables
      • Environments
      • Projects
      • Versioning
      • Access and Authorization
      • Secret management
      • Data management
        • Import and Export
      • Generation
        • Models
        • Handlers
        • Resolvers
        • REST
        • Middlewares
      • Logging
      • Microservices
        • Communication
    • RECIPES
      • TypeScript
        • Custom .tslint
      • Basic authentication
      • Setup a local database with your service
      • GraphQL
    • Tutorials
      • Auth0 authentication
      • Metabase integration
      • Database manipulations
        • External database: MongoDB
        • External database: DynamoDB
      • Wrapping an NPM package with GraphQL: a chess server
    • FAQ
  • Command Line Interface
    • Getting started
    • Commands
Powered by GitBook
On this page
  • Overview
  • Service logs
  • Project and environment logs
  • Project logs
  • Environment logs
  • Logger
  • Overview
  • Usage

Was this helpful?

Export as PDF
  1. Getting started
  2. FUNDAMENTALS

Logging

PreviousMiddlewaresNextMicroservices

Last updated 4 years ago

Was this helpful?

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 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 .

> cs logs -s demo_app

Displaying logs for environment private, service demo_app
2020-11-17T14:02:49.243Z [GqlLoader] Loaded queries: helloWorld
2020-11-17T14:02:49.338Z [RestLoader] Loaded REST handlers:
2020-11-17T14:02:49.341Z [RestLoader] -> /name - GET
2020-11-17T14:02:49.341Z [Bootstrap] -> [GET] http://localhost:3002/rest/name
2020-11-17T14:02:49.341Z [Bootstrap] REST endpoints are available on:
2020-11-17T14:02:49.341Z [Bootstrap] GraphQL is available on: http://localhost:3002/graphql

Logs for private 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

> cs logs -s demo_app -n 1000

Project and environment logs

Project logs

> cs logs -p my_project

Environment logs

> cs logs -p my_project -e development
> cs logs -s demo_app -e demo

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.

import { logger } 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 application

  • error - error logs of considerable importance that will prevent normal program execution, but might still allow the application to continue running

  • warn - potentially harmful situations of interest that indicate potential problems -

  • debug - information that is diagnostically helpful to people more than to system administrators

  • verbose - verbose information about any thing which may be useful

Usage

By default, any log method consume three params: message, context and data.

public log(message: any, context = '', data?: any): void
public warn(message: any, context = '', data?: any): void
public debug(message: any, context = '', data?: any): void
public verbose(message: any, context = '', data?: any): void

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:

import { logger } from 'codestore-utils';


logger.log('User received a new achievement', `${this.constructor.name}`, { achievement: { name: 'STAR', level: 3 }});

An exception to the rule is an error method that has a slightly different signature:

public error(error: string | Error, trace = '', context = '', data?: any): void

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:

import { logger } from 'codestore-utils';


try {
    throw new Error('This is an error...');
} catch(e) {
    logger.error(e);
}

To access full logs you should specify project ID using -p flag.

To list your available project execute cs project:service:list command. Learn more on the section.

After command execution logs from all deployed services on all (development, staging, production) environments will be .

To filter environments just specify environment name using -e flag. Below is an example of displaying logs of all deployed services on development of my_project .

Also, you can display service logs from demo and private . To display these logs specify environment name using -e and service id using -s flag.

elasticsearch
service
environment
project
Projects
displayed
environment
project
environment