Giter VIP home page Giter VIP logo

apex-logger's Introduction

Apex Logger with parameterized logging and argument validation

Provides a flexible and extensible Logger class with parameterized logging.

Deploy to Salesforce

This logger with parameterized logging is a logging utility that allows for the insertion of dynamic values, known as parameters, into log messages at runtime. This allows for more detailed and informative log messages, as the values of variables or the state of the system can be included in the log.

This feature is useful for debugging and troubleshooting by providing more detailed and informative log messages and also it helps developers to track their application by providing more data in the logs.

Logger class

The "{}" pair is called the formatting anchor. It serves to designate the location where arguments need to be substituted within the message pattern. Logs debug, info and error messages to the console with parameters to be merged into the given stringFormat.

Logger logger = new LoggerImpl();

logger.debug('Test debug');
//|DEBUG|Test debug: 12

logger.error('Test error: {0} ', 12);
//|ERROR|Test error: 12

logger.debug('Test {0} debug: {0} ', 'StrValue');
//|DEBUG|Test StrValue debug: StrValue

logger.info('Test info {0} message {1}, {2} ', new List<Object>{
        'Str', 12, new List<Integer>{1, 2}
});
//|INFO|Test info Str message 12, (1, 2)

logger.debug('Test {0} debug {1} message {2}, {3} ', new List<Object>{
        Datetime.newInstance(2021, 12, 6),
        'Str', 12, new Map<Integer, String>{1 => 'one', 2 => 'two'}
});
//|DEBUG|Test 2021-12-06 00:00:00 debug Str message 12, {1=one, 2=two}

Argument validation using ObjectUtil class

Early argument validation using fail fast principle is a software design pattern that emphasizes the importance of validating input arguments early in the execution process and immediately stopping execution and throwing an exception when invalid arguments are detected. This can help to prevent errors and improve the robustness and reliability of the code.

ObjectUtil class provides basic object validation methods currently requireNonNull(Object obj, String message) and requireNonEmpty(List objs, String message).

    public String method(List<Id> recordIds, String logId) {
    
        ObjectUtil.requireNonNull(logId,'Log Id cannot be null for ... !');
        ObjectUtil.requireNonEmpty(recordIds, 'Record Id list cannot be empty for ... !');
    
        logger.info('SObject record id(s) received for processing: {0}', recordIds);
        logger.info('SObject external Log id received : {0}', logId);
}

apex-logger's People

Contributors

p-adrian05 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.