001/* Copyright (C) Cross The Road Electronics 2024 */
002package com.ctre.phoenix;
003
004/**
005 * Object to handle error logging
006 */
007public class Logger
008{
009        /**
010         * Logs an entry into the Phoenix DS Error/Logger stream
011         * @param code Error code to log.  If OKAY is passed, no action is taken.
012         * @param origin Origin string to send to DS/Log
013         * @return OKAY error code.
014         */
015        public static ErrorCode log(ErrorCode code, String origin) {
016                /* only take action if the error code is nonzero */
017                if (code != ErrorCode.OK) {
018                        String stack = java.util.Arrays.toString(Thread.currentThread().getStackTrace());
019                        stack = stack.replaceAll(",", "\n");
020                        int errCode = code.value;
021                        return ErrorCode.valueOf(CTRLoggerJNI.JNI_Logger_Log(errCode, origin, stack));
022                }
023                /* otherwise return OK */
024                return ErrorCode.OK;
025        }
026
027        //public static void close() {
028        //      //CTRLoggerJNI.JNI_Logger_Close();
029        //}
030        //public static void open() {
031        //      //CTRLoggerJNI.JNI_Logger_Open(2);
032        //}
033        /*
034        public static String getVerbose(int code) {
035                return CTRLoggerJNI.JNI_Logger_GetLong(code);
036        }
037        public static String getShort(int code) {
038                return CTRLoggerJNI.JNI_Logger_GetShort(code);
039        }
040        */
041}
042