logtape icon indicating copy to clipboard operation
logtape copied to clipboard

feat: option to efficiently use horizontal space

Open pankgeorg opened this issue 5 months ago • 3 comments

fixes: #73

pankgeorg avatar Jul 11 '25 13:07 pankgeorg

Thanks for your contribution! Could you show me some screenshots with this new option?

dahlia avatar Jul 11 '25 14:07 dahlia

Thanks for your contribution! Could you show me some screenshots with this new option?

I'll get some nicer ones, but here is some for now! image

image

compare this to image

Not saying one is better (noone should be logging that much 🙈) but if you have to, the first is more compact :)

Thanks for your time in any case!

On a technical note, the magic constants (4, 6 etc) may be passed instead of the true; I'm not 100% sure how the API should look like. Please let me know of your thoughts!

pankgeorg avatar Jul 11 '25 14:07 pankgeorg

Hey @dahlia ! I cleaned this up a bit! Let me know if you need anything else!!

Here is also a script to test it
#!/usr/bin/env -S deno run --allow-all

import { configure, getLogger } from "./packages/logtape/src/mod.ts";
import { getPrettyFormatter } from "./packages/pretty/src/mod.ts";

// Configure logging with both formatters
const regularFormatter = getPrettyFormatter({
  colors: false,
  messageNewLine: false,
  properties: true,
});

const newLineFormatter = getPrettyFormatter({
  colors: false,
  messageNewLine: true,
  properties: true,
});

// Create a huge message (around 1000 characters)
const hugeMessage = "This is an extremely long log message that demonstrates the difference between regular formatting and the new messageNewLine option. " +
  "When you have very long messages like this one, the regular formatter will continue the message on the same line as the category, which can make it " +
  "difficult to read in narrow terminals or when you have long category names. The new messageNewLine option helps by placing the message on a new line " +
  "below the timestamp, level, and category information, which saves horizontal space and improves readability. This is particularly useful when you're " +
  "dealing with detailed log messages that contain lots of context information, error descriptions, or when you're logging complex data structures. " +
  "The feature addresses issue #73 by providing an efficient way to use horizontal space in logging output, making logs more readable in constrained environments " +
  "like narrow terminal windows or when viewing logs in split-pane editors where horizontal space is at a premium.";

console.log("=".repeat(80));
console.log("REGULAR FORMATTING (messageNewLine: false)");
console.log("=".repeat(80));

// Create a log record manually to format it
const logRecord = {
  level: "info" as const,
  category: ["my", "very", "long", "category", "name"],
  message: [hugeMessage],
  timestamp: Date.now(),
  properties: {
    userId: "12345",
    requestId: "abc-def-ghi",
    sessionId: "session-xyz-789",
    userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
  }
};

const regularOutput = regularFormatter(logRecord);
console.log(regularOutput);

console.log("\n" + "=".repeat(80));
console.log("NEW LINE FORMATTING (messageNewLine: true)");
console.log("=".repeat(80));

const newLineOutput = newLineFormatter(logRecord);
console.log(newLineOutput);

console.log("=".repeat(80));
console.log("COMPARISON SUMMARY");
console.log("=".repeat(80));
console.log(`Regular output lines: ${regularOutput.split('\n').length - 1}`);
console.log(`NewLine output lines: ${newLineOutput.split('\n').length - 1}`);
console.log(`Message length: ${hugeMessage.length} characters`);
And some example output:
================================================================================
REGULAR FORMATTING (messageNewLine: false)
================================================================================
✨ info    my…name              This is an extremely long log
                                message that demonstrates the
                                difference between regular
                                formatting and the new
                                messageNewLine option. When you
                                have very long messages like this
                                one, the regular formatter will
                                continue the message on the same
                                line as the category, which can
                                make it difficult to read in
                                narrow terminals or when you have
                                long category names. The new
                                messageNewLine option helps by
                                placing the message on a new line
                                below the timestamp, level, and
                                category information, which saves
                                horizontal space and improves
                                readability. This is particularly
                                useful when you're dealing with
                                detailed log messages that
                                contain lots of context
                                information, error descriptions,
                                or when you're logging complex
                                data structures. The feature
                                addresses issue #73 by providing
                                an efficient way to use
                                horizontal space in logging
                                output, making logs more readable
                                in constrained environments like
                                narrow terminal windows or when
                                viewing logs in split-pane
                                editors where horizontal space is
                                at a premium.
                        userId: "12345"
                     requestId: "abc-def-ghi"
                     sessionId: "session-xyz-789"
                     userAgent: "Mozilla/5.0 (Windows NT 10.0;
                                Win64; x64) AppleWebKit/537.36"


================================================================================
NEW LINE FORMATTING (messageNewLine: true)
================================================================================
✨ info    my…name
    This is an extremely long log message that demonstrates the
    difference between regular formatting and the new
    messageNewLine option. When you have very long messages like
    this one, the regular formatter will continue the message on
    the same line as the category, which can make it difficult to
    read in narrow terminals or when you have long category
    names. The new messageNewLine option helps by placing the
    message on a new line below the timestamp, level, and
    category information, which saves horizontal space and
    improves readability. This is particularly useful when you're
    dealing with detailed log messages that contain lots of
    context information, error descriptions, or when you're
    logging complex data structures. The feature addresses issue
    #73 by providing an efficient way to use horizontal space in
    logging output, making logs more readable in constrained
    environments like narrow terminal windows or when viewing
    logs in split-pane editors where horizontal space is at a
    premium.
      userId: "12345"
      requestId: "abc-def-ghi"
      sessionId: "session-xyz-789"
      userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64)
    AppleWebKit/537.36"

================================================================================
COMPARISON SUMMARY
================================================================================
Regular output lines: 38
NewLine output lines: 24
Message length: 994 characters

pankgeorg avatar Sep 02 '25 12:09 pankgeorg