Alerty Blog

How To Store Logs On Vercel? A Complete Guide To Vercel Logging

Written by Jack Dwyer | Jul 6, 2024 12:09:29 AM

Vercel Logging is a vital aspect of managing serverless applications on Vercel. Imagine this: you encounter an issue with your application and need to access and analyze logs to pinpoint the problem swiftly. What if you could view and store these logs on Vercel, streamlining this process? This blog post will show you how to handle Vercel logging efficiently, gain insights, and enhance your application's performance.

Are you looking to streamline your Vercel logging process and enhance your application's performance? Alerty's NextJS logging tool can help you achieve your objectives, such as learning how to view and store logs on Vercel.

Table of Contents

Logging Basics

Logs are records of events on your computer, either by a person or a running process. It helps you track what happened and troubleshoot problems. Vercel is a cloud-based platform that simplifies developing and deploying front-end web applications. With Vercel, you can create high-performance applications without complex server management or infrastructure configuration, offering a seamless development experience.

One of the standout features of Vercel is its automatic scaling of web applications based on traffic, ensuring that your websites and applications remain speedy even during times of high traffic. As your application scales, you'll encounter more log data, but Vercel offers a range of monitoring and log analytics tools to help you quickly identify and resolve issues.

Related Reading

Types Of Logs In Vercel

Vercel Logging: Build Logs

Build logs in Vercel are automatically generated during the application's build time. These logs detail the actions taken during the build process, such as:

  • Cloning the repository
  • Installing dependencies
  • Populating the build cache

Vercel Logging: Runtime Logs

Runtime logs in Vercel include all logs generated by serverless and edge function invocations, showcasing each action taken in a separate log entry. These logs are real-time and 4 KB per line, making it easy to review the output from your functions. 

Vercel Logging: Activity Logs

Activity logs in Vercel track the actions and activities of your team members, detailing who performed an action and when it occurred. These logs show information like:

  • User
  • Event type
  • Account role
  • Timestamp

Prerequisites For Vercel Logging

Vercel Account

To access the Vercel dashboard, you'll need to set up a Vercel account. This account will be your gateway to managing all aspects of Vercel, including logging.

Node.js and NPM

Before diving into Vercel logging, ensure you have Node.js and npm installed on your local machine. These tools will streamline your setup process and make starting easier.

Vercel CLI

While not mandatory, having the Vercel CLI tool can be incredibly useful for managing logs from the command line. If you prefer a more hands-on approach to logging management, the Vercel CLI is worth considering.

Logging Integration

To centralize and manage your Vercel logs effectively, you'll need to set up a logging integration. Popular options include:

  • Alerty
  • LogDNA
  • Datadog
  • Logflare

Vercel also offers first-party integrations with some of these services for added convenience.

How To View Vercel Logs

Vercel offers two convenient methods for checking log records: the Vercel CLI or the web dashboard interface.

1. Using Vercel CLI

Vercel provides a command-line tool to retrieve logs and view them locally. To use this tool, you must first install Vercel by executing the following command:

bash
npm i -g vercel

Once the installation process is complete, you can check the version of the installed Vercel CLI by running the following command:

bash
vercel --version

Next, run the following command to connect to a Vercel project:

bash
vercel


If this is your first time using the Vercel CLI, you will be prompted to log in to your account. Once you've logged in, you'll be asked a series of questions. Follow the instructions and be sure to link to an existing project (i.e., the Vercel project you just created).

To retrieve log records for a specific deployment, use the following command:

bash
vercel logs <deployment_url>

You will find the deployment URL on the Project page.

This command will only pull the build logs for the specified deployment. If you wish to view the corresponding runtime logs, add a --follow or -f flag so that Vercel watches for additional log output.

bash
vercel logs <deployment_url> -f

2. Using the Vercel Dashboard

When you deploy your website to Vercel, the platform generates build logs showing deployment progress. The build logs contain information about:

  • The version of the build tools
  • Warnings or errors encountered during the build process
  • Details about the files and dependencies that were installed, compiled, or built during the deployment

Accessing and Understanding Build & Runtime Logs

Build logs are particularly useful for debugging issues that may arise during deployment. If a deployment fails, these can help you identify the root cause of the issue.

  • To access build logs, click the build logs button from the production deployment tile on the projects overview page. The build logs show the timestamp and the log message. You can also use the filter to show only the error or warning messages, which will be displayed in different colors.
  • To view Runtime logs, you should click the logs tab. You should observe several log records on the resulting page, and you can click any of them to view more details.

It's important to note that runtime logs in Vercel are only stored for a maximum of 1 hour. If you need to store logs long-term, you must rely on a third-party log management platform, which we will discuss in the next section.

You can find the activity logs by navigating to your team's homepage and selecting the activity tab.

Related Reading

Enable Web Vitals Metrics

Web vitals metrics, a feature offered by Vercel, allows you to monitor your application's performance by collecting real user metrics to estimate a score. This feature helps you understand how users interact with your application and provides valuable insights to improve overall performance. You can easily enable Web Vitals Metrics by following these steps:

Visit the Vercel dashboard

To enable this feature, navigate to the analytics section on your Vercel dashboard. From here, you can access the performance analytics tab.

Enable Performance Analytics

Once you are in the performance analytics tab, toggle the feature to enable performance analytics on your application. Vercel will prompt you to redeploy your project after enabling this feature.

Redeploy your project

After activating performance analytics, Vercel will ask you to redeploy your project. To initiate the redeployment process, simply follow the instructions provided.

Collect performance data

Once the redeployment process is complete, Vercel will collect performance data every time a user visits your application. This data will help you evaluate your application's performance using real user metrics.

Enabling web vitals metrics on Vercel can help you better understand how users interact with your application and identify areas for improvement. Make sure to regularly review the performance data collected by Vercel to optimize your application and enhance the overall user experience.

Get started with Web Vitals Metrics on Vercel today and take your application's performance to the next level!

How To Aggregate And Centralize Vercel Logs

Vercel, a popular platform for deploying and hosting web applications, provides developers with valuable logging capabilities. While building and activity logs are stored indefinitely, runtime logs are only kept for one hour. To maintain these runtime logs for an extended period, users need to centralize and aggregate them using third-party log management platforms such as Alerty or solutions available on the Vercel marketplace.

Integrating a Log Tool with Vercel

Users can follow a straightforward integration process to connect Vercel projects with a logging tool available on the Vercel marketplace. By navigating to the log tool's integration page within the Vercel dashboard, developers can add the integration by selecting the desired Vercel project. This seamless connection allows logs to be efficiently sent to the chosen platform for further analysis and long-term storage.

Setting Up Configurable Log Drains

Vercel’s configurable log drains present another effective method for centralizing logs. This feature enables users to direct logs to any endpoint URL via the HTTP protocol, offering greater flexibility compared to the limited integrations in the Vercel marketplace. With configurable log drains, users can:

  • Select specific log sources
  • Log formats (JSON or NDJSON)
  • Endpoint URLs
  • Incorporate custom headers

This level of customization allows developers to tailor their logging setup to meet the specific requirements of their applications.

Developers can ensure that runtime logs generated by applications deployed on Vercel are efficiently aggregated and centralized for long-term storage and analysis. Whether integrating with logging tools from the Vercel marketplace or utilizing configurable log drains to send logs to custom endpoints, Vercel offers users flexibility in managing their application logs effectively.

Best Practices For Vercel Logging

Use Log Drains

Vercel's log drains feature makes it easy to pipe your deployment logs to a dedicated logging service like Alerty, Datadog, or Logflare. This allows you to centralize your logs, create alerts, and analyze them more effectively.

Leverage Structured Logging

Use a structured logging library like Pino to ensure your logs are machine-readable, making them easier to search and analyze. Vercel's documentation mentions that console logs are wrapped in metadata, so structured logging can help you extract the relevant information.

Monitor Serverless Function Logs

Pay close attention to the logs for your Serverless Functions. It can provide valuable insights into performance, errors, and other issues. Vercel's functions tab makes it easy to inspect these logs quickly.

Analyze Build Logs

Vercel's improved build logs can help you understand how your source code is being built and deployed. Review these logs regularly to identify any potential issues or optimizations.

Integrate with Third-Party Tools

Take advantage of Vercel's integrations with logging providers like Alerty, LogDNA and Datadog. These tools offer advanced features like alerting, metrics, and log analysis that can complement Vercel's built-in logging capabilities.

Leverage Vercel's Observability Features

Vercel's Observability suite includes features like Monitoring, Logs, and Speed Insights that can help you gain deeper insights into your application's performance and behavior.

Related Reading

 

Catch Issues Before They Affect Your Users with Alerty's NextJS Logging Tool

Alerty is a cloud monitoring service tailored to developers and early-stage startups. It offers a comprehensive suite of features to ensure application smooth performance. Supporting popular technologies like NextJS, React, Vue, and Node.js, Alerty assists developers in identifying and fixing issues promptly. 

  • This tool extends its monitoring capabilities to databases such as Supabase, PostgreSQL, and RDS
  • Allows tracking of essential metrics like CPU usage and memory consumption
  • Provides quick incident management and Real User Monitoring (RUM) to optimize user experience
  • Ensure seamless application performance

Simplified Setup & Cost-Effective Monitoring

With Alerty's universal service monitoring feature, dependencies such as Stripe API, OpenAI, and Vercel can be efficiently monitored, providing a holistic view of the application ecosystem. 

  • Leveraging AI technology, Alerty simplifies the setup process, making it a cost-effective solution compared to other monitoring services. 
  • Its user-friendly design allows for a quick setup, enabling developers and small teams to integrate monitoring into their workflow easily. 
  • Alerty seamlessly integrates with tools like Sentry, streamlining the monitoring and issue resolution process for efficient and affordable application performance monitoring.

Are you ready to catch issues before they affect your users and ensure optimal performance for your NextJS application with Alerty's advanced monitoring capabilities?