<h1> You probably want to use LogList and not the singular Log component.</h1><br><div class="lui-log" data-controller="log" data-log-expanded-copy-text-value="Expand" data-log-collapsed-copy-text-value="Collapse"> <div class="lui-log__main"> <div class="lui-log__main-header"> <span class="text-secondary-xs-normal text-secondary-xs-regular text-gray-700">02:00h</span> </div> <div class="lui-log__content" data-log-target="content"> <div class="lui-log__word">Translation </div> <div class="lui-log__word">missing: </div> <div class="lui-log__word">en.log_translators.services/shipping.create_dpd_pickup_point_guide.expired</div> </div> <div class="lui-log__buttons"></div> </div> <div class="lui-log__source"> <span id="lui-token_6503213766" class="lui-token lui-entity-token lui-entity-token-general " style="color: #212529; background-color: #F8F9FA;"> <span class="lui-token__text">System</span> <div class="lui-token__actions"> </div> </span> </div></div>Log
Description
Related components
| Used Components | Components where is Used |
|---|---|
| Label |
Usage rules
- ✅ Do
- ❌ Don't
<h1> You probably want to use LogList and not the singular Log component.</h1><br><%# log is a Hash, with the same structure as a Item's presenter logs %><%= render LooposUi::Log.from_any_source(log) %>No notes provided.
No params configured.
Description
The Log component is a versatile component for displaying individual log entries with rich content, expandable sections, and interactive elements.
It's designed to work within the LogList component but can also be used standalone.
The component supports various content types including text with HTML formatting, entity tokens, expandable content, and action buttons.
Arguments
| Property | Default | Required | Description |
|---|---|---|---|
error |
false |
Whether this log represents an error state | |
user |
nil |
The user who performed the action | |
date |
nil |
The timestamp of the log entry |
Slots
For content related:
content(default slot). Supports rich text with HTMLexpand- For expanded content. Will create a button to expand the section.button- For buttons and actions. Will create Buttons.button_manual- Avoid usage, but if necessary you can pass anything into this slot.source- Populates the right side of the Log. Has polymorphic options:entity_token_source- Renders an EntityToken.source- Alternative interface you can build an entity token and pass in as a parameter.
title_token(polymorphic slot) Appears to the left of the log title.- Can render:
- an
EntityToken - an entity
- manual content
Factory System
The Log component includes a factory system that allows automatic creation of Log components from various data sources. This system provides a consistent interface for converting different data types into Log components.
How It Works
The factory system automatically detects the appropriate factory for a given data source and uses it to create a Log component.
This is done through the from_any_source class method:
log = LooposUi::Log.from_any_source(my_data_source)# Note you can also use the desired factory directlylog = LooposUi::Log::Factories::CoreItemLogPresenterHash.create(my_data_source)# orlog = LooposUi::Log::Factories::CoreItemLogPresenterHash.try_create(my_data_source)# returns NilLog if the factory can't create the log in production# raises error in developmentImplemented Factories
1. CoreItemLogPresenterHash
Purpose: Converts hash data from core item log presenters into Log components.
Data Source: Hash with the following structure:
{ time: DateTime, author: String, app_instance: { name: String, kind: String }, message: String, error: Boolean}2. ScriptLog
Purpose: Converts LoopOs::ScriptLog objects into Log components.
Data Source: LoopOs::ScriptLog instances with properties like:
created_atuser_identificationlevelnamefilesinput_data
Automatic Features:
- Download Button: Automatically added when
filesare present - Retry Button: Automatically added when
input_datais present andscriptis a ScriptProxy with retry capability - Info Modal: Always included for detailed script information
- Retry Modal: Automatically created when retry button is present
Parameters:
script: ScriptProxy object that provides retry functionality (optional, for retry button)
Example:
script_proxy = LoopOs::Scripts::ScriptProxy.new(@loop_os_script, context: { retry_path_proc: ->(script_log) { rerun_script_script_path(@loop_os_script, script_log_id: script_log.id) }})log = LooposUi::Log::Factories::ScriptLog.new(script_log, script: script_proxy).createCreating Custom Factories
To create a custom factory, you need to:
Inherit from the base class:
class MyCustomFactory < LooposUi::Log::Factories::BaseImplement the can_create? class method:
def self.can_create?(source) # Return true if this factory can handle the given source source.is_a?(MyCustomModel)endImplement the create instance method:
def create LooposUi::Log.new( date: @source.created_at, user: @source.user_name, error: @source.error? ).with_content(@source.message)endAvailable Instance Variables in create method:
@source- The original data source passed to the factory constructor@view_context- Available when usingdefer_renderfor complex rendering
Example: Number Factory
Here's a complete example from the dummy app showing how to create a simple factory:
module Factories class ExampleLogNumberFactory < LooposUi::Log::Factories::Base def self.can_create?(source) source.is_a?(Integer) end def create LooposUi::Log.new( # random time +- 5days date: Time.now + (3*@source).hours + 60.minutes - rand(60).minutes, user: "random LogNumberFactory #{@source}", error: rand > 0.9 ).with_content("random message #{@source}") end endendDeferred Rendering
The factory create method must return a LooposUi::Log instance.
But this runs before the component is rendered, so if you need to call for render, you need to use defer_render and call the view_context.render method.
def create log = LooposUi::Log.new(...) log.defer_render do |log, view_context| # Complex rendering logic here view_context.render( SomeComponent.new(...)) end logendYou have some helpers methods available if you want to build up the log incrementally:
with_expand_content(content)
Note if you want to render HTML directly (e.g from a partial), you need to mark it as html_safe to avoid escaping.
Check for examples in the with_custom_expand example source code.