LegacyLogManagerConfigs.java

/*
** Module   : LegacyLogManagerConfigs.java
** Abstract : Startup configs for LOG-MANAGER.
**
** Copyright (c) 2023-2025, Golden Code Development Corporation.
**
** -#- -I- --Date-- -----------------------Description------------------------
** 001 GBB 20230331 Created initial version.
** 002 GBB 20230512 Logging methods replaced by CentralLogger/ConversionStatus.
** 003 GBB 20230523 LoggingUtil.resolveLogFile signature changed with unrelated flag for rotation.
** 004 GBB 20230608 Field added to indicate if using the server-side filesystem is enabled.
** 005 RAA 20230608 Added null parameter to resolveLogFile.
** 006 GBB 20230613 setAppServer no longer sets isServerSideFileSystem to true.
** 007 TT  20230915 Migrated fileSize and numLogFiles from String to Integer.
** 008 CA  20240223 The implicit appserver logfile name must include the full path.
** 009 GBB 20241010 Making constant DEFAULT_APPSERVER_LOGFILE_NAME public.
** 010 GBB 20250403 Moving DEFAULT_APPSERVER_LOGFILE_NAME to LegacyLogOps.
*/
/*
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
** published by the Free Software Foundation, either version 3 of the
** License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Affero General Public License for more details.
**
** You may find a copy of the GNU Affero GPL version 3 at the following
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
** 
** Additional terms under GNU Affero GPL version 3 section 7:
** 
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
**   terms apply to the works covered under the License.  These additional terms
**   are non-permissive additional terms allowed under Section 7 of the GNU
**   Affero GPL version 3 and may not be removed by you.
** 
**   0. Attribution Requirement.
** 
**     You must preserve all legal notices or author attributions in the covered
**     work or Appropriate Legal Notices displayed by works containing the covered
**     work.  You may not remove from the covered work any author or developer
**     credit already included within the covered work.
** 
**   1. No License To Use Trademarks.
** 
**     This license does not grant any license or rights to use the trademarks
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
**     of Golden Code Development Corporation. You are not authorized to use the
**     name Golden Code, FWD, or the names of any author or contributor, for
**     publicity purposes without written authorization.
** 
**   2. No Misrepresentation of Affiliation.
** 
**     You may not represent yourself as Golden Code Development Corporation or FWD.
** 
**     You may not represent yourself for publicity purposes as associated with
**     Golden Code Development Corporation, FWD, or any author or contributor to
**     the covered work, without written authorization.
** 
**   3. No Misrepresentation of Source or Origin.
** 
**     You may not represent the covered work as solely your work.  All modified
**     versions of the covered work must be marked in a reasonable way to make it
**     clear that the modified work is not originating from Golden Code Development
**     Corporation or FWD.  All modified versions must contain the notices of
**     attribution required in this license.
*/

package com.goldencode.p2j.util;

import com.goldencode.p2j.util.logging.*;

/** Data class to store all startup LOG-MANAGER configs. */
public final class LegacyLogManagerConfigs
{
   /** Default logging level. */
   private final String levelString;

   /** List of comma-separated log entry types. */
   private final String entryTypes;

   /** File size in bytes used as threshold for file roll over. */
   private final Integer fileSize;

   /** Max number of log files. */
   private final Integer numLogFiles;

   /** The id of the client process. */
   private final long processId;

   /** The max number of characters. */
   private final int maxInputCharacters;
   
   /** Operating system user */
   private final String userOS;
   
   /** FWD context user. */
   private final String userFwd;

   /** File path for the log. */
   private String logFile;

   /** Sets the name of the appserver. */
   private String appServerName;

   /** Flag to indicate if the appserver logger has already been initialized in a different context. */
   private boolean isLoggerInitialized;

   /** A flag to indicate if LOG-MANAGER should write to the server-side file system. */
   private boolean isServerSideFileSystem;
   
   /**
    * Public constructor for LegacyLogManagerConfigs.
    *
    * @param   logFile
    *          File path for the log.
    * @param   levelString
    *          Default logging level.
    * @param   entryTypes
    *          List of comma-separated log entry types.
    * @param   fileSize
    *          File size in bytes used as threshold for file roll over.
    * @param   numLogFiles
    *          Max number of log files.
    * @param   processId
    *          The id of the client process.
    * @param   maxInputCharacters
    *          The max number of characters.
    * @param   userOS
    *          Operating system user.
    * @param   userFwd
    *          FWD context user.
    * @param   isServerSideFileSystem
    *          A flag to indicate if LOG-MANAGER should write to the server-side file system.
    */
   public LegacyLogManagerConfigs(String logFile,
                                  String levelString,
                                  String entryTypes,
                                  Integer fileSize,
                                  Integer numLogFiles,
                                  long processId,
                                  int maxInputCharacters,
                                  String userOS,
                                  String userFwd,
                                  boolean isServerSideFileSystem)
   {
      this.levelString = levelString;
      this.entryTypes = entryTypes;
      this.fileSize = fileSize;
      this.numLogFiles = numLogFiles;
      this.processId = processId;
      this.maxInputCharacters = maxInputCharacters;
      this.userOS = userOS;
      this.userFwd = userFwd;
      this.logFile = LoggingUtil.resolveLogFile(logFile,
                                                () -> processId,
                                                userOS,
                                                userFwd,
                                                appServerName,
                                                "client",
                                                null,
                                                false);
      this.isServerSideFileSystem = isServerSideFileSystem;
   }

   /**
    * Returns the file path for the log.
    *
    * @return   The file path for the log.
    */
   public String getLogFile()
   {
      return logFile;
   }
   
   /**
    * Returns the default logging level.
    *
    * @return   The default logging level.
    */
   public String getLevelString()
   {
      return levelString;
   }
   
   /**
    * Returns a list of comma-separated log entry types.
    *
    * @return   A list of comma-separated log entry types.
    */
   public String getEntryTypes()
   {
      return entryTypes;
   }
   
   /**
    * Returns file size in bytes used as threshold for file roll over.
    *
    * @return   The file size in bytes used as threshold for file roll over.
    */
   public Integer getFileSize()
   {
      return fileSize;
   }

   /**
    * Returns the max number of log files.
    *
    * @return   The max number of log files.
    */
   public Integer getNumLogFiles()
   {
      return numLogFiles;
   }
   
   /**
    * Returns the id of the client process.
    *
    * @return   The id of the client process.
    */
   public long getProcessId()
   {
      return processId;
   }
   
   /**
    * Returns the max number of characters.
    *
    * @return   The max number of characters.
    */
   public int getMaxInputCharacters()
   {
      return maxInputCharacters;
   }

   /**
    * Returns a flag to indicate if running in an appserver.
    * 
    * @return   A flag to indicate if running in an appserver.
    */
   public boolean isAppserver()
   {
      return appServerName != null;
   }

   /**
    * Sets the name of the appserver.
    *
    * @param   appServerName
    *          The name of the appserver.
    */
   public void setAppServer(String appServerName)
   {
      this.appServerName = appServerName;
      if (logFile == null)
      {
         character workDir = FileSystemOps.getWorkingDirectory();
         String sep = FileSystemOps.getFileSeparator();
         String filename = workDir.getValue() + sep + LegacyLogOps.DEFAULT_APPSERVER_LOGFILE_NAME;
         logFile = LoggingUtil.resolveLogFile(filename,
                                              () -> processId, 
                                              userOS,
                                              userFwd,
                                              appServerName,
                                              "client",
                                              null,
                                              false);
      }
   }
   
   /**
    * Returns a flag to indicate if LOG-MANAGER should be using the server-side filesystem.
    *
    * @return   A flag to indicate if LOG-MANAGER should be using the server-side filesystem.
    */
   public boolean isServerSideFileSystem()
   {
      return isServerSideFileSystem;
   }

   /** Sets a flag to indicate the appserver logger has already been initialized in a different context. */
   public void setLoggerInitialized()
   {
      isLoggerInitialized = true;
   }

   /**
    * Returns a flag to indicate if the appserver logger has already been initialized in a different 
    * context.
    *
    * @return  A flag to indicate if the appserver logger has already been initialized in a different 
    *          context.
    */
   public boolean isLoggerInitialized()
   {
      return isLoggerInitialized;
   }
}